在 Jekyll 中,如何呈现 collection 的自定义元数据?
In Jekyll, how do I render custom metadata for a collection?
我的 _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
我想为我的 collections 创建一个自动索引。所以我使用这样的代码:
## {{ 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>
是的,我知道我已经把 markdown 和 html 搞混了。与这个问题无关。
问题是 {{ site.collections.github_pages.title }}
和 {{ site.collections.github_pages.description }}
没有渲染任何东西,尽管我认为它们应该渲染。
谁能指出我的错误?
问题是 title
和 description
应该包含在每个集合中,而不是 _config.yml
。
查看 Accessing Collection AttributesPermalink 了解更多详情。
更新
title
可以出现在 _config.yml
中的每个集合元数据中。问题是您如何访问这些变量。
一种方法是为每个集合设置特定的布局,然后您可以像这样访问它们:
{% assign col = site.collections | where: 'label','github_pages' | first%}.
TITLE: {{ col.title }}.
DESCRIPTION: {{ col.description }}.
我的 _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
我想为我的 collections 创建一个自动索引。所以我使用这样的代码:
## {{ 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>
是的,我知道我已经把 markdown 和 html 搞混了。与这个问题无关。
问题是 {{ site.collections.github_pages.title }}
和 {{ site.collections.github_pages.description }}
没有渲染任何东西,尽管我认为它们应该渲染。
谁能指出我的错误?
问题是 title
和 description
应该包含在每个集合中,而不是 _config.yml
。
查看 Accessing Collection AttributesPermalink 了解更多详情。
更新
title
可以出现在 _config.yml
中的每个集合元数据中。问题是您如何访问这些变量。
一种方法是为每个集合设置特定的布局,然后您可以像这样访问它们:
{% assign col = site.collections | where: 'label','github_pages' | first%}.
TITLE: {{ col.title }}.
DESCRIPTION: {{ col.description }}.