所以我在Jekyll _data文件夹中有一个文件authors.yml . 它的设置如下:
short_name:
name: First Lastname
email: e@mail.com
twitter: twitterID
image: image.jpg
bio: 'Bio goes here.'
我想在这个文件中创建每个作者的列表页面 . 这是我尝试过的:
<ul>
{% for author in site.data.authors %}
<li>{{ author.name }}</li>
{% endfor %}
</ul>
返回的是许多与文件中的作者数匹配的空列表标记 .
我想知道是否有任何方法可以显示每个作者中包含的数据而无需在YAML文件中使用以下内容(因为它打破了网站上的其他代码):
-author: short_name
name: First Lastname
email: e@mail.com
twitter: twitterID
image: image.jpg
bio: 'Bio goes here.'
这可能吗?
或者,添加“作者”键时被破坏的代码如下 .
在模板中:
{% assign author = site.data.authors[post.author] %}
在一个插件中:
entry_name = site.data['authors'][entry.author]
3 回答
我不确定这是否是你所追求的,但我一直在努力解决类似的问题 .
为此,我需要在我的数据中包含一个
short_name
项 . 见下文:现在我们可以在模板中使用
{{ author.name }}
等 .关于这个问题,我实际上是written a blog post . 在_data文件中,您只需为要显示的每组作者属性创建一个新条目 .
因此,如果您将authors.yml文件更改为如下所示:
然后,您可以在作者对象上引用您要查找的属性:
希望有所帮助 .
我有同样的问题 . 这是最好的解决方案 .
这是我的布局文件的摘录:
这是我的名为'people.yml'的数据文件