gpt4 book ai didi

jekyll - 不使用插件从 yaml 创建多个 jekyll 页面

转载 作者:行者123 更新时间:2023-12-01 15:21:25 25 4
gpt4 key购买 nike

我正在开发一个 Jekyll 站点,我希望能够为组中的每个人创建一个页面。我知道如果集合中的文件是 Markdown 的,我可以使用集合来生成页面。我希望能够在集合中包含 yaml 文件,然后在将每个 yaml 文件传递​​给模板后生成页面。

人员文件可能如下所示:

# person-1.yaml
name: thingy m. bob
position: coffee fetcher
bio: no bio needed

# person-2.yaml
name: mars e. pan
position: head honcho
bio: expert in everything

然后是这样的模板文件(people-template.md):

# {{ page.name }} - {{ page.position }}
{{ page.bio }}

并且输出将是 /people/ 下的单个文件,即 /people/person-1/people/person-2,其格式与模板中的相同,但使用 .yaml 文件。

我正在使用 GitHub 页面,所以我不想使用任何不支持的插件。

最佳答案

我已经实现了类似的东西......这是我创建的设置:

- _Layouts
- person.html
...
people
- index.md (list of people - see code below)
- _posts
- 2015-01-01-person-one.md (ordering defined by date which is thrown away)
- 2015-01-02-person-two.md
- 2015-01-03-person-three.md
...

然后对于一个人的列表,你可以使用类似的东西:

<ul>
{% for person in site.categories.people %}
<li><a href="{{ person.url }}>{{ person.name}}"></a></li>
{% endfor %}
</ul>

每个人都在表格中

---
name: "thingy m. bob"
# using quotes to avoid issues with non-alpha characters
position: "coffee fetcher"
bio: "no bio needed"

layout: person
---

any markdown if you want more of a description

我希望这给了你一些开始的东西......我认为将 _posts 文件夹放在 people 文件夹下会自动将类别设置为 人们。如果我错了,只需将 category: people 添加到 yaml。

如果您想删除日期部分,您可以在 _config.yaml 中设置帖子 url 的模式。

祝你好运

关于jekyll - 不使用插件从 yaml 创建多个 jekyll 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32715434/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com