summary refs log tree commit diff stats
path: root/ht.sh
diff options
context:
space:
mode:
Diffstat (limited to 'ht.sh')
-rwxr-xr-xht.sh62
1 files changed, 62 insertions, 0 deletions
diff --git a/ht.sh b/ht.sh new file mode 100755 index 0000000..cc0d0ba --- /dev/null +++ b/ht.sh
@@ -0,0 +1,62 @@
1#!/bin/sh
2# ht.sh
3# *.ht -> *html
4
5# config
6header_file=header.htm
7footer_file=footer.htm
8meta_file=meta.sh
9
10# state
11HTDAT="$(date +%s)"
12HT_TMPL_COUNT=0
13
14print() {
15 printf '%s\n' "$*"
16}
17
18htt() { # htt FILE
19 # Like `cat`, but with templating.
20 ht_end="ht_main_${HTDAT}_${HT_TMPL_COUNT}" # be extra double sure
21 eval "$(
22 print "cat <<$ht_end"
23 cat "$@"
24 print
25 print "$ht_end"
26 )"
27 HT_TMPL_COUNT=$((HT_TMPL_COUNT + 1))
28}
29
30htmeta_clear() {
31 # Generate metadata-clearing commands from $meta_file.
32 while read -r line; do
33 case "$line" in
34 *'()'*) # function
35 unset -f "${line%()*}"
36 ;;
37 *=*) # variable assignment
38 unset -v "${line%=*}"
39 ;;
40 *) # other -- XXX: Don't know what to do
41 ;;
42 esac
43 done <"$meta_file"
44}
45
46htmeta() { # htmeta FILE
47 # Collect metadata from FILE.
48 # Metadata looks like this: `;;@<SHELL_EXPRESSION>`
49 sed -n 's/^;;@//p' "$1" | tee "$meta_file"
50}
51
52main() {
53 # Make two passes over each input file, collecting metadata and content.
54 :
55 # Of course, this isn't safe, but you trust yourself, right?
56 for file; do
57 eval "$(htmeta_clear)"
58 eval "$(htmeta "$file")"
59
60 ./ht.awk <"$file" | htt "$header_file" - "$footer_file" >"${file}ml"
61 done
62}