【问题标题】:limit jekyll posts to specified folder将 jekyll 帖子限制到指定文件夹
【发布时间】:2016-07-19 05:26:49
【问题描述】:

我正在使用 Jekyll 构建一个网站,

我想要一些类似的文件夹结构

root
   - _posts
       Kinds of MD files
   Index.html
   - v1.0
       - _posts
           Kinds of MD files
       Index.html

我要建一个网站,http://host/root/这样的URL指向当前版本的文档,http://host/root/v1.0这样的URL指向1.0版本的文档。

在两个 index.html 中,我都使用如下代码,

  {% assign sortedCategories = site.categories | sort %}
  {% for category in sortedCategories %}
  <h1 class="post-title" id="{{ category[1] | replace:' ','-' | replace:'.','' }}">{{ category[1] | join: "/" | upcase }}</h1>
  <ul class="post-list">
    {% for posts in category %}
    {% for post in posts reversed %}
    {% if post.title != null%}
    <li>
      <h2 class="post-title" id="{{ post.id | remove_first:'/'}}">{{ post.title }}</h2>
      <article class="post-content">
        {{ post.content }}
      </article>
    </li>
    {% endif %}
    {% endfor %}
    {% endfor %}
  </ul>
  {% endfor %}

我遇到的问题是,

  1. 由于两个 _post 文件夹都有相似的帖子和类别,在 http://host/root/ 中,每个帖子显示两次。

  2. 在 URL http://host/root/ 中,它有一个包含所有帖子的附加类别(在文件夹 _posts 和 v1.0/posts 中)

  3. URL http://host/root/v1.0 的相同问题

我想知道如何将 site.categories 限制为仅搜索指定的文件夹?或者对此有什么其他的建议?

谢谢

【问题讨论】:

    标签: jekyll categories


    【解决方案1】:

    posts 不能仅限于特定文件夹,因为它是站点范围的。您可以创建自定义collection。假设您有 v1、v2 和 root(指向 v2)。您可以为 v2 和 root 使用相同的集合名称。

    【讨论】:

      【解决方案2】:

      正如@ganesshkumar 所说,为此使用 jekyll 集合

      【讨论】:

      • 嗨,欢迎来到 Stack Overflow。您能否详细说明如何 使用 Jekyll 集合来回答问题。谢谢。
      猜你喜欢
      • 2011-06-14
      • 1970-01-01
      • 2016-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多