从 markdown 访问 jekyll 集合属性
Accessing jekyll collection attributes from markdown
我有一组代表我教授的课程的集合。他们每个人都有一些与该课程相关的独特属性。例如:
# Collections, which are CS courses for me
collections:
cs1:
output: true
title: "CS1"
permalink: /teaching/cs1/:path/
TAemail: "cs1@school.edu"
cs2:
output: true
title: "CS2"
permalink: /teaching/cs2/:path/
TAemail: "cs2@school.edu"
...
在每个集合中,有一个 Logistics.md
文件应该显示该课程的电子邮件地址。例如,如果课程是 cs2,我想使用的是:
[Teaching team email](mailto:{{ site.cs2.TAemail }}) ...
但是,这不起作用。如果我将 TAemail
名称放入集合中的 Logistics.md
文件中,并对其进行某种查找,例如:
{% for file in site.cs2 %}
{% if file.type == 'Info' %}
{% if file.subtype == 'Logistics' %}
| | email: | [ Team ](mailto: {{ file.TAemail }}) |
{% endif %}
{% endif %}
{% endfor %}
它工作正常。这看起来很尴尬而且不太像 jekyll。
有什么想法吗?
{{ site.cs2.TAemail }}
不起作用,因为 site.cs2
是一个包含集合项目的数组,因此您无法访问您指定的元数据,因为它不是 属性 的数组。
访问集合元数据的方法是通过site.collections
。
例如
{% assign cs_collection = site.collections | where: "label", "cs1" | first %}
Send e-mail to: {{ cs_collection.TAemail }}
顺便说一句,集合中的每一项都包含一个名为collection
的属性,带有所属集合的名称,因此您可以根据项目动态查询集合,而无需必须在 where 过滤器中对集合名称进行硬编码。
例如
{% for item in site.cs1 %}
{% assign this_collection = item.collection %}
{% assign cs_collection = site.collections | where: "label", this_collection | first %}
Send e-mail to: {{ cs_collection.TAemail }}
{% endfor %}
我有一组代表我教授的课程的集合。他们每个人都有一些与该课程相关的独特属性。例如:
# Collections, which are CS courses for me
collections:
cs1:
output: true
title: "CS1"
permalink: /teaching/cs1/:path/
TAemail: "cs1@school.edu"
cs2:
output: true
title: "CS2"
permalink: /teaching/cs2/:path/
TAemail: "cs2@school.edu"
...
在每个集合中,有一个 Logistics.md
文件应该显示该课程的电子邮件地址。例如,如果课程是 cs2,我想使用的是:
[Teaching team email](mailto:{{ site.cs2.TAemail }}) ...
但是,这不起作用。如果我将 TAemail
名称放入集合中的 Logistics.md
文件中,并对其进行某种查找,例如:
{% for file in site.cs2 %}
{% if file.type == 'Info' %}
{% if file.subtype == 'Logistics' %}
| | email: | [ Team ](mailto: {{ file.TAemail }}) |
{% endif %}
{% endif %}
{% endfor %}
它工作正常。这看起来很尴尬而且不太像 jekyll。
有什么想法吗?
{{ site.cs2.TAemail }}
不起作用,因为 site.cs2
是一个包含集合项目的数组,因此您无法访问您指定的元数据,因为它不是 属性 的数组。
访问集合元数据的方法是通过site.collections
。
例如
{% assign cs_collection = site.collections | where: "label", "cs1" | first %}
Send e-mail to: {{ cs_collection.TAemail }}
顺便说一句,集合中的每一项都包含一个名为collection
的属性,带有所属集合的名称,因此您可以根据项目动态查询集合,而无需必须在 where 过滤器中对集合名称进行硬编码。
例如
{% for item in site.cs1 %}
{% assign this_collection = item.collection %}
{% assign cs_collection = site.collections | where: "label", this_collection | first %}
Send e-mail to: {{ cs_collection.TAemail }}
{% endfor %}