Page 1 of 1

C Preprocessor HTML generation

Posted: Sunday, 12 January 2025 @ 19:54 EST
by noracodes
It's not a novel technique in the slightest, but I'm currently using the C preprocessor to process the HTML files for https://standingstones.neocities.org/, which is pending a rename but is something I intend to work on further. The script I'm using looks like this:

Code: Select all

#!/usr/bin/env bash
set -euxo pipefail

mkdir -p out/

shopt -s extglob
cp -r !(out) out/
shopt -u extglob

shopt -s globstar
for filename in **/*.html; do
	if [[ ! $filename =~ "out/" ]]; then
		mkdir -p "$(dirname $filename)"
		cpp -traditional-cpp -P "$filename" > "out/$filename"
	fi
done
shopt -u globstar
Essentially this copies everything to the out directory, processes all HTML files with cpp, replacing their unprocessed copies there, and then exits. I then just run `neocities push out` and that's that.

It's certainly not something I'd do for anything more complex, but it works remarkably well for what I want, which is just putting in a uniform header and footer.

Re: C Preprocessor HTML generation

Posted: Sunday, 12 January 2025 @ 20:07 EST
by Lady
I only know about it because it is written by the same person as wrote ‘Modern C’, which I am currently reading, but are you aware of EĿlipsis? It claims « Currently we have rudimentary support for lex and for general text processing languages, and more specifically for html and markdown. »

Re: C Preprocessor HTML generation

Posted: Sunday, 12 January 2025 @ 21:14 EST
by noracodes
I was not! It looks interesting, but it doesn't appear to be packaged anywhere, and I'm not sure how to build it; it appears to require GCC 14, which isn't available on any system I have access to right now.