← til

Adding a hidden collection in Jekyll

December 18, 2018
jekyll

TIL is the hidden section of this site, and since I'm using Jekyll as an engine, I needed to learn how to add a new section.

To add new collection to Jekyll, you have to first define it in _config.yml.

collections: 
  til:
    output: true
    permalink: /:collection/:title

After that, create a folder for that collection beginning with the underscore:

mkdir _til

Place all the posts related to that collection in that folder.

You can now iterate that collection in some other page with

{% for post in site.til %}
  <li class="post">
    <h3 class="post-title">
      <a href="{{ post.url }}">
        {{ post.title }}
      </a>
    </h3>

    <span class="post-date">
      {{ post.date }} in {{ post.categories | join ', ' }}
    </span>
  </li>
{% endfor %}

A good idea would be to place this logic in til/index.html, since then that will be rendered when someone visits /til.