diff options
| author | vosjedev <vosje+git@vosjedev.net> | 2025-10-09 16:26:09 +0200 |
|---|---|---|
| committer | vosjedev <vosje+git@vosjedev.net> | 2025-10-09 16:26:09 +0200 |
| commit | 2e66324e942fef01f44193e056279da1ec205a3f (patch) | |
| tree | 0d07dc40c1845bb07a441ab6d6d6e33fd92b3cc6 | |
| parent | 008d005340b0953b1074c6119804d94716bc607b (diff) | |
| download | acit-2e66324e942fef01f44193e056279da1ec205a3f.tar.gz acit-2e66324e942fef01f44193e056279da1ec205a3f.tar.bz2 acit-2e66324e942fef01f44193e056279da1ec205a3f.tar.xz | |
[html] Add infra for html files
| -rw-r--r-- | gen_html.sh | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/gen_html.sh b/gen_html.sh new file mode 100644 index 0000000..8a07020 --- /dev/null +++ b/gen_html.sh @@ -0,0 +1,42 @@ + + +cd html || { + "no html directory found" +} + +out=../src/sl_bot/web/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 + + + |
