A Simple JSON Feed Implementation for Jekyll


by
339w

How to easily get a list of JSON feed items in the terminal.

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 icon, favicon, and 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.

That’s about it; check out my JSON feed code for Hafnia Times, compare it to the Atom feed code, and see the live result on JSON Feed Viewer.

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:

View blog in JSON Feed Viewer.

  1. 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 .liquid extension in the gist, because Gist forces syntax-highlighting based on your extension. ↩︎