about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCase Duckworth2022-09-22 13:04:56 -0500
committerCase Duckworth2022-09-22 13:04:56 -0500
commitc22c2add6d38397c676eee1c36ba90c39e7c62fe (patch)
treec1926833f921573349a1d2544ad16487e0c85bfd
parentInitial commit (diff)
downloadshite-c22c2add6d38397c676eee1c36ba90c39e7c62fe.tar.gz
shite-c22c2add6d38397c676eee1c36ba90c39e7c62fe.zip
Changes
-rwxr-xr-xshite71
1 files changed, 51 insertions, 20 deletions
diff --git a/shite b/shite index ebd9e1e..aed47c0 100755 --- a/shite +++ b/shite
@@ -2,30 +2,36 @@
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
5expand() { 11expand() {
6 end="expand_$(date +%s)_${count:=0}" 12 end="expand_$(date +%s)_${count:=0}"
7 eval "$( 13 eval "$(
8 echo "cat <<$end" 14 echo "dog <<$end"
9 cat "$@" 15 dog <"$@"
10 echo 16 echo
11 echo "$end" 17 echo "$end"
12 )" && count=$((count + 1)) 18 )" && count=$((count + 1))
13} 19}
14 20
15body() { 21body() {
16 awk 'NR==1{next;}{print;}' 22 sed 1n
17} 23}
18 24
19phtml() { 25phtml() {
20 awk 'BEGIN{RS="";}/^[ \t]*</{print;next;}{print "<p>"$0"</p>";}' 26 sed -e '/./{H;1h;d;};x;s,^[ \n\t]\+,,;s,^[^<].*,<p>&</p>,'
21} 27}
22 28
23title() { 29title() {
24 awk 'BEGIN{FS=" ";}NR==1{print $1;quit;}' 30 sed '1s/\t.*$//;q'
25} 31}
26 32
27pubdate() { 33pubdate() {
28 awk 'BEGIN{FS=" ";}NR==1{print $2;quit;}' 34 sed '1s/^[^\t]*\t//;q'
29} 35}
30 36
31filters() { 37filters() {
@@ -35,8 +41,9 @@ filters() {
35pages() { 41pages() {
36 for file; do 42 for file; do
37 echo >&2 "$file" 43 echo >&2 "$file"
44 mkdir -p "$OUT"/"${file%.htm}"
38 filters <"$file" | 45 filters <"$file" |
39 expand .template.html >out/"${1%.html}"/index.html 46 expand .template.html >"$OUT"/"${file%.htm}"/index.html
40 done 47 done
41} 48}
42 49
@@ -44,7 +51,7 @@ index() {
44 for file; do 51 for file; do
45 echo >&2 "index: $file" 52 echo >&2 "index: $file"
46 echo "<li><a href=\"$file\">$(title "$file")</a></li>" 53 echo "<li><a href=\"$file\">$(title "$file")</a></li>"
47 done | expand .index.html >out/index.html 54 done | expand .index.html >"$OUT"/index.html
48} 55}
49 56
50feed() { 57feed() {
@@ -52,37 +59,61 @@ feed() {
52 echo >&2 "feed: $file" 59 echo >&2 "feed: $file"
53 echo "<item>" 60 echo "<item>"
54 echo " <title>$(title "$file")</title>" 61 echo " <title>$(title "$file")</title>"
55 echo " <link>$DOMAIN/${file%.html}/</link>" 62 echo " <link>$DOMAIN/${file%.htm}/</link>"
56 echo " <guid>$DOMAIN/${file%.html}/</guid>" 63 echo " <guid>$DOMAIN/${file%.htm}/</guid>"
57 if test -n "$(pubdate "$file")"; then 64 if test -n "$(pubdate "$file")"; then
58 echo " <pubDate>$(pubdate "$file")</pubDate>" 65 echo " <pubDate>$(pubdate "$file")</pubDate>"
59 fi 66 fi
60 echo "</item>" 67 echo "</item>"
61 done | expand .feed.xml >out/feed.xml 68 done | expand .feed.xml >"$OUT"/feed.xml
69}
70
71usage() {
72 dog <<EOF
73shite: shit out a site
74by Case Duckworth <acdw@acdw.net>
75:: USAGE ::
76shite [-h]
77shite [-d DOMAIN] [-C DIR] [-o DIR]
78:: FLAGS ::
79-h Show this help and exit
80:: OPTIONS ::
81-d DOMAIN Domain name to use as the base for URLs.
82 Default: \$PWD
83-C DIR Directory of source files for website.
84 Default: \$PWD
85-o DIR Directory for output files. Will be created.
86 Default: \$PWD/out
87EOF
88 exit ${1:-0}
62} 89}
63 90
64main() { 91main() {
65 DOMAIN="${SHITE_DOMAIN:-${PWD##*/}}" 92 DOMAIN="${SHITE_DOMAIN:-${PWD##*/}}"
66 SOURCE="$PWD" 93 SOURCE="$PWD"
67 while getopts d:C: opt; do 94 OUT=out
95 while getopts d:C:o:h opt; do
68 case "$opt" in 96 case "$opt" in
69 d) DOMAIN="$OPTARG" ;; 97 d) DOMAIN="$OPTARG" ;;
70 C) SOURCE="$OPTARG" ;; 98 C) SOURCE="$OPTARG" ;;
71 *) exit 1 ;; 99 o) OUT="$OPTARG" ;;
100 h) usage ;;
101 *) usage 1 ;;
72 esac 102 esac
73 done 103 done
74 shift "$((OPTIND - 1))" 104 shift "$((OPTIND - 1))"
75 105
76 cd "$SOURCE" 106 cd "$SOURCE"
77 mkdir -p out 107 mkdir -p "$OUT"
78 test -f .shite.sh && . .shite.sh 108 test -f ./.shite.sh && . ./.shite.sh
79 pages *.html 109 pages *.htm
80 index *.html 110 index *.htm
81 feed *.html 111 feed *.htm
82 for file in *; do 112 for file in *; do
83 test "${file#*.}" = html && continue 113 test "${file#*.}" = htm && continue
84 test "${file#*.}" = xml && continue 114 test "${file#*.}" = xml && continue
85 cp -r "$file" out/ 115 test "$file" = "$OUT" && continue
116 cp -r "$file" "$OUT"/
86 done 117 done
87} 118}
88 119