diff options
author | Case Duckworth | 2022-08-03 23:48:29 -0500 |
---|---|---|
committer | Case Duckworth | 2022-08-03 23:48:29 -0500 |
commit | 9cbff995f6fcec9e91efda6baf2f896a1fc52772 (patch) | |
tree | a681379eab64a526208e3228d3af23f2d02b575d /ht.sh | |
parent | Fix bug (diff) | |
download | ht-9cbff995f6fcec9e91efda6baf2f896a1fc52772.tar.gz ht-9cbff995f6fcec9e91efda6baf2f896a1fc52772.zip |
Make it like, work.
Diffstat (limited to 'ht.sh')
-rwxr-xr-x | ht.sh | 18 |
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 | |||
7 | footer_file=footer.htm | 7 | footer_file=footer.htm |
8 | meta_file=meta.sh | 8 | meta_file=meta.sh |
9 | 9 | ||
10 | # state | ||
11 | HTDAT="$(date +%s)" | ||
12 | HT_TMPL_COUNT=0 | ||
13 | |||
14 | print() { | 10 | print() { |
15 | printf '%s\n' "$*" | 11 | printf '%s\n' "$*" |
16 | } | 12 | } |
17 | 13 | ||
18 | htt() { # htt FILE | 14 | htt() { # 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 | ||
46 | htmeta() { # htmeta FILE | 43 | htmeta() { # 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 | ||
52 | main() { | 49 | main() { |
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 | |||
59 | test "$DEBUG" && set -x | ||
60 | test "$SOURCE" || main "$@" | ||