Skip to main content

Introducing JekyllBot

2 min read
: Automatically generate a JSON content API for Jekyll-based posts and pages. Uses Heroku, works with GitHub pages.

After making the move to Jekyll, one thing I lost was the ability to generate machine-readable representations of content. That may sound trivial, but it’s actually not considering the RESTful direction we’re heading, and is crucial to manipulate content on the frontend (for example, Backbone.js ). The idea being, for any post or page, if you simply replace the final / with .json, you should get an API.

I had previously written a short Jekyll plugin to generate JSON representations of posts, but GitHub Pages (where this site is hosted), doesn’t allow plugins for security reasons. Enter JekyllBot. JekyllBot lives on a (free) Heroku instance, and following any push to GitHub, silently generates JSON files for each post, pushing the changes back to GitHub. No need to do a thing. This allows you to continue to use web-based editors like Prose, and alleviates the need to ever touch the command-line.

How does it work? I added my Heroku instance as a post-receive hook in the repository’s settings page, and have JekyllBot running within Sinatra to listen for the payload. After a push, it simply runs Jekyll (with the plugin), commits to Git, and pushes the repository back to GitHub if there are any changes. The secret lies in the JSON generating plugin, which places the resulting files in the source directory (rather than _site), allowing the files to be tracked by Git, and thus silently passed through as static files by GitHub’s Pages servers when the site is built.

With a little customization, there’s no reason this process couldn’t work with most Jekyll plugins (for example, sitemaps, tag archives), allowing GitHub pages to support much more robust Jekyll implementations from within their existing security restrictions. Feel free to give JekyllBot a try on your own site, or simply add .json to the URL above to see it in action.

Originally published December 27, 2012 View revision history
Share

More to explore

Helpful 404s for Jekyll (and GitHub Pages)

3 min read

How to build 404 pages for Jekyll and GitHub Pages that automatically suggest similar URLs to those requested, using Levenshtein distance and your sitemap.

Jekyll: Where content is truly king

2 min read

Choosing Jekyll over a traditional CMS for government.github.com freed us to spend six months iterating on what mattered most — the content.

Welcome to the Post-CMS World

7 min read

Jekyll (and other static-sites) lead to simple, flexible, and reliable websites that allow for a renewed focus on what actually matters: the content.

Intro to GitHub for non-technical roles

10 min read

GitHub isn't just for developers. A practical guide for non-technical roles to follow along, collaborate, and track work with confidence.

Ben Balter

I'm Ben Balter — I write here about engineering leadership, open source, and showing your work. I wrote Open & Async, the playbook for remote and distributed teams. My open source projects have hundreds of millions of downloads. I was the Director of Hubber Enablement at GitHub, where I helped thousands of GitHubbers do their best remote work. Before this role: Chief of Staff for Security, enterprise PM, and GitHub's first Government Evangelist. Before GitHub: attorney, Presidential Innovation Fellow, and member of the White House's first agile development team. More about the author →

Follow along: Bluesky LinkedIn

This page is open source Help improve this article on GitHub