Collections in Jekyll

by Luke, Founder

Jekyll has introduced something called collections (beta at the time of writing) which has been added to handle custom post/page types.

The usual example is for a website that wants a blog and also a portfolio. The portfolio can be handled with collections.

Overall it works really well, but I did run into a few issues while setting it up against Jekyll 2.5.2. I thought I'd write these things down here to save myself and maybe others' time.

Firstly, in the Jekyll's _config.yml, I had some issues around the permalink. I initially set it to /work/:year/:title but for some reason :year just isn't working. I removed that section and still had odd problems. It turns out you have to include a slash at the end otherwise it gets confused about the output format. I ended up setting it to this: permalink: /work/:title/.

Second thing was around sorting. I wanted the collection items to be sorted descending by date. Using the sort | reverse in the for loop didn't work. Apparently, you cannot sort inside the for statement, who knew. This is how I did what I needed:

Gist: https://gist.github.com/2b4eaad90467b3a7c266

Jekyll is awesome for managing static sites. I've used it on a few sites, including this one. If you haven't tried it yet, you really should.

More articles

The Quotation Bank App — Bringing daily English Literature insights to students

We’re excited to share that **The Quotation Bank App** — developed in partnership with *The Quotation Bank* — is now live on the **App Store and Google Play**.

Read more

Enabling Apple Pay within Stripe Connect accounts

We've been working on a SaaS product for one of our clients and decided to use Stripe Connect to manage platform payments. Stripe Connect enables organizations onboarded into the…

Read more

Ready when you are

Let’s build something together

Whether you’re starting fresh or looking to improve things, we’re ready to talk.