cd html || {
"no html directory found"
}
out=../src/acit/html.py
exec >"$out" # write all STDOUT to the file
cat <<DOCSTR
"""
This file provides variables with HTML. It is automatically generated by running ``bash gen_html.sh``.
Do not edit directly.
"""
DOCSTR
#header="$(cat .header.html | tr '\n' ' ' | sed 's/\//\\\//g')"
for file in *; do
htmlname="${file%.html}"
htmlname="${htmlname//[^a-zA-Z0-9]/_}" # replace anything that isn't a letter or number with an underscore
: <<-NOTE
This breaks when the file contains """ somewhere, due to python closing the multiline string on that.
AFAIK we can't escape it.
NOTE
# remember that due to the exec >"$out" done earlier all the output of the echo and sed statements get redirected directly into the output file
# the sed acts as `cat` with a find-replace
echo "$htmlname"'="""' # open multiline string
sed 's/"""/\\"\\"\\"/g' "$file" # add the HTML itself, also replace all occurences of """ with escaped ones to prevent closing the string early
echo '"""' # close multiline string
echo "Included '$file' as html.$htmlname" >&2
done | sed '/<!-- INSERT PAGE HEADER -->/r .header.html'
#sed 's/^.*INSERT PAGE HEADER.*$/'"$header"'/' # this sed also inserts headers