手动订购 Jekyll 集合

Manually order a Jekyll collection

如 Jekyll 文档 here 中所述,我的 _config.yml 中有以下内容:

collections:
  sections:
    order:
      - introduction.md
      - battery-state.md
      - vibe.md
      - references.md

要呈现 HTML 内每个文件的内容,我有以下内容:

{% for section in site.sections %}
  {{ section.content }}
{% endfor %}

但是,内容顺序并不是我在配置文件中定义的那样。如何按照我在配置文件中定义的顺序显示内容?

Jekyll 4.0 中引入了手动排序集合中的文档 要使用此功能,请确保您使用的是 Jekyll 4.0

对于部署在 GitHub Pages 上的站点,这意味着必须在 GitHub Pages 环境之外构建站点并上传 目标目录的内容 (_site).

您还可以选择将版块添加到页面的首页。当您不使用 Jekyll v4 或您希望用户能够在 CloudCannon、Netlify CMS、Forestry 或其他带有前端编辑器的 CMS 中编辑订单时,这很有用。

sections:
  - introduction
  - battery-state
  - vibe
  - references

并使用这样的布局:

{% for s in page.sections %}
    {% for section in site.sections %}
        {% if s == section.slug %}
             ...
        {% endif %}
    {% endfor %}
{% endfor %}