Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Jekyll中定义自定义集合?_Jekyll_Liquid_Github Pages_Jekyll Bootstrap - Fatal编程技术网

如何在Jekyll中定义自定义集合?

如何在Jekyll中定义自定义集合?,jekyll,liquid,github-pages,jekyll-bootstrap,Jekyll,Liquid,Github Pages,Jekyll Bootstrap,接下来,我在_config.yml中编写了以下代码 _config.yml collections: - popular_posts 因此,当我打印{site.collections}}时,输出是“popular_posts” 我还制作了一个名为“\u popular\u posts”的文件夹,其级别与“\u posts”相同。 _popular_posts包含两个带有YAML前端内容的.md文件,与post相同 但是,如果打印{site.popular_posts}或{{site.col

接下来,我在_config.yml中编写了以下代码

_config.yml

collections: 
- popular_posts
因此,当我打印{site.collections}}时,输出是“popular_posts”

我还制作了一个名为“\u popular\u posts”的文件夹,其级别与“\u posts”相同。 _popular_posts包含两个带有YAML前端内容的.md文件,与post相同

但是,如果打印{site.popular_posts}或{{site.collections.popular_posts},则没有输出

如何让Jekyll识别该目录中的.md文件,以便下面的代码能够工作

{% for popular_post in site.popular_posts %}
  <a href="{{ popular_post.link }}">
    <h1>{{ popular_post.title }}</h1>
    <img class="pop-img" src="{{ popular_post.image_url }}">
  </a>
  <span id="pop-order"><span class="pop-current-popular_post-number">{{ popular_post.number }}</span>/5</span>
{% endfor %}
{%for popular_posts in site.popular_posts%}
{{popular_post.number}/5
{%endfor%}

这很简单!你在正确的轨道上。在
\u config.yml
中:

collections:
- popular_posts
这将告诉Jekyll读入
\u popular\u posts
中的所有文件

如果您希望这两个文件中的每一个都有相应的输出文件(如
\u posts
现在的工作方式),则需要将
\u config.yml
更改为:

collections:
  popular_posts:
    output: true
这将在
/popular\u posts/filename1.html
/popular\u posts/filename2.html
生成文件,每篇文章一页

收藏是如此,如果你在那里尝试,它会失败


如果需要,请查看更多帮助

您是否将
输出:
设置为
true
?我不完全理解集合,但据我所知,这是让Jekyll生成集合项所必需的。还要注意的是,collections功能据说是beta版的,可能还没有完全实现。