列出杰基尔的所有收藏

Jam*_*ale 6 jekyll

我正在用Jekyll(v2.5.3)建立杂志网站。Jekyll网站文档使我相信我可以列出网站上的所有集合,并将每个集合的YAML数据嵌入到我的中_config.yml

_config.yml:

collections:
  issue_001:
    output: true
    permalink: /:title/:path
    title: Rebirth
    date: 2015-07-01
  issue_002:
    output: true
    permalink: /:title/:path
    title: Talking Heads
    date: 2015-08-01
Run Code Online (Sandbox Code Playgroud)

index.html:

{% for issue in site.collections %}
  <li>
    <h6 class="post-meta">Issue {{ issue.name }} &mdash; {{ issue.date | date: "%b %-d, %Y" }}</h6>

    <h2>
      {{ issue.title }}
    </h2>
  </li>
{% endfor %}
Run Code Online (Sandbox Code Playgroud)

我在首页上看到两个问题,但是我没有为每个问题(名称,日期,标题等)访问任何数据。我很欣赏这是一个测试版功能,因此只想问一下它是否损坏,或者我做错了吗?

Dav*_*uel 7

在中{% for issue in site.collections %}issue是一个包含以下内容的数组:

0 => "issue_001",
1 => Hash
 {"output"=>true,
  "permalink"=>"/:title/:path",
  "title"=>"Rebirth",
  "date"=>#,
  "label"=>"issue_001",
  "docs"=>[#],
  "files"=>[],
  "directory"=>"/home/djacquel/www/test.dev/jekyll/wat/_issue_001",
  "relative_directory"=>"_issue_001"}
Run Code Online (Sandbox Code Playgroud)

正确的数据访问方式是:

{% for issue in site.collections %}
  <li>
    <h6 class="post-meta">
      Issue {{ issue[1].label }}
      &mdash;
      {{ issue[1].date | date: "%b %-d, %Y" }}
    </h6>
    <h2>
      {{ issue[1].title }}
    </h2>
  </li>
{% endfor %}
Run Code Online (Sandbox Code Playgroud)


spa*_*oid 7

如果有人仍然有此请求,则以下是最新的Jekyll(v3.8.3)中的工作方式:

{% for collection in site.collections %}
  <h2>Items from {{ collection.label }}</h2>
  <ul>
    {% for item in site[collection.label] %}
      <li><a href="{{ item.url }}">{{ item.title }}</a></li>
    {% endfor %}
  </ul>
{% endfor %}
Run Code Online (Sandbox Code Playgroud)