summary refs log tree commit diff stats
path: root/ht.sh
diff options
context:
space:
mode:
Diffstat (limited to 'ht.sh')
-rwxr-xr-xht.sh18
1 files changed, 8 insertions, 10 deletions
diff --git a/ht.sh b/ht.sh index cc0d0ba..7f20255 100755 --- a/ht.sh +++ b/ht.sh
@@ -7,17 +7,14 @@ header_file=header.htm
7footer_file=footer.htm 7footer_file=footer.htm
8meta_file=meta.sh 8meta_file=meta.sh
9 9
10# state
11HTDAT="$(date +%s)"
12HT_TMPL_COUNT=0
13
14print() { 10print() {
15 printf '%s\n' "$*" 11 printf '%s\n' "$*"
16} 12}
17 13
18htt() { # htt FILE 14htt() { # htt FILE
19 # Like `cat`, but with templating. 15 # Like `cat`, but with templating.
20 ht_end="ht_main_${HTDAT}_${HT_TMPL_COUNT}" # be extra double sure 16 : "${HT_TMPL_COUNT:=0}"
17 ht_end="ht_main_$(date +%s)_${HT_TMPL_COUNT}" # be extra double sure
21 eval "$( 18 eval "$(
22 print "cat <<$ht_end" 19 print "cat <<$ht_end"
23 cat "$@" 20 cat "$@"
@@ -40,23 +37,24 @@ htmeta_clear() {
40 *) # other -- XXX: Don't know what to do 37 *) # other -- XXX: Don't know what to do
41 ;; 38 ;;
42 esac 39 esac
43 done <"$meta_file" 40 done <"$meta_file" 2>/dev/null
44} 41}
45 42
46htmeta() { # htmeta FILE 43htmeta() { # htmeta FILE
47 # Collect metadata from FILE. 44 # Collect metadata from FILE.
48 # Metadata looks like this: `;;@<SHELL_EXPRESSION>` 45 # Metadata looks like this: `;;@<SHELL_EXPRESSION>`
49 sed -n 's/^;;@//p' "$1" | tee "$meta_file" 46 sed -n 's/^;;@//p' "$1" 2>/dev/null | tee "$meta_file"
50} 47}
51 48
52main() { 49main() {
53 # Make two passes over each input file, collecting metadata and content. 50 # Make two passes over each input file, collecting metadata and content.
54 :
55 # Of course, this isn't safe, but you trust yourself, right? 51 # Of course, this isn't safe, but you trust yourself, right?
56 for file; do 52 for file; do
57 eval "$(htmeta_clear)" 53 eval "$(htmeta_clear)"
58 eval "$(htmeta "$file")" 54 eval "$(htmeta "$file")"
59 55 ./ht.awk <"$file" | htt "$header_file" - "$footer_file"
60 ./ht.awk <"$file" | htt "$header_file" - "$footer_file" >"${file}ml"
61 done 56 done
62} 57}
58
59test "$DEBUG" && set -x
60test "$SOURCE" || main "$@"