diff options
-rw-r--r-- | footer.htm | 1 | ||||
-rw-r--r-- | header.htm | 2 | ||||
-rwxr-xr-x | ht.sh | 18 | ||||
-rw-r--r-- | test.ht | 2 |
4 files changed, 12 insertions, 11 deletions
diff --git a/footer.htm b/footer.htm new file mode 100644 index 0000000..0ceac0f --- /dev/null +++ b/footer.htm | |||
@@ -0,0 +1 @@ | |||
<!-- so ends ${file} --> | |||
diff --git a/header.htm b/header.htm new file mode 100644 index 0000000..14eeb22 --- /dev/null +++ b/header.htm | |||
@@ -0,0 +1,2 @@ | |||
1 | <!DOCTYPE html> | ||
2 | <title>${title}</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 | |||
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 "$@" | ||
diff --git a/test.ht b/test.ht index 97425a9..58125a8 100644 --- a/test.ht +++ b/test.ht | |||
@@ -1,5 +1,5 @@ | |||
1 | # ht: a bespoke document preparation system | 1 | # ht: a bespoke document preparation system |
2 | 2 | ;;@title="ht: a bespoke document preparation system" | |
3 | ;; comments are like this. | 3 | ;; comments are like this. |
4 | ;; they're a good time. | 4 | ;; they're a good time. |
5 | 5 | ||