不使用插件

时间:2015-09-22 11:15:14

标签: jekyll github-pages

我正在开发一个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个文件。< / p>

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

1 个答案:

答案 0 :(得分:1)

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

- _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文件夹下会自动将类别设置为people。如果我错了,只需将category: people添加到yaml。

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

祝你好运

相关问题