I read about the new JSON feed spec, and I was intrigued by the novelty of it—not the ease of using JSON as much as the insurmountable pain of using Atom XML.
Since I use Jekyll for my sites, writing the code would need to be done in Liquid without any plugins and Ruby code. I decided to extend the code for my Hafnia Times site and project, in part because the whole thing is open-sourced on GitHub.
It’s borderline stupid how easy it was, but here’s the code1 it took:
A few stray comments on this.
First, fields like
author depend on your particular implementation, and I didn’t feel like generalizing the code by using front-matter variables rather than just pasting the values directly.
Second, you’ll have to read the spec for the full deets on which fields are optional and mandatory; I want to get around to some fields that I’ve commented out for now in the code. Because Hafnia Times supports multiple authors, I can’t just put
post.author as you would in most cases.
If images don’t show up, it’s because they’re hotlink protected.
It’s really just that easy.
Update: Thought why not and added one for this blog at https://ndarville.com/feed.json:
It literally took me longer to write this blog post than the JSON feed code, because I couldn’t get Jekyll to escape the Liquid code example. I used the
.liquidextension in the gist, because Gist forces syntax-highlighting based on your extension. ↩︎