Last active
December 12, 2023 12:08
-
-
Save wheybags/a3b3d59dd4e537a91fdeb2fd97a75363 to your computer and use it in GitHub Desktop.
gcc html madness
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -euxo pipefail | |
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | |
cd "$DIR" | |
# Treat as c source file: -x c | |
# Don't output line markers: -P | |
# Don't search system include path: -nostdinc | |
# Remove some predefined macros: -undef | |
my_cpp() { | |
cpp -x c -P -nostdinc -finput-charset=utf8 -undef $@ | |
} | |
# generates a header that undefines all the remaining predefined macros | |
my_cpp -dM - </dev/null | awk '{ print "#undef",$2; }' > /tmp/wheybags_com_undef.h | |
generate_page() { | |
local path | |
path="$(echo $1 | sed 's/^site\/tmp\/pages\///')" | |
echo $path | |
local parent_dir | |
parent_dir="$(dirname "$path")" | |
mkdir -p "site/$parent_dir" | |
my_cpp -I site/tmp -include /tmp/wheybags_com_undef.h "site/tmp/pages/$path" > "site/$path" | |
} | |
export -f generate_page | |
export -f my_cpp | |
rm -rf site/* || true | |
mkdir -p site/tmp | |
cp -r pages site/tmp/pages | |
cp -r template site/tmp/template | |
find site/ -type f -exec sed -i 's/\/\//DOUBLE_SLASH_CPP_FIX/g' {} \; | |
find site/tmp/pages -type f -exec bash -c 'generate_page "$0"' {} \; | |
rm -rf site/tmp | |
find site/ -type f -exec sed -i 's/DOUBLE_SLASH_CPP_FIX/\/\//g' {} \; | |
cp -r assets site/assets | |
cp favicon.ico site/favicon.ico |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment