Article Image
Article Image

[Links are still not up, doing this with a static website took a bit longer than expected, see the rest of the article for details.]

Inspired by my defunct series “Best Of Reddit”1 where I went through reddit once a month to find the best content of the month I had the idea of keeping a log with what are my top X items in a category (for example books, movies, …). I explain more about it in the Best Of homepage, but to make it quick, it is there mainly as a personal wiki.

It is still rather empty, but you get the idea. The page about books is the only one up at the moment and the only one really populated with anything.

I took the occasion to automate the process of generating such pages from a json file. As I’ve written in length, my website runs Jekyll so it doesn’t have a server and I can’t do anything too fancy. Whatever needs generating needs to run at build time. This is totally fine for this use case since all information needed are known at build time. I can have one json file for each category and have a script that given those files can generate a page for it. Luckily there is already a jekyll plugin that does just that: [datapage-gen][4].

[Next up we are going to configure the plugin to generate the various pages]

It seems that trying to parse data from a json file to generate multiple pages is something hard to do with jekyll. It works fine you want to read it and have it in one page, but when you try to split it it becomes a problem since Jekyll can’t generate files on the fly or dynamically look at the content of a folder. This can be solved using plugins, but the few I found did not work properly for my use case.

I’ve also tried going the collection route with no success. Collections in Jekyll are a different kind of pages that are focused on a specific element. But even with collection most of the work would be manual.

After a lot more digging it seems that the solution would be to combine both methods. Having a collection for the best of while using a plugin to generate the necessary files from the json. There is still a big unaddressed problem with this approach though, all plugins that I found cannot dynamically access the filesystem so you need to tell them for each json file to use as source their specific filename to be able to access it. I would much rather have a folder instead and everything dropped there would be generated.

  1. As a tribute to the series I’ve included a section about reddit as well. 

Blog Logo

Valentino Urbano



Valentino Urbano

iOS Developer, Swift, Writer, Husband

Back to Overview