Last night I had the strange sensation that as I was dreaming, my conscious mind was also turning over a programming idea, one that still kind of made sense when I woke up: what if I were to write a static site generator… in zsh?
Maybe it’s not as crazy as it sounds! Think about some of the things that shell scripts make easy:
- Enumerating, reading, and writing files
- Gluing together external commands
- Making substitutions in text
And at a high level, what does a static site generator do?
- It discovers the files in a certain directory.
- It probably converts each file from Markdown to HTML using some library.
- It transcludes each bit of HTML into a template, with the choice of template (“page,” “post,” “note,” etc.) usually determined by the file path.
- It saves the resulting files under new names.
For a number of reasons which aren’t particularly interesting, I’ve grown dissatisfied with Jekyll, the tool that generates this site right now, and I’ve been thinking about the form a replacement might take. (Like many hapless programmers, I would want to create my own.)
I use Haskell and zsh for most of my hobby programming. The former would be the obvious candidate for a Serious Application like a static site generator, but maybe the latter is suited to the problem domain too. To be sure, it wouldn’t be very fun to parse my Markdown files’ YAML headers with a shell script; there are disadvantages to using a language whose two types are “string” and “strings.” Shell scripts are also not exactly known for their speed. But zsh in particular lets you write text manipulation one-liners which in Haskell would require a Ph.D. and three
If I do take the plunge and write my own static site generator, I’ll probably end up doing it in Haskell. But I’ll keep the possibility of a zsh version in the back of my mind. I could call it Tartini.