Configuring collections in Jekyll

by on
2 minute read

Expanding the possibilities

The Jekyll blog engine is amazing in its purpose of building and helping us to keep updated our posts. But sometimes we need something more customized to meet our necessities, right? Yeah, I know and that is the reason why we thought in writing this post.

While configuring this blog we faced this little stone in our path. We simply were able to derive our default directory structure to include our articles folder and better organize those things.

Now that the problem was solved we want to share it hoping that it could become useful to somebody.

The problem

Jekyll comes by default ready to deal with pages named posts, but fortunately it’s possible to expand this configuration to accomodate other types of content. This brings us the opportunity of well organize our content in groups.

That type of content (that share a common look, structure and purpose) are called collections by the Jekyll engine. Just adding a new folder prefixed by an underscore won’t turn its content into a collection.

It could be easy like that don’t you think? by the way that was my first thought. Ok, but what happens when you do that? The engine will solely ignore the fact you have Markdown pages in the folder and will make a raw copy of the files to the build destination folder. No Markdown processing for you, at all.

Making the trick

In order to make the Jekyll engine see our new folder as a collection of markdown pages folder is to configure it in a collections section in the _config.yml file as ilustrated in the snippet below:

...
collections:
- receipts
- bills
... 

This will make the engine treat our _receipts and _bills as repositories of pages written using Markdown syntax. This causes the pages to be parsed, built and transferred to the destination folder after the processing.

Attention! DO NOT USE the include section of the _config.yml. It will only make the engine copy the folders content without any Markdown processing. That’s not what we’re looking for.

That’s it! Now, since Jekyll doesn’t update the configuration data even with the --watch flag set, we just have to re-run the server and check the new behavior.

Would this worth a share? Thank you!

article, jekyll, configuring
comments powered by Disqus