在 Jekyll 中,如何呈现集合的自定义元数据



我的_config.yml文件中有以下内容:

collections:
  nr_qa:
    output: true
    permalink: /:collection/:name
    title: 'Node-RED Questions and Answers'
    descriptions: 'Node-RED is a flow-based (visual) programming tool. These pages have some information that may be currently missing from the documentaiton.'
  github_pages:
    title: 'GitHub Pages and Jekyll/Liquid'
    description: 'Hints and tips on using Jekyll for publishing to GitHub Pages.'
    output: true
    permalink: /:collection/:name

我想为我的集合创建一个自动索引。所以我使用这样的代码:

## {{ site.collections.github_pages.title }}
{{ site.collections.github_pages.description }}
<ul>
{% for item in site.github_pages %}
  <li>
    <a href="{{ item.url }}">{{ item.title | replace:'_',' ' }}</a>
    <p>{% if item.description %}
        {{ item.description }}
    {% else %}
        {{ item.excerpt | strip_html }}
    {% endif %}</p>
  </li>
{% endfor %}
</ul>

是的,我知道我宁愿在那里混淆我的降价和 html。与这个问题无关。

问题是{{ site.collections.github_pages.title }}{{ site.collections.github_pages.description }}不会渲染任何东西,即使我认为他们应该渲染任何东西。

谁能指出我的错误?

问题是titledescription应该包含在每个集合中,而不是包含在_config.yml中。

查看访问集合属性永久链接以获取更多详细信息。

更新

title可以存在于 _config.yml 中的每个集合元数据中。问题在于您如何访问这些变量。

一种方法是为每个集合设置特定的布局,然后您可以像这样访问它们:

{% assign col = site.collections | where: 'label','github_pages' | first%}.
TITLE: {{ col.title }}.
DESCRIPTION: {{ col.description }}.

最新更新