如何创建和显示自定义Jekyll元数据



我有一个Jekyll私人博客(即实验室笔记本(,它使用了奇妙的最小错误主题。我在每一篇博客文章中都大量使用标签,并且可以看到标签列表。

我也喜欢跟踪我在博客文章中提到的人,所以我为每条帖子添加了额外的元数据,如下所示:

---
title: "My great experiment"
tags:
- physics
- chemistry
- Higgs boson
people:
- Albert Einstein
- Galileo Galilei
- Marie Curie
---

我想做的是看到我的博客中提到的所有人——在所有的博客文章中——但Jekyll似乎没有填充site.people变量。我试着将site.people变量可视化,如下所示:

{
{
"people": [
{%- for person in site.people -%}
"{{ person[0] }}"{% unless forloop.last %},{% endunless %}
{%- endfor -%}
],
}
}

但我在渲染的网页上看到的只是:

{ { “people”: [],
} }

我需要做什么才能让杰基尔看到这些人的元数据我需要告诉Jekyll还有其他元数据需要查看吗?

我认为您需要在第二个代码片段中将site替换为page,请参阅变量的处理。

  • 站点:全球网站(例如_config.yml(
  • 页面:当前页面

附加I丢弃了数组索引[0]

{
{
"people": [
{%- for person in page.people -%}
"{{ person }}"{% unless forloop.last %},{% endunless %}
{%- endfor -%}
],
}
}

我的输出/结果


{ { “people”: [“Albert Einstein”,”Galileo Galilei”,”Marie Curie”],
} }

更新2020-10-23:

声明所有物理学家的全局_config.yml的片段。

...
physicists:
- Albert Einstein
- Galileo Galilei
- Marie Curie
- Isaac Newton
- Nikola Tesla
- Max Planck
...

要获得任何后上的所有物理学家的列表

---
title: "My great experiment"
tags:
- physics
- chemistry
- Higgs boson
people:
- Albert Einstein
- Galileo Galilei
- Marie Curie
---
## List all Physicists
{% for itm in site.physicists %}
{{ itm }}
{% endfor %}

最新更新