Easy-Blog Oven
TL;DR: I made a new static site generator for my blog. It's not very clever. I've been calling it my "Easy-Blog Oven" and it seems to be working well so far.
I've tried a lot of tools for writing on the web. In fact, I've spent more time trying tools for writing on the web than actually writing on the web. My last round was writing my own thing using Gulp and Amazon S3 as a learning project. A couple of years later, I hooked it up to Travis CI to publish on a push to master.
I wrote 30 whole blog posts using that system! But, it felt slow and cumbersome. Also, I stopped using Gulp for any other projects. And, at some point, new versions of Node.js stopped running my site generator altogether. So, I've been putting off fixing that whole mess for a while.
But then, just this past week, I whipped up a quick static site generator for a project at work. All it does is this:
- Iterate through files and load them.
- Render HTML using tagged template literals.
After building that, it occurred to me: What if I just wrote a stupid simple script for my blog to iterate through all my entries? So, I tried it in a real quick sketch of code.
It was Aaron Swartz' "Bake, Don't Fry" blog post back in 2002 that first got me thinking about static site generators. Since this script started about as simple as a box with a light bulb in it, I started calling it my "Easy-Blog Oven".
I've accumulated over 1000 posts in the 18 years since I started a blog. I expected this naive script to take an annoyingly long time to run. It took 2 seconds. Turns out computers and Node.js are fast, these days. Hell, there's probably more data dredged up from a typical node_modules
folder than my entire blog.
Thus encouraged, I tried loading everything into memory. My computer's got lots of it. Then, it's just filter, map, reduce, and sort operations on arrays to generate index pages for posts by date and tag. Turning lists of posts into HTML with tagged template literals added an entire second to the execution time.
From there, I ported over a few more elaborations & complications from my old Gulp-based site generator. That added up to a whole six seconds of execution time. I'd bet I could find a few single web pages out there that take about as long to load as this thing takes to generate my whole site.
So anyway, I started all of this on Friday night. I spent a big chunk of Saturday continuing to tinker. And then, today, I learned enough about Github Actions get this thing building and uploading to Amazon S3.
The whole build and publish process now seems to take about 3 minutes. The longest part is uploading everything to Amazon S3, which could be greatly improved by just uploading what's changed. The site build itself only seems to take about 6-7 seconds. Pretty neat.
Now, let's see if I start using this thing again.