GitHub Gists as a content management system
I often use GitHub Gists to jot down quick snippets to share. Lately, I've also tried to make sure an add a proper README (and a LICENSE!) - partially so that readers have some context on what they're looking at, but also so I can remember what the heck I was doing when I wrote whatever code I've slung out there.
Gists are horrible for discoverability, and I always forget the neat things I've hacked together. I wanted a section on my website with at minimum links, but hopefully the actual content from some of my "better" gists - with better defined as:
- is a gist that I've starred
- is one of my own gists
- has a
- is newer than 2017-01-01
I spent a little bit of time today hacking this together with bash, curl, and jq! I think it qualifies as just hacky enough to use as an example to validate this insane workflow :)
How it works
All the work happens in
pull-gists.sh. A brief walkthrough:
- Hit the GitHub API to look for my starred gists
- (ab)use jq to filter down to gists where I'm the owner, it's newer than a given date, and has a
- Iterate over the gists & extract a bunch of properties
- Write out some frontmatter (I'm using Hugo for my blog) to a file per gist / post
- Download the README as the post content
- A Hugo template adds embed script tags for each interesting file. (The README has already been added, and the LICENSE is just spam on a blog post)
On the backend, I'm currently hosted on Azure Storage + an Azure Function proxy as my frontend. The Hugo site gets built in Azure DevOps per-commit to master for regular posts. And I now have a daily build trigger to pick up new starred gists.
Putting it all together, this hacked together mess means I have a way to draft blog posts on https://gist.github.com/, then star them when I'm ready for them to go out. I'm pretty happy with this - I hope it sparks some interesting ideas for you as well!