【问题标题】:Jekyll: installing a gem-based themeJekyll:安装基于 gem 的主题
【发布时间】:2017-08-14 22:24:33
【问题描述】:

我已经成功地使用 Jekyll v3.4.3 创建了我的第一个静态网站。现在我想将默认的“minima”主题更改为另一个基于 gem 的主题,例如,jekyll-theme-minimal

据我了解,根据jekyll documentation,这只需要以下步骤:

1.- 将主题添加到您网站的 Gemfile:

gem "jekyll-theme-minimal", "~> 0.0.3"

2.- 安装主题:

bundle install

3.- 将以下内容添加到您网站的 _config.yml 以激活主题(注释掉“minima”并添加新主题):

theme: jekyll-theme-minimal

4.- 建立您的网站:

bundle exec jekyll serve

我遵循了这些步骤,但是构建网站(第 4 步)会带来以下错误:

$ bundle exec jekyll serve
Configuration file: /home/username/jekyll/myblog/_config.yml
Configuration file: /home/username/jekyll/myblog/_config.yml
            Source: /home/username/jekyll/myblog
       Destination: /home/username/jekyll/myblog/_site
 Incremental build: disabled. Enable with --incremental
      Generating... 
     Build Warning: Layout 'post' requested in _posts/2017-03-22-welcome-to-jekyll.markdown does not exist.
  Liquid Exception: Could not locate the included file 'icon-github.html' in any of ["/home/username/jekyll/myblog/_includes"]. Ensure it exists in one of those directories and, if it is a symlink, does not point outside your site source. in about.md

我看到新的基于 gem 的主题已经安装了

$ bundle show jekyll-theme-minimal
/home/username/.gem/ruby/2.4.0/gems/jekyll-theme-minimal-0.0.3

但我注意到新主题没有 _includes 目录。另外,我看到我的 Jekyll 站点目录中的 about.md 文件仍在引用默认的“minima”主题:

$ cat ~/jekyll/myblog/about.md 
---
layout: page
title: About
permalink: /about/
---

This is the base Jekyll theme. You can find out more info about customizing your Jekyll theme, as well as basic Jekyll usage documentation at [jekyllrb.com](https://jekyllrb.com/)

You can find the source code for the Jekyll new theme at:
{% include icon-github.html username="jekyll" %} /
[minima](https://github.com/jekyll/minima)

You can find the source code for Jekyll at
{% include icon-github.html username="jekyll" %} /
[jekyll](https://github.com/jekyll/jekyll)

如何在我的网站中将默认的“minima”主题更改为另一个基于 gem 的主题?

【问题讨论】:

    标签: rubygems themes jekyll


    【解决方案1】:

    Jekyll 主题文档指定了使用新主题的一般程序,但由于 Jekyll 非常灵活,它不能保证每个主题都能开箱即用。

    Jekyll 默认安装,附带示例数据、pages 布局和includes

    Minimal 主题具有默认布局不包含,因为 Jekyll 附带的示例帖子使用 includes 并使用 page 布局,它不起作用。

    安装 minimal 主题后,您需要确保所有帖子都将 layout: default 作为其布局(没有 layout: pages或任何其他),并且帖子内容没有包含

    在这种情况下,像这样调整 about.md 之后,它看起来像这样:

    ---
    layout: default
    title: About
    permalink: /about/
    ---
    
    This is the base Jekyll theme. You can find out more info about customizing your Jekyll theme, as well as basic Jekyll usage documentation at [jekyllrb.com](https://jekyllrb.com/)
    
    You can find the source code for the Jekyll new theme at:
    [minima](https://github.com/jekyll/minima)
    
    You can find the source code for Jekyll at
    [jekyll](https://github.com/jekyll/jekyll)
    

    或者,如果您不想更改帖子的内容,只需提供缺少的包含和/或布局,创建这些文件夹并创建您希望使用新主题拥有的正确缺少的文件,您不是仅限于使用主题使用的内容Overriding theme default

    【讨论】:

    • 很好的解释,对我帮助很大。看来 Jekyll 并没有我想象的那么简单,我会继续阅读文档以获取更多知识
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-28
    • 2020-12-23
    • 1970-01-01
    • 2023-04-02
    相关资源
    最近更新 更多