【问题标题】:Want to create another _post directory in jekyll想在 jekyll 中创建另一个 _post 目录
【发布时间】:2016-02-17 04:22:27
【问题描述】:

我想创建一个作者_layout,我可以用它来挂载一个由 Jekyll 提供支持的站点的所有作者的列表(实际上是一个播客的主机列表)。我希望这是在

+ \
  + _posts
  + _includes
  + _layouts
  + _config.yml
  + authors <-- Here

在我的 Jekyll 站点中,我已经看到 Jekyll 在那里呈现 markdown 文件。

但是,我不能把作者带到那里并用它来建立一个列表。

我正在使用此代码

<ul>
    {% for post in site.categories.authors %}
    <li><a href="{{ site.url }}{{ post.url }}">{{ post.title }}</a></li>
    {% endfor %}
</ul>

关于我应该如何做我想做的任何建议?我希望生成页面以返回列表中主机的名称,并为每个主机提供链接,例如

<a href="/authors/foo">This guy</a>
<a href="/authors/bar">That guy</a>
<a href="/authors/baz">That other guy</a>

要渲染的文件位于:

+ \
  + _posts
  + _includes
  + _layouts
  + _config.yml
  + authors
    + foo.md
    + bar.md
    + baz.md

【问题讨论】:

    标签: post jekyll podcast


    【解决方案1】:

    如果您想使用集合,则需要正确配置它们。但是当您需要添加额外的降价文件并且您不希望它们在_posts 中时,集合很有用。

    如果您想收藏,请查看this answer


    但我相信你需要的是Jekyll _data,而不是集合。

    为此,请在站点 root 中创建一个名为 _data 的文件夹,并将名为 authors.yml 的文件添加到其中。

    然后,您将要调用的数据添加到authors.yml

    - ref: 01
      name: Name Surname
      url: http://something.com
    
    - ref: 02
      name: Name Surname 2
      url: http://somethingelse.com
    

    然后通过液体调用它们:

    {% for author in site.data.authors %}
    <a href="{{ author.url }}">{{ author.name }}</a>
    {% endfor %}
    

    如果我误解了你的问题,我很抱歉......我真的希望能帮到你!

    【讨论】:

      猜你喜欢
      • 2021-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多