How to define a custom collection in Jekyll?

Following the Jekyll Collections documentation , I wrote the following code in _config.yml

_config.yml

collections: 
- popular_posts

So, when I print {{site.collections}}, the output is "popular_posts".

I also created the _popular_posts folder at the same level as the _posts. _popular_posts contains two .md files with some YAML controls, like a message.

However, if I print {{site.popular_posts}} or {{site.collections.popular_posts}}, there is no way out.

How can I Jekyll recognize .md files in this directory so that the following code works?

{% 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 %}
+4
source share
1 answer

! . _config.yml:

collections:
- popular_posts

Jekyll _popular_posts.

, (, _posts), _config.yml :

collections:
  popular_posts:
    output: true

/popular_posts/filename1.html /popular_posts/filename2.html, .

GitHub, , , .

jekyll-help , !

+4

Source: https://habr.com/ru/post/1544830/


All Articles