I have a collection in my Jekyll site that I’d like to sort by name but ignoring articles like “the” and “a”. So, “The Cubicle” should go between “Cube” and “Dog”. If you know a magic way to do this that is different from my idea below, please suggest it.
My idea is to just add a front matter property to everything in the collection that would control the sort order, so I could keep “The Cubicle” for the name and have “Cubicle, The” for the new property (call it “sort name” or something). Is there a way I can save myself time and have the new property default to the same thing as name if I leave it out?
jekyll 4 (not on GH pages) has some sorting support, but not what you are asking for, just a way to specify how they sort which could be manageable for a small number of pages.
I think what you want to do is create a strip_articlefilter that you’d call before sort, but whether you want to create a custom plugin is another question.
module Jekyll
module ArticleFilter
def strip_article(input)
input.sub(/^(an? |the )\s*/i,"")
end
end
end
Liquid::Template.register_filter(Jekyll::ArticleFilter)