diff options
-rwxr-xr-x | shite | 50 |
1 files changed, 22 insertions, 28 deletions
diff --git a/shite b/shite index 74bd9af..951498b 100755 --- a/shite +++ b/shite | |||
@@ -2,38 +2,26 @@ | |||
2 | # shite --- shit out a site | 2 | # shite --- shit out a site |
3 | # by C. Duckworth <acdw@acdw.net> | 3 | # by C. Duckworth <acdw@acdw.net> |
4 | 4 | ||
5 | dog() { | ||
6 | while IFS= read -r line; do | ||
7 | printf '%s\n' "$line" | ||
8 | done | ||
9 | } | ||
10 | |||
11 | expand() { | 5 | expand() { |
12 | end="expand_$(date +%s)_${count:=0}" | 6 | end="expand_$(date +%s)_${count:=0}" |
13 | eval "$( | 7 | eval "$( |
14 | echo "dog <<$end" | 8 | echo "cat <<$end" |
15 | dog <"$1" | 9 | cat "$1" |
16 | echo | 10 | echo |
17 | echo "$end" | 11 | echo "$end" |
18 | )" && count=$((count + 1)) | 12 | )" && count=$((count + 1)) |
19 | } | 13 | } |
20 | 14 | ||
21 | body() { | ||
22 | # because the metadata is in a comment, we can just | ||
23 | dog | ||
24 | # the whole input. | ||
25 | } | ||
26 | |||
27 | phtml() { | 15 | phtml() { |
28 | sed -e '/./{H;1h;$!d;};x;s,^[ \n\t]\+,,;s,^[^<].*,<p>&</p>,' | 16 | sed -e '/./{H;1h;$!d;};x;s,^[ \n\t]\+,,;s,^[^<].*,<p>&</p>,' |
29 | } | 17 | } |
30 | 18 | ||
31 | meta() { | 19 | meta() { |
32 | tmp="/tmp/$file.meta" | 20 | metaf="/tmp/$file.meta" |
33 | echo "$tmp" >>/tmp/shite.tmp | 21 | echo "$metaf" >>"$RMF" |
34 | test -f "$tmp" || | 22 | test -f "$metaf" || |
35 | sed -n '/<!--/,/-->/p' >"$tmp" | 23 | sed '/<!--/n;/-->/q' >"$metaf" |
36 | sed -n "s/^[ \t]*$1:[ \t]*//p" "$tmp" | 24 | sed -n "s/^[ \t]*$1:[ \t]*//p" <"$metaf" |
37 | } | 25 | } |
38 | 26 | ||
39 | title() { | 27 | title() { |
@@ -45,15 +33,19 @@ pubdate() { | |||
45 | } | 33 | } |
46 | 34 | ||
47 | filters() { | 35 | filters() { |
48 | body | phtml | 36 | phtml |
49 | } | 37 | } |
50 | 38 | ||
51 | pages() { | 39 | pages() { |
52 | for file; do | 40 | for file; do |
53 | echo >&2 "[build] $file" | 41 | echo >&2 "[build] $file" |
54 | mkdir -p "$OUT"/"${file%.htm}" | 42 | outd="$OUT/${file%.htm}" |
55 | filters <"$file" | | 43 | outf="$outd/index.html" |
56 | expand .template.html >"$OUT"/"${file%.htm}"/index.html | 44 | datf="/tmp/$file.dat" |
45 | echo "$datf" >>"$RMF" | ||
46 | mkdir -p "$outd" | ||
47 | filters <"$file" >"$datf" | ||
48 | expand .template.html <"$datf" >"$outf" | ||
57 | done | 49 | done |
58 | } | 50 | } |
59 | 51 | ||
@@ -64,7 +56,7 @@ index() { | |||
64 | done | expand .index.html >"$OUT"/index.html | 56 | done | expand .index.html >"$OUT"/index.html |
65 | } | 57 | } |
66 | 58 | ||
67 | feed() { | 59 | feed() { # generates RSS 2.0 |
68 | for file; do | 60 | for file; do |
69 | echo >&2 "[feed] $file" | 61 | echo >&2 "[feed] $file" |
70 | echo "<item>" | 62 | echo "<item>" |
@@ -79,7 +71,7 @@ feed() { | |||
79 | } | 71 | } |
80 | 72 | ||
81 | usage() { | 73 | usage() { |
82 | dog <<EOF | 74 | cat <<EOF |
83 | shite: shit out a site | 75 | shite: shit out a site |
84 | by Case Duckworth <acdw@acdw.net> | 76 | by Case Duckworth <acdw@acdw.net> |
85 | :: USAGE :: | 77 | :: USAGE :: |
@@ -100,9 +92,9 @@ EOF | |||
100 | 92 | ||
101 | cleanup() { | 93 | cleanup() { |
102 | while read f; do | 94 | while read f; do |
103 | rm "$f" | 95 | rm "$f" >/dev/null 2>&1 |
104 | done </tmp/shite.tmp | 96 | done <"$RMF" |
105 | rm /tmp/shite.tmp | 97 | rm "$RMF" |
106 | } | 98 | } |
107 | 99 | ||
108 | main() { | 100 | main() { |
@@ -110,6 +102,7 @@ main() { | |||
110 | DOMAIN="${SHITE_DOMAIN:-${PWD##*/}}" | 102 | DOMAIN="${SHITE_DOMAIN:-${PWD##*/}}" |
111 | SOURCE="$PWD" | 103 | SOURCE="$PWD" |
112 | OUT=out | 104 | OUT=out |
105 | RMF=/tmp/shite.rm | ||
113 | while getopts d:C:o:h opt; do | 106 | while getopts d:C:o:h opt; do |
114 | case "$opt" in | 107 | case "$opt" in |
115 | d) DOMAIN="$OPTARG" ;; | 108 | d) DOMAIN="$OPTARG" ;; |
@@ -123,6 +116,7 @@ main() { | |||
123 | 116 | ||
124 | cd "$SOURCE" | 117 | cd "$SOURCE" |
125 | mkdir -p "$OUT" | 118 | mkdir -p "$OUT" |
119 | alias body=cat | ||
126 | test -f ./.shite.sh && . ./.shite.sh | 120 | test -f ./.shite.sh && . ./.shite.sh |
127 | pages *.htm | 121 | pages *.htm |
128 | index *.htm | 122 | index *.htm |