Discourse as a CMS for a Jekyll site

I’m a big user of both Discourse and Jekyll, and recently I’ve been experimenting with trying to use a Discourse instance as a content management system for a Jekyll static site. I have only just begun playing around with this and part of my reason for posting at this stage is just to see if anyone else has already done this or similar. Alternatively you might have a better way and talk me out of wasting any time on it :grin:

How I envisage it would work

  • Markdown content would be edited in a Discourse instance (giving non-technical users a nice UI for editing) and can be easily re-edited, updated etc. Formatting toolbar and other niceties make the non-techy user much happier.

  • In the Jekyll site is a YAML file containing an array of post URLs (or post IDs if we decide the baseUrl of the Discourse is always the same one…) which should be polled for content.

  • A simple Jekyll plugin would run a hook to poll each URL (at each restart of the Jekyll server?) and GET the data. (For many ‘open’ Discourse instances no auth would be required. In some circumstances an API key would need to be supplied)

  • The JSON content is downloaded from the URL by adding.json, and the raw key of this JSON object contains the Markdown as a string wrapped in double quotes.

  • Jekyll YAML front matter would need to be added to the Markdown, and cleanup such as the wrapping quotes removed and \n newlines replaced.

  • Jekyll builds these entire pages into HTML, or you could {{include file | markdownify }} them into other pages.

Why bother?

  • Makes it way easier for a non-technical editor or maintainer to update a static site.

  • Ideal if you already have a Discourse and want to make a static website eg for a business.

  • Static sites are cheap, reliable and secure.

  • Why not use Page Publishing? When I’ve tried it, the pages seem to need a lot of work to make them look good. Jekyll allows more control, and of course allows a mixture of Discourse-managed and non-Discourse-managed content sources.

Thoughts from the community? Is this worth pursuing?

5 Likes

This is totally worth pursuing. But I am biased: I have been working on a similar thing a few years ago as a hobby project.

Goal was not only to be able to create a Jekyll site from curated content in Discourse, but to be able to publish it as an (epub or pdf) e-book as well (which is my answer to the ‘why not use page publishing’ question)

I followed pretty much the same approach with a yml file and an array of post URLs.
Images were a thing but I still have the python code lying around that gets all upload:// links, decodes them, downloads and resizes the images and changes the links to local image URLs.

I never finished the project but I would certainly be interested in picking this up again and to contribute the (few) things I already made.

4 Likes

Thanks! I will see if I can give it some time in coming months.

Don’t suppose you have any of the code in a GitHub repo?

I took a deeper look and it seems like only the images code would be worth surviving, and please don’t mind the code style (or lack thereof).
I’ve made a gist: retrieve images from a raw discourse post · GitHub

Sounds amusing. I have a client that has sort-of done the same thing by using tags to let users generate resumes (though it’s all just rendered in Discourse).

See also https://meta.discourse.org/posts/1001736/raw

2 Likes

Even better, thanks!

1 Like