The one where m4 is discussed
Have you ever put together a blog and thought, wow, this hypertext stuff is so straightforward? I know, it happens every time. Whether you are making your own personal hell in node or channelling the zeitgeist with hugo (a far nicer experience tbf) in the back of every programmer’s head is the thought, “how could I, in the search of true purity, make my life, somehow, more painful?”
No worries, m4 to the rescue.
Wikipedia describes m4 as “a general-purpose macro processor included in most Unix-like operating systems, and is a component of the POSIX standard.” Neat right? This is where I’d like to include a sample of what m4 looks like in practice. Maybe a simple for loop looks like in m4? Unfortunately, due to the inherently insidious nature of m4, every attempt to include this snippet leads to a stack overflow.
In lieu of that example how would I describe m?. As the wikipedia article states m4 is a macro processor. It reads keywords like, import
, ifdef
and __myarg
and expands the output replacing each keyword / function with the appropriate text. This is very useful for things like attaching partials (headers / footers) to every document. Whats even more exciting / dangerous is that combinations of these keywords extends m4 into a Turing complete language of its own.
While m4 may be Turing complete, not all Turing complete languages were created equal. Stray too far outside the well defined realm of m4 and you’ll soon run into some truly nightmarish code.
For the purpose of putting together a blog using this dark gandalf approach I’d recommend taking a look at Chrisman Brown’s post on m4. It walks you through some of the pitfalls of m4 and he provides a github repo with a template blog that you can take and modify to your hearts content.
Would I recommend using m4 over a static site generator like hugo, no. Have I built my blog using m4, yes. In truth, the selling point for me was the transparency and ease of deployment. Once the blog is setup, it only takes a 20 line makefile to make the whole thing tick.