将 jekyll 帖子限制在指定文件夹

limit jekyll posts to specified folder

我正在使用 Jekyll 构建网站,

我想要一些类似

的文件夹结构
root
   - _posts
       Kinds of MD files
   Index.html
   - v1.0
       - _posts
           Kinds of MD files
       Index.html

我想建一个网站,URL喜欢http://host/root/ points to current version document,the URL like http://host/root/v1.0指向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 文件夹有相似的 post 和类别,在 http://host/root/ 中,每个 post 显示两次。

  2. 在URLhttp://host/root/中,它有一个额外的类别,其中包含所有posts(在文件夹_posts和v1中.0/posts)

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

我想知道如何限制 site.categories 只搜索指定的文件夹?或者对此还有其他建议吗?

谢谢

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

如@ganeshkumar 所述,为此使用 jekyll 集合