about summary refs log tree commit diff stats
path: root/shite
diff options
context:
space:
mode:
Diffstat (limited to 'shite')
-rwxr-xr-xshite50
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
5dog() {
6 while IFS= read -r line; do
7 printf '%s\n' "$line"
8 done
9}
10
11expand() { 5expand() {
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
21body() {
22 # because the metadata is in a comment, we can just
23 dog
24 # the whole input.
25}
26
27phtml() { 15phtml() {
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
31meta() { 19meta() {
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
39title() { 27title() {
@@ -45,15 +33,19 @@ pubdate() {
45} 33}
46 34
47filters() { 35filters() {
48 body | phtml 36 phtml
49} 37}
50 38
51pages() { 39pages() {
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
67feed() { 59feed() { # 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
81usage() { 73usage() {
82 dog <<EOF 74 cat <<EOF
83shite: shit out a site 75shite: shit out a site
84by Case Duckworth <acdw@acdw.net> 76by Case Duckworth <acdw@acdw.net>
85:: USAGE :: 77:: USAGE ::
@@ -100,9 +92,9 @@ EOF
100 92
101cleanup() { 93cleanup() {
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
108main() { 100main() {
@@ -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