9/17/2021, 2:52:14 PM
In case you were wondering, this blog is:
I managed to stand up a minimal version of this (sans styling) in a single afternoon1. Here's how it works, and some caveats.
Using Gist as a data store is not a novel idea, I've seen it reproduced a number of times by other people. It's free, there's an API, and I don't have to worry about backups, since the service itself can be considered an off-site backup separate from the web server serving the blog.
ww9 suggested in his guide that appending
#blog to your gist title would allow it to be filterable – N.B. this ended up not being the case, but I still appended the tag and did the filtering from within the Node app itself.
node-fetch to retrieve the gists, and stored the result in-memory, along with the ETag present in the response header.
Every time the page loads, I send a
HEAD request to that same URL, and compare ETags. If there is a mismatch, I update the gists stored in-memory. I didn't want to be a bad consumer (of a free API, no less!) and continually hit the route on each page load, if the data hadn't changed.
So far so good, but some things I have noticed:
created_atdate returned by GitHub will always be the date the Gist was created.
meta.jsonallowed me to save some arbitrary data to each blog post, such as a timestamp override.
per_pageargument increases this to 100, but after that, I will have to build additional logic to handle additional pages2
1 This wasn't meant to be a humblebrag. Between my 2-year-old toddler and a newborn, I needed to move fast or this wasn't getting off the ground at all! It looked ugly, but it did its job.
2 sigh... even in my hobby projects, feature creep finds a way.