# 📎 Using ed(1) as My Static Site Generator By Artyom Bologov I have a long story with bipolar spikes making me re-evaluate my tech choices. You can observe it with multiple of my website setups: I started with Tripod, my Gemtext-oriented OOP Lisp engine . Then I used the DSLs Common Lisp provides to generate HTML from s-expressions . And, finally, I switched to C Preprocessor . And here’s a new flare-up, I guess? This time I’m testing the limits of what ed-family editors can do. Including parsing Lisp . And using ed as an everyday scripting environment . I’ve also tried ex/vi (not Vim!) To the point of making a Lisp programming config for it . But ex/vi are too troublesome, so forget it . Back to ed then! Here’s a compiler from high-level Modal system to ed, written in ed itself . Here’s a script processing Wisp syntax extension for Lisps . And here’s a whole category for ed tasks I solved on RosettaCode . The overarching narrative can be a transformation from one format to the other. Like... what site generators do? So I can use ed as my site generator, and get away with it? ## Setup: Glorified ed Scripts (#setup) So the way ed scripts are ran: =================================== sh =================================== ed -s file.html < script.ed ==================== Example script run ==================== This incantation - Opens a `file.html`, - Reads commands from stdin (redirected `script.ed`.) - And saves/writes (`w` command) file if there are respective commands in the stdin. A huge advantage is that I can swap commands in the script file. Replacing writing commands to printing ones, for example. This way, I can print the content of the post without modifying it. Y’know, for blog debugging (everyone does that?) With that general formula, I can abstract article builds per format with two scripts: a preprocessing (deabbreviation and escaped char expansion) script and the actual conversion. Here’s how my Makefile rule for .txt building looks like: =================================== =================================== %.txt: %.h -cp $^ $@ -ed -s $@ < scripts/preprocess.ed -ed -s $@ < scripts/totxt.ed ==================== Makefile implicit rule for conversion from .h to actual output text files ==================== Repeat this for every format (my site supports five atm) with dedicated `to*.ed` scripts. And that’s it! ## Advantages (#advantages) I can use whatever syntax I want now! With C Preprocessor, I was restricted to `X(ARG1, ARG2, ...)` structure for all my elements. With ed, I can go crazy with something like ``, imitating self-closing HTML tags. Or whatever. Closer to the way I model my writing. Another upside: I don’t have to rewrite all of my posts in a new format. My ed scripts are processing the old preprocessor-oriented format too! So ed is capable of replacing C Preprocessor and even adds some features on top. One more advantage is that there no longer are weird chars breaking everything. When I see an apostrophe, my eye starts twitching. C Preprocessor recognizes apostrophe as a char marker and reads the rest of the line verbatim. Same goes for double quote and hash. Special chars, forbidden magic. In general, ed has this sloppiness of regex/substitutions. And interactivity of a REPL (well, to an extent.) Perfect for text processing and document authoring. ## Limitations (#limitations) ed is stupid (I say lovingly.) It has no file inclusion, for one. So C Preprocessor’s `#include` is no longer accessible. I manage without it, because most of the files I include are easily hard-codeable. But the mere inability to include arbitrary files is somewhat alarming. Another problem that I already got the taste of: having arbitrary substitutions at the fingertips spoils me. I might end up with some really otherworldly syntax without noticing. And I wouldn’t be able to rollback to e.g. C Preprocessor to generate my posts. But then, ed is so simple and more or less standard, so what can go wrong? It did go wrong { Arch and Alpine package slightly different versions of ed. Alpine version was breaking on line joining and variable substitution. So I had to swap Alpine for Arch on the Gitlab CI. I would have been able to stay on Alpine if I was able to debug what’s wrong with ed there. But Gitlab (like any other CI platform?) doesn’t make it easy to debug things on CI. } ## Should You Use ed As Site Generator? (#you-too) No, not at all. It’s a weird choice that’s only there because I’m having a new phase. But still, it’s fun! Try ed if you have too much free time and are bored out of your mind 😜 Copyright 2022-2025 Artyom Bologov (aartaka). Any and all opinions listed here are my own and not representative of my employers; future, past and present.