I Wrote a Static Site Generator in Bash

Published

I’ve mentioned and hinted at it in various posts over the years, but at last I have released a Super Duper Official™ v1.0.0 version of my personal project: bic.

The one-liner pitch is

Static site generator, in Bash.

Was it in an act of sadism? Boredom? Probably neither, more of just an idle curiosity of can I do it?” and I shot myself with another Bash footgun and kept on stumbling all the way til now.

But why Paul, why!?

I kinda said it above: I was curious if I could even do it? I think that’s how most things start, at least for me. I get curious about something. I learn more about it, and if it’s something that really sticks with me, I go about building my own version of that thing. In this instance, I’ve been curious about static site generators for years and decided I wanted to write my own incredibly opinionated version of one. But let’s make it extra tricky: we’ll do it in Bash.

Also, I really wanted a friend of mine, Mitch, to write his own personal blog and he promised he would if I made an artisanal bespoke static site generator (SSG). 🤓

I also firmly believe that these are the types of projects that keep me engaged and interested. I am the sole stakeholder and hell, I even have a user or two.

OK, but really… how?

At the core of it, a static site generator is effectively a mini, ephemeral ETL pipeline: glob some files, do some processing, and emit them to a directory.

I’ve never done ✨ real ✨ ETL (extract transform load) work in my career, so uh, my bad if I totally butchered that.

But really, that’s where this started. This is the exact content that I had in my todo.md file:

- [x] blog.sh (named it bic)
  - use typeset in example: https://github.com/davidmerfield/Typeset
  - use modernize.css or sanitize.css?
  + glob all .md files in posts/
  + render into index.html and .html
  + simple.css
  + /static -> / 

I had some basic, opinionated ideas on how I would want a SSG to work. And really, that’s how it started. I created the repository in early 2021 and had a MVP within a few days. A non-zero reason for choosing the name bic (bash + static) was the dot sh was available. :)

And technically, the core business logic all implemented in a single Bash script but for things like converting Markdown to HTML I use Pandoc plus Mustache (specifically the Bash implementation mo1) for templating and then I’ve been a huge fan of Hashids (now Sqids) so I wanted to leverage that too.

Any takeaways?

This got me really good at writing Bash. Not surprising, but you pick up on idiomatic patterns for a language when writing a project with some substance. 🤌

Plus, it’s fun to take a side project and treat it like a real product with things like proper documentation, CI/CD pipelines, and a test suite. Speaking of I also got pretty good with Bats.

But really, if you’re interested in a minimal & opinionated SSG, I truly think that bic is worth a look.


  1. I even found a bug: https://github.com/tests-always-included/mo/issues/75↩︎


I love hearing from readers so please feel free to reach out.

Reply via emailSubscribe via RSS or email

Last modified  #programming   #bash   #blogging 

🔗 Backlinks

← Newer post  •  Older post →