【问题标题】:List of all authors on site in JekyllJekyll 网站上的所有作者列表
【发布时间】:2016-05-18 17:25:05
【问题描述】:

我目前正在使用数据文件来指定网站上的作者,我需要将所有作者的列表拉到“关于”页面上。

这是我的_data/authors.yml 文件的格式

# Authors
one:
  name: One
  display_name: Person One
  avatar: /img/avatar1.jpg
  permalink: author/personone/
two:
  name: Two
  display_name: Person Two
  avatar: /img/avatar2.jpg
  permalink: author/persontwo/

如果它是一个类别页面,我会使用它来列出他们指定帖子的人:

{% for post in site.categories.[page.category] %}
{% assign author = site.data.authors[post.author] %}
    {{ author.display_name }}
{% endfor %}

但我想显示所有作者,而不必指定与他们相关的帖子(一些作者在网站上还没有帖子)。

想法?

编辑:

将我的代码从那个 Jekyll 文档示例换成:

<ul>
    {% for author in site.data.authors %}
        <li>
            <a href="{{ author.permalink }}">
                {{ author.display_name }}
            </a>
        </li>
    {% endfor %}
</ul>

重建后什么都不显示...

【问题讨论】:

    标签: yaml jekyll author


    【解决方案1】:

    您没有正确的 YML 结构。

    _data/authors.yml:

    - name: One
      display_name: Person One
      avatar: /img/avatar1.jpg
      permalink: author/personone/
    
    - name: Two
      display_name: Person Two
      avatar: /img/avatar2.jpg
      permalink: author/persontwo/
    

    (注意破折号)

    然后:

    <ul>
        {% for author in site.data.authors %}
        <li>
            {{ author.display_name }}
        </li>
        {% endfor %}
    </ul>
    

    另外,如果您想保留原始 YAML 结构。 您可以使用它来访问作者(使用索引 1)。

    <ul>
        {% for author in site.data.authors %}
        <li>
            {{ author[1].name }}
        </li>
        {% endfor %}
    </ul>
    

    【讨论】:

    • 我只是想显示网站上的所有作者,并带有指向他们个人资料页面的链接。我不想拉入任何帖子/数据,只是从authors.yml 中指定的内容(全名、头像、页面 URL)。我敢肯定,我缺少一种能够使其工作的语法。
    • 哦。那是pretty easy
    • 已经试过了。我认为我的authors.yml 文件的格式可能与 Jekyll 文档显示的不同,因此语法不起作用。我以我能想到的各种方式尝试了他们示例中的内容,但无济于事。
    • 使用基于 Jekyll 文档的新代码编辑了我上面的回复。还是不行。
    • 编辑了我的答案,因为我显然不明白这个问题。
    【解决方案2】:

    这对我有用,as suggested here

    在 _config.yml 中:

    authors:
      hanzou:
        name: Hanzou Hattori
        display_name: Hanzou
        gravatar: c66919cb194f96c696c1da0c47354a6a
        email: hanzou@company.com
        web: http://company.com
        twitter: company
        github: hhattori
      jorgen:
        name: Jörgen Mortensen
        display_name: Jörgen
        gravatar: 12e480a364a5c19214f99b4dfe9a11d5
        email: jorgen@company.com
        web: http://company.com
        twitter: company
        github: jorgenm
    

    在模板中列出作者:

    {% for author in site.authors %}
        {{ author[1].name }} -- {{ author[1].email }}
    {% endfor %}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-13
      • 1970-01-01
      • 1970-01-01
      • 2018-09-05
      • 2021-01-07
      • 1970-01-01
      • 2013-12-07
      • 1970-01-01
      相关资源
      最近更新 更多