SpicyJekyll is a Jekyll plugin that adds sensible default behaviors to your custom collections. Like real spices, SpicyJekyll makes your custom collections tastier to consume. ♨️ 👍
Copy spicy_collections.rb
to your Jekyll plugins directory. That's it!
For each custom collection you have, add an entry to your collections
hash in _config.yml
:
collections:
authors:
recipes:
SpicyJekyll expects to see the members of that collection as files in _{collection-name}
in your configured source directory. For example, each recipe would be a file in _recipes
.
Then provide a refname
key to tell SpicyJekyll how to find these files. SpicyJekyll will look for files named ...<refname>-...
in this file and process them (see "Behavior" below).
collections:
authors:
refname: author
For example, you can organize your authors like this:
_authors/
author-smith-alice.markdown
author-feminella-john.markdown
author-gupta-steve.markdown
author-breckenridge-jen.markdown
The portion before the refname is reserved for your use so that you can have a convenient filename-based id-number sort if that's relevant to your collection. For example, if your authors have employee ID numbers and it's more useful to sort by those, then you can do that:
_authors/
000001-author-smith-alice.markdown
000002-author-feminella-john.markdown
000003-author-gupta-steve.markdown
000004-author-breckenridge-jen.markdown
If not, you can just ignore that, and use the first example.
Running SpicyJekyll on a custom collection has the following effects. Your collection will:
-
Be ordered by a
date
field. If you would rather sort by a different field, set thesort_by
key on your collection. For example, to sort by a field calledlast_name
, addsort_by: last_name
to your collection's metadata in_config.yml
. The sorting is in ascending order. If you want to sort by descending, use thereverse
filter. -
Have its documents augmented with
next
andprevious
references. The aforementioned ordering will be used to sort your collection. The first document will have anil
reference toprevious
and the last document will have anil
reference tonext. Each navigation reference is a hash containing
titleand
url` fields. This is helpful for showing next/previous navigation links in your templates, for instance. -
Be rigorously checked for a
title
property on each document. This prevents Jekyll's silent errors for missing keys. If a title is missing from any document, it will be considered a fatal error and your site's build will halt. -
Have stable permalinks. Every collection gets a permalink slug based on the filename. This lets you change the title or headline of the document without affecting its slug, so long as you leave the filename alone. This is helpful when you don't want to break URLs inadvertently.
-
Log what it's doing. For each member of the collection, Jekyll will log useful output to let you know that your element was processed. This lets you more quickly diagnose any issues that might be present in your collections.