有没有办法循环遍历 jekyll 集合的前面内容?

Is there a way to loop through the front matter of a jekyll collection?

我有一个未输出的 Jekyll 集合,但其中的元素显示在单个页面上,如下所示:

{% for element in site.collection %}
  {{ element.content }}
{% endfor %}

我希望能够做这样的事情:

{% for element in site.collection %}
  {{ element.content }}
  {% for front_matter in element %}
    <!-- do stuff -->
  {% endfor %}
{% endfor %}

YAML _data 文件中的 YAML 哈希可以实现这一点,但在这里不起作用,因为 {{ element }} 本身似乎与 {{ element.content }} 相同。似乎也没有为此指定任何变量,例如 {{ element.front_matter }}。是否可以循环遍历 jekyll 集合中元素的前端内容?

我知道执行此操作的理想方法是将我想要循环的所有 front_matter 包含在一个变量中,例如:

---
front_matter:
  foo: bar
  bar: foo
---

但是,当我尝试将这些配对(foobar)配置为可以通过 prose.io 轻松更新时,它们不能嵌套在其他值下。如果有一个 虽然用散文来解决这个问题,但我会接受这个答案。

非常感谢!

可以循环遍历 Jekyll 集合中元素的变量:

{% for items in site.my_collection %}
  {% for item in items %}
    {{ item }}: {{ items[item] }}
  {% endfor %}
{% endfor %}

但重要的是要记住,还有其他元数据也可用并将包含在迭代中,例如 pathurl 等,以及您的前言,例如对于 _my_collection/something.md:

next:

path: _my_collection/something.md

output: <p></p>

url: /my_collection/something.html

id: /my_collection/something

content: <p></p>

collection: my_collection

relative_path: _my_collection/something.md

excerpt: <p></p>

previous:

draft: false

categories:

slug: something

ext: .md

tags:

date: 2017-05-23 14:43:57 -0300