From 9cbff995f6fcec9e91efda6baf2f896a1fc52772 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 3 Aug 2022 23:48:29 -0500 Subject: Make it like, work. --- footer.htm | 1 + header.htm | 2 ++ ht.sh | 18 ++++++++---------- test.ht | 2 +- 4 files changed, 12 insertions(+), 11 deletions(-) create mode 100644 footer.htm create mode 100644 header.htm diff --git a/footer.htm b/footer.htm new file mode 100644 index 0000000..0ceac0f --- /dev/null +++ b/footer.htm @@ -0,0 +1 @@ + diff --git a/header.htm b/header.htm new file mode 100644 index 0000000..14eeb22 --- /dev/null +++ b/header.htm @@ -0,0 +1,2 @@ + +${title} 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 footer_file=footer.htm meta_file=meta.sh -# state -HTDAT="$(date +%s)" -HT_TMPL_COUNT=0 - print() { printf '%s\n' "$*" } htt() { # htt FILE # Like `cat`, but with templating. - ht_end="ht_main_${HTDAT}_${HT_TMPL_COUNT}" # be extra double sure + : "${HT_TMPL_COUNT:=0}" + ht_end="ht_main_$(date +%s)_${HT_TMPL_COUNT}" # be extra double sure eval "$( print "cat <<$ht_end" cat "$@" @@ -40,23 +37,24 @@ htmeta_clear() { *) # other -- XXX: Don't know what to do ;; esac - done <"$meta_file" + done <"$meta_file" 2>/dev/null } htmeta() { # htmeta FILE # Collect metadata from FILE. # Metadata looks like this: `;;@` - sed -n 's/^;;@//p' "$1" | tee "$meta_file" + sed -n 's/^;;@//p' "$1" 2>/dev/null | tee "$meta_file" } main() { # Make two passes over each input file, collecting metadata and content. - : # Of course, this isn't safe, but you trust yourself, right? for file; do eval "$(htmeta_clear)" eval "$(htmeta "$file")" - - ./ht.awk <"$file" | htt "$header_file" - "$footer_file" >"${file}ml" + ./ht.awk <"$file" | htt "$header_file" - "$footer_file" done } + +test "$DEBUG" && set -x +test "$SOURCE" || main "$@" diff --git a/test.ht b/test.ht index 97425a9..58125a8 100644 --- a/test.ht +++ b/test.ht @@ -1,5 +1,5 @@ # ht: a bespoke document preparation system - +;;@title="ht: a bespoke document preparation system" ;; comments are like this. ;; they're a good time. -- cgit 1.4.1-21-gabe81