It’s a new phase, so I’m re-evaluating my life and tech choices yet again. This time, I identify as a C programmer. I’m moving to C-based software and trying to script everything with C. So why not move my website from Lisp to C too? To C preprocessor, actually.
There are several inspirations for this idea:
So, technically, I’m not the first one to generate a website with C preprocessor (let’s call it CPP. But I’m up to the challenge of making it actually usable and pretty! The page you’re looking at is generated with C preprocessor, so consider that a success.
CPP is quite dumb: it operates on code that’s not even parsed yet. Which is bad if you want to make Lisp-like macros. And good if you want to embed some text or files into arbitrary text. Even if this text is HTML. So preprocessor is a templating engine of sorts.
But CPP possesses several advantages over tools like Mustache:
Preprocessor also has built-in recursive file inclusion.
One can write HTML files with preprocessor directives in them.
Here’s how a template file (say,
<head> <title> PAGE_TITLE </title> #ifdef PAGE_DESCRIPTION <meta name="description" content=PAGE_DESCRIPTION/>; #endif </head>
You can then
Preprocessor, as any templating engine, has some special chars that you have to handle. And preprocessor doesn’t make it easy to work with these.
Given all these problems with chars and the fact that preprocessor is scary, is it worth it? Actually, yes. The preprocessor-based setup abstracts away the repetitive parts, while keeping things simple and portable enough. And, however painful it is to acknowledge, it’s simpler than my previous Lispy setup.
You can review all of my build code here:
Update December 2024: I rewrote the whole thing in ed(1).