summaryrefslogtreecommitdiff
path: root/bin/update_html
diff options
context:
space:
mode:
authorJohn J. Camilleri <john@digitalgrammars.com>2018-10-31 15:47:12 +0100
committerJohn J. Camilleri <john@digitalgrammars.com>2018-10-31 15:47:12 +0100
commit7867c8c8287c4430d6fd5c8aed2e581ca4a9186d (patch)
treeaabea5a4f4a1429cc84d419f7863ed286b280876 /bin/update_html
parent632cd1e522f9f8b626b3acc661799cc81d29c728 (diff)
pre and post HTML templates for all txt2tags conversions
Remaining: cleaning of t2t files (remove unnecessary options)
Diffstat (limited to 'bin/update_html')
-rwxr-xr-xbin/update_html33
1 files changed, 31 insertions, 2 deletions
diff --git a/bin/update_html b/bin/update_html
index 75f54b13e..7777c7895 100755
--- a/bin/update_html
+++ b/bin/update_html
@@ -3,9 +3,38 @@
### This script finds all .t2t (txt2tags) files and updates the corresponding
### .html file, if it is out-of-date.
+config=".txt2tagsrc"
+pre="_pre.html"
+post="_post.html"
+tmp="tmp.html"
+
find . -name '*.t2t' | while read t2t ; do
html="${t2t%.t2t}.html"
if [ "$t2t" -nt "$html" ] ; then
- txt2tags -thtml "$t2t"
+ txt2tags --config-file="$config" --target=html "$t2t"
+ cat $pre $html $post > $tmp
+ mv $tmp $html
+ head1=$(head -n 1 "$t2t")
+ head2=$(tail -n+2 "$t2t" | head -n 1)
+ head3=$(tail -n+3 "$t2t" | head -n 1)
+
+ # Replace "headers" from t2t in final HTML
+ # Documentation here: https://txt2tags.org/userguide/headerarea
+ if [ -n "$head1" ] ; then
+ sed -i.bak "s/{{HEAD1}}/$head1/" "$html" && rm "$html.bak"
+ else
+ sed -i.bak -E "s/<.+{{HEAD1}}.+>//" "$html" && rm "$html.bak"
+ continue # empty headers
+ fi
+ if [ -n "$head2" ] ; then
+ sed -i.bak "s/{{HEAD2}}/$head2/" "$html" && rm "$html.bak"
+ else
+ sed -i.bak -E "s/<.+{{HEAD2}}.+>//" "$html" && rm "$html.bak"
+ fi
+ if [ -n "$head3" ] ; then
+ sed -i.bak "s/{{HEAD3}}/$head3/" "$html" && rm "$html.bak"
+ else
+ sed -i.bak -E "s/<.+{{HEAD3}}.+>//" "$html" && rm "$html.bak"
+ fi
fi
-done \ No newline at end of file
+done