【问题标题】:How to create and display custom Jekyll meta data如何创建和显示自定义 Jekyll 元数据
【发布时间】:2020-10-21 12:55:34
【问题描述】:

我有一个 Jekyll 私人博客(即实验室笔记本),它使用了精彩的 minimal-mistakes 主题。我为我的每篇博文都大量使用了标签,并且可以看到标签列表。

我还喜欢跟踪我在博文中提到的人,因此我为每篇博文添加额外的元数据,如下所示:

---
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 看到人员元数据?我需要以某种方式告诉 Jekyll 还有其他需要查看的元数据吗?

【问题讨论】:

    标签: frontend jekyll metadata liquid


    【解决方案1】:

    我认为您需要在第二个代码 sn-p 中将 site 替换为 page,请参阅 variables 的处理。

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

    另外我删除了数组索引[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的sn-p声明所有物理学家。

    ...
    
    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 %}
    

    【讨论】:

    • 我一定没有很好地解释我的问题。我想要一个页面来显示所有提到特定人的博客文章。您链接的页面显示在site.tags.TAG 中访问标签。我想对人们做同样的事情。标签的处理方式是否与其他 frontmatter 元数据不同?
    • 您想在site.physicistspage.people 之间找到匹配项吗?如果是,你需要匹配物理学家和循环内的人
    猜你喜欢
    • 2018-03-18
    • 1970-01-01
    • 2023-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-18
    相关资源
    最近更新 更多