Collections

For once a straightforward update to the site! While working on the genealogy section of the site, I learned about Jekyll’s collections functionality and implemented the section as a collection. This was as simple as adding four lines of code to _config.yml, including one line to call NiklasEi’s Jekyll custom permalinks gem. This in turn was easily installed by adding gem 'jekyll_custom_permalink', '~> 0.0' to my Gemfile, and then running bundle install on the Pi.

Having implemented one collection, my mind was now open to all of the possibilities that collections afford. But, in their default implementation, collections must be placed at the site root, which make the directory structure quite messy very quickly. There’s functionality to account for this, however, and so with another line of code, and some shuffling of folders in the repository, I was set. I pushed the changes, re-executed the server, and after a quick build, everything was up and running. To the user, everything looks the same as before, but now it is much cleaner in the back end.

This article at Jekyll One had some useful points of clarification for Jekyll’s documentation. This is the code in _config.yml:

collections_dir: collections
collections:
  genealogy:
    output: true
    custom_permalink_placeholders: ["sosa"]
    permalink: /genealogy/:sosa/:title/

Note the custom permalink to sort genealogy pages by Sosa-Stradonitz number, pulled from the yaml in each markdown file.

Also note that it is not necessary to add _posts to the list of collections in _config.yml, but the directory must be moved from the site root into the new collections directory, along with any other collections, in order for posts to continue to be accessible.

Up until now, the site had used separate _posts subdirectories within each page’s directory. I inverted this to make the collection cleaner, so now the directory looks like this:

_posts
 -- blog
  --- post01.md
  --- post02.md
 -- commonplace
  --- entry01.md
  --- entry02.md
 -- journal
  --- record01.md
  --- record01.md
 -- log
  --- log01.md
  --- log01.md

A final note: unlike _posts, the other default directories prefixed with an underscore that live in the site root—_layouts and _plugins—do not need to be moved into the collections directory.


Previous Update Next Update

« Markdown Journal Build Times »