Jekyll如何处理_posts/subdir中的帖子

cit*_*kid 10 jekyll

Jekyll Bootstrap项目在_posts/core-samples /目录中有一个示例博客文章.

我假设子主导中的帖子(文件)的处理方式与根目录中的帖子相同.它是否正确?

如果是这样,我将添加一个"stage"子目录,将其排除,这样我就可以停放帖子并通过移动它们来发布它们.

Che*_*ana 6

由于只是不同之处,post.path所以我同意你的说法:

子目录中的帖子(文件)的处理方式与目录中的帖子相同

您可以将帖子停放在目录中_posts/core-samples/,然后像这样发布它们:

{% for post in site.posts %}
  {% if post.path contains 'core-samples' %}
     ..your code
  {% endif %}
{% endfor %}  
Run Code Online (Sandbox Code Playgroud)

作为工作示例,您可能会看到此代码如何在其区域中发布这些停放的帖子


duh*_*ime 6

我最终来到这里是因为我想创建以下结构:

index.html
_animals
  cats
    my-cat.html
    ...
  dogs
    my-dog.html
    ...
Run Code Online (Sandbox Code Playgroud)

我创建了该结构,然后在_config.yml

collections:
  animals:
    output: true
    permalink: /animal/:title.html
Run Code Online (Sandbox Code Playgroud)

最后,让狗进来index.html

<div id='dogs'>
  {% for a in site.animals %}
    {% if a.path contains 'dogs' %}
      <a href='{{ a.url }}'>{{ a.title }}</a>
    {% endif %}
  {% endfor %}
</div>
Run Code Online (Sandbox Code Playgroud)

注意:这种方法要求包含所有记录的目录(_animals在我的示例中)不能被命名_posts,因为后者是 Jekyll 中的特殊名称。


cit*_*kid 5

无意中发现它在后yaml部分:

您可以指定帖子所属的一个或多个类别,而不是将帖子放在文件夹中.生成网站时,帖子的行为就像通常使用这些类别一样.类别(复数键)可以指定为YAML列表或空格分隔的字符串.

所以子目录==类别

  • 反过来说:`_posts`的*parent*目录成为一个类别.请参阅https://github.com/jekyll/jekyll/issues/1141#issuecomment-18363523 (5认同)
  • 据我通过测试可以看出,这是误导性的。也就是说,_posts 目录内的子目录似乎被忽略(未转换为类别)。你有不同的行为吗? (2认同)