about summary refs log tree commit diff stats
path: root/shite
diff options
context:
space:
mode:
Diffstat (limited to 'shite')
-rwxr-xr-xshite90
1 files changed, 90 insertions, 0 deletions
diff --git a/shite b/shite new file mode 100755 index 0000000..ebd9e1e --- /dev/null +++ b/shite
@@ -0,0 +1,90 @@
1#!/bin/sh
2# shite --- shit out a site
3# by C. Duckworth <acdw@acdw.net>
4
5expand() {
6 end="expand_$(date +%s)_${count:=0}"
7 eval "$(
8 echo "cat <<$end"
9 cat "$@"
10 echo
11 echo "$end"
12 )" && count=$((count + 1))
13}
14
15body() {
16 awk 'NR==1{next;}{print;}'
17}
18
19phtml() {
20 awk 'BEGIN{RS="";}/^[ \t]*</{print;next;}{print "<p>"$0"</p>";}'
21}
22
23title() {
24 awk 'BEGIN{FS=" ";}NR==1{print $1;quit;}'
25}
26
27pubdate() {
28 awk 'BEGIN{FS=" ";}NR==1{print $2;quit;}'
29}
30
31filters() {
32 body | phtml
33}
34
35pages() {
36 for file; do
37 echo >&2 "$file"
38 filters <"$file" |
39 expand .template.html >out/"${1%.html}"/index.html
40 done
41}
42
43index() {
44 for file; do
45 echo >&2 "index: $file"
46 echo "<li><a href=\"$file\">$(title "$file")</a></li>"
47 done | expand .index.html >out/index.html
48}
49
50feed() {
51 for file; do
52 echo >&2 "feed: $file"
53 echo "<item>"
54 echo " <title>$(title "$file")</title>"
55 echo " <link>$DOMAIN/${file%.html}/</link>"
56 echo " <guid>$DOMAIN/${file%.html}/</guid>"
57 if test -n "$(pubdate "$file")"; then
58 echo " <pubDate>$(pubdate "$file")</pubDate>"
59 fi
60 echo "</item>"
61 done | expand .feed.xml >out/feed.xml
62}
63
64main() {
65 DOMAIN="${SHITE_DOMAIN:-${PWD##*/}}"
66 SOURCE="$PWD"
67 while getopts d:C: opt; do
68 case "$opt" in
69 d) DOMAIN="$OPTARG" ;;
70 C) SOURCE="$OPTARG" ;;
71 *) exit 1 ;;
72 esac
73 done
74 shift "$((OPTIND - 1))"
75
76 cd "$SOURCE"
77 mkdir -p out
78 test -f .shite.sh && . .shite.sh
79 pages *.html
80 index *.html
81 feed *.html
82 for file in *; do
83 test "${file#*.}" = html && continue
84 test "${file#*.}" = xml && continue
85 cp -r "$file" out/
86 done
87}
88
89test -n "$DEBUG" && set -x
90test -n "$SOURCE" || main "$@"