I recently made this blog with Jekyll. It’s a nice little program once you get used to it’s methodology. Jekyll’s daughter, Octopress, touts itself as being “for hackers” and Jekyll itself isn’t much different in this respect.
The docs are lacking examples and this did throw me initially, even leading me to put off making the site for a month or so. Eventually I got round to building the site and found Jekyll to be almost pleasurable to work with.
There is a certain satisfaction to implementing your own features. When you use packages which do the heavy lifting for you, it’s often the case that it’s not quite how you’d like it and then you go around changing things anyway. (This was my experience with Octopress, which I eventually abandoned as I found it too opinionated.)
Categories & Tags
My biggest problem with Jekyll was its seeming lack of support for category and tag index pages. In a blog, visitors generally expect to be able to following tag and category links to a page listing other similarly-grouped pages.
Jekyll provides no clear cut way of implementing this, but it is possible and not complicated, so I’ll go through my own way of solving the problem.
The answer was in a Development Seed blog post on Jekyll. In particular, they mention how they had created a
search.json file via Jekyll which they use in their AJAX auto-complete searching.
While I wasn’t look for auto-completion, the idea of creating a JSON index of the site was perfect. I could create a script which searched the JSON index for some matching parameter that I passed. After a little thought on deciding how to pass what I wanted to display, I settled on using GET variables.
post.json partial in
search.json now generates an array containing all of the sites posts.
This is a blank
div which will hold the search results. I wanted to have tag and category pages, so in my post templates I linked categories with
The main script is pretty simple.
We have a map of objects we’d like to search (categories and tags), where
getParam(key) retrieves the value of the GET parameter with key
key. For the link
map, if the parameter has been specified we grab the JSON index, filter the posts which have the desired properties (posts which match e.g.
post.category == 'testing') and then display them.
layoutResultsPage is almost entirely site-specific. In my case, I cycle through each post appending a
li containing a few select properties (date, title, and tags) to a
- I only use one category per post, but the script should be generic enough to handle multiple categories.
- It is not designed to deal with multiple parameters such as
- As it is, the script is heavily tailored for my own use.
You can try out the script by clicking any tag or category on this site or this example.