aboutsummaryrefslogtreecommitdiffstats
path: root/gen_html.sh
blob: b768c3631f0fd5cfc5a9305478f53a2514410b12 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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