C Preprocessor HTML generation

Discussion of tools for interacting with the Web: site generators, user agents, applications, and scripts. Publicly‐accessible.
Post Reply
User avatar
noracodes
Posts: 10
Joined: Saturday, 11 January 2025 @ 21:37 EST
Location: Chicago, IL
Contact:

C Preprocessor HTML generation

Post 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.
---
it/its | she/her | sina o toki e toki pona tawa mi! | sina ale o pana pali!
User avatar
Lady
Posts: 26
Joined: Saturday, 11 January 2025 @ 13:03 EST
Location: PHL
Contact:

Re: C Preprocessor HTML generation

Post 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. »
User avatar
noracodes
Posts: 10
Joined: Saturday, 11 January 2025 @ 21:37 EST
Location: Chicago, IL
Contact:

Re: C Preprocessor HTML generation

Post 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.
---
it/its | she/her | sina o toki e toki pona tawa mi! | sina ale o pana pali!
Post Reply