I needed a simple static site generator, as one does. I only wanted to re-use the same template across multiple html files. Instead I created something accursed indeed.
I wrote a small program in C that generates C programs in PHP-like way. For example, for this input:
[#
#include <stdio.h>
int main(void) {
for (int i = 0; i < 5; ++i) {
#]
Iteration number <b>[# printf("%d", i); #]</b>
[#
}
}
#]
It generates output like this:
#include <stdio.h>
int main(void) {
for (int i = 0; i < 5; ++i) {
printf("%s", "Iteration number <b>");
printf("%d", i);
printf("%s", "</b>\n");
}
}
It's a very simple templating engine you see. Then I compile the resulting code and here's my page.
I can include other pages via the C preprocessor's #include mechanism.
Aand I also made a makefile. Surely this was easier than learning eleventy, right?..
I also implemented delimeters other than [# and #].
For instance, [@ ... @] make it so that the enclosed text
is simply pasted in the preprocessed C source code as a string literal.
And [$ ... $] generates a source code block, escaping html entities
when necessary.