列出杰基尔的所有收藏 [英] Listing all Collections in Jekyll

查看:47
本文介绍了列出杰基尔的所有收藏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm building a magazine site with Jekyll (v2.5.3). The docs on the Jekyll site led me to believe that I could list all the collections on my site, and embed YAML data for each collection in my _config.yml.

_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

index.html:

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 %}

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

I get two issues appearing on the homepage, but none of the data I'm accessing for each issue (name, date, title etc.) is appearing. I appreciate this is a beta feature, so just wanted to ask is this broken, or am I doing it wrong?

推荐答案

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

In {% for issue in site.collections %}, issue is an array that contains :

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"}

访问数据的正确方法是:

The right way to access datas is :

{% 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 %}

这篇关于列出杰基尔的所有收藏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆