summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCase Duckworth2022-08-03 23:48:29 -0500
committerCase Duckworth2022-08-03 23:48:29 -0500
commit9cbff995f6fcec9e91efda6baf2f896a1fc52772 (patch)
treea681379eab64a526208e3228d3af23f2d02b575d
parentFix bug (diff)
downloadht-9cbff995f6fcec9e91efda6baf2f896a1fc52772.tar.gz
ht-9cbff995f6fcec9e91efda6baf2f896a1fc52772.zip
Make it like, work.
-rw-r--r--footer.htm1
-rw-r--r--header.htm2
-rwxr-xr-xht.sh18
-rw-r--r--test.ht2
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
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 "$@"
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