【问题标题】:Jekyll collection not working on github.pagesJekyll 集合在 github.pages 上不起作用
【发布时间】:2014-07-10 15:06:43
【问题描述】:

按照 Jekyll 文档 http://jekyllrb.com/docs/collections/ 中的说明,我在我的 jekyll 博客中为开发人员相关的帖子创建了一个集合

collections:
  developer:
    output: true

在 jekyll 页面上,我尝试输出这样的帖子列表

  <ul class="posts">
    {% for post in site.developer %}

      <li>
        <span class="post-date">{{ post.date | date: "%b %-d, %Y" }}</span>
        <a class="post-link" href="{{ post.url | prepend: site.baseurl }}">{{ post.title }}</a>

       <p>{{ post.excerpt }}</p>
      </li>

    {% endfor %}
  </ul>

这适用于我的本地计算机。我可以在

查看此收藏中的一篇帖子
http://localhost:4000/developer/2014-07-07-blah-blah.html  

开发者帖子列表显示在开发者页面上

http://localhost:4000/developer/

但是,该列表在 github 页面上不可见,我无法访问该 url 上的帖子。否则,该博客在 github 页面上运行良好,即主页上的所有 site.posts 都是可见的等。

注意,我确实将文件推送到了 github。我可以在 repo 中看到它们。

【问题讨论】:

  • 我们能看到github repo吗?

标签: jekyll github-pages


【解决方案1】:

我的第一个猜测是“GitHub Pages”仍在使用过时的 Jekyll 版本。

GitHub 页面的Dependency versions 页面显示使用了 Jekyll 1.5.1。 但是集合功能是由 PR 2199 在 Jekyll 2.0.0 中引入的,请参阅 Jekyll 历史页面 here

如果是这种情况,那么您无能为力,除非您将存储库托管在其他地方,或者将编译后的源代码推送到 GitHub 页面。

【讨论】:

  • 截至 2014 年 8 月 21 日,jekyll 2.2 正在使用中。这是否表明现在可以使用集合?
  • @RyanTuck 是的。它现在正在我的 Jekyll 构建中使用。
【解决方案2】:

您不需要使用 Collection 来为帖子或页面生成自定义列表。

在你的前面添加:

---
...
flag: dev
---

带有标志 == dev 的页面列表示例

{% for page in pages %}
    {% if page.flag == 'dev' %}
    <li><a href="{{ site.baseurl }}{{ page.url }}">{{ page.title }}</a></li>
    {% endif %}
{% endfor %}

【讨论】:

  • 但是你这样做是为了分页。
猜你喜欢
  • 2013-12-20
  • 1970-01-01
  • 2023-03-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-07
  • 1970-01-01
相关资源
最近更新 更多