max*_*mos 26 jekyll twitter-bootstrap jekyll-bootstrap
我是Jekyll的新手,想要引入一些Twitter Bootstrap功能.有没有人这样做过,如果有的话,你有什么建议吗?我会选择Jekyll-Bootstrap,但不再支持它了.我已经建立了我的Jekyll网站,我希望有一种方法来引入Bootstrap.
Dav*_*uel 40
由于Jekyll原生支持sass,你可以使用bootstrap-sass.
我个人用bower install bootstrap-sass命令安装它.
这将在bower_components文件夹中安装Bootstrap和Jquery .
在你的_config.yml中添加:
sass:
# loading path from site root
# default to _sass
sass_dir: bower_components/bootstrap-sass/assets/stylesheets
# style : nested (default), compact, compressed, expanded
# :nested, :compact, :compressed, :expanded also works
# see http://sass-lang.com/documentation/file.SASS_REFERENCE.html#output_style
# on a typical twitter bootstrap stats are :
# nested 138,7kB, compact 129,1kB, expanded 135,9 kB, compressed 122,4 kB
style: compressed
Run Code Online (Sandbox Code Playgroud)
如果您想使用javascript,请在_includes/footer.html中添加:
<script src="{{ site.baseurl }}/bower_components/jquery/dist/jquery.min.js"></script>
<script src="{{ site.baseurl }}/bower_components/bootstrap-sass/assets/javascripts/bootstrap.min.js"></script>
Run Code Online (Sandbox Code Playgroud)
在css/main.scss删除以前的内容并添加
---
# Only the main Sass file needs front matter (the dashes are enough)
---
@charset "utf-8";
/* path to glyphicons */
$icon-font-path: "/bower_components/bootstrap-sass/assets/fonts/bootstrap/";
/* custom variable */
$body-bg: red;
/* any style customization must be before the bootstrap import */
@import "bootstrap";
Run Code Online (Sandbox Code Playgroud)
您可以看到所有可用的变量 bower_components/bootstrap-sass/assets/stylesheets/bootstrap/_variables.scss
您可以删除旧的_sass文件夹.
现在,您的css文件将在每次构建时生成.
由于 Bootstrap 4 Beta 现在在 Sass 上运行,您可以使用“官方”bower 包。
这就是我所做的:
bower install bootstrap#v4.0.0-beta --save将 Bootstrap 及其依赖项安装到该bower_components文件夹。
在 中_config.yml,我更改了 Sass 文件夹并bower_components从处理中排除:
sass:
sass_dir: assets/css
# Exclude from processing.
exclude:
- bower_components
Run Code Online (Sandbox Code Playgroud)
我改变assets/css/main.scss如下:
---
# Only the main Sass file needs front matter (the dashes are enough)
---
@charset "utf-8";
@import "variables"; // (2)
@import "../../bower_components/bootstrap/scss/bootstrap"; // (1)
// Import other styling below
// ...
Run Code Online (Sandbox Code Playgroud)
(1)请注意,第二个 import 语句必须相对于 中指定的 Sass 目录_config.yml。由于我选择它作为也包含 的文件夹main.scss,因此您最喜欢的 IDE(例如 WebStorm)中的资产链接不会中断。
(2)为了覆盖 Bootstrap Sass 变量,我创建了assets/css/_variables.scss必须在 Bootstrap 库之前导入的变量。
由于我没有找到使用 JS 的方法bower_components,我选择包含Bootstrap 建议的CDN 版本:
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js" integrity="sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js" integrity="sha384-h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4Si90RDIqNm1" crossorigin="anonymous"></script>
Run Code Online (Sandbox Code Playgroud)
Bootstrap 4.3.1 和 Jekyll 4.0 的更新
您可以使用 bunder 将 BS 安装到您的站点中
bundle install bootstrap
Run Code Online (Sandbox Code Playgroud)
将其添加到 gem 文件中:
gem 'bootstrap', '~> 4.3.1'
Run Code Online (Sandbox Code Playgroud)
获取BS的路径
bundle info bootstrap
Run Code Online (Sandbox Code Playgroud)
将该路径添加到 _config.yml
sass:
load_paths:
- _sass
- C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/bootstrap-4.3.1/assets/stylesheets
Run Code Online (Sandbox Code Playgroud)
也可以添加相对路径。
最后,将引导程序添加到 style.scss
@import "bootstrap";
Run Code Online (Sandbox Code Playgroud)
https://getbootstrap.com/docs/4.3/getting-started/download/
| 归档时间: |
|
| 查看次数: |
10413 次 |
| 最近记录: |