#!/bin/sh # shite --- shit out a site # by C. Duckworth expand() { end="expand_$(date +%s)_${count:=0}" eval "$( echo "cat <<$end" cat "$1" echo echo "$end" )" && count=$((count + 1)) } phtml() { sed -e '/./{H;1h;$!d;};x;s,^[ \n\t]\+,,;s,^[^<].*,

&

,' } meta() { metaf="/tmp/$file.meta" echo "$metaf" >>"$RMF" test -f "$metaf" || sed '//q' >"$metaf" sed -n "s/^[ \t]*$1:[ \t]*//p" <"$metaf" } title() { meta title } pubdate() { meta pubdate } filters() { phtml } pages() { for file; do echo >&2 "[build] $file" outd="$OUT/${file%.htm}" outf="$outd/index.html" datf="/tmp/$file.dat" echo "$datf" >>"$RMF" mkdir -p "$outd" filters <"$file" >"$datf" expand .template.html <"$datf" >"$outf" done } index() { for file; do echo >&2 "[index] $file" echo "
  • $(title "$file")
  • " done | expand .index.html >"$OUT"/index.html } feed() { # generates RSS 2.0 for file; do echo >&2 "[feed] $file" echo "" echo " $(title "$file")" echo " $DOMAIN/${file%.htm}/" echo " $DOMAIN/${file%.htm}/" if test -n "$(pubdate "$file")"; then echo " $(pubdate "$file")" fi echo "" done | expand .feed.xml >"$OUT"/feed.xml } usage() { cat < :: USAGE :: shite [-h] shite [-d DOMAIN] [-C DIR] [-o DIR] :: FLAGS :: -h Show this help and exit :: OPTIONS :: -d DOMAIN Domain name to use as the base for URLs. Default: \$PWD -C DIR Directory of source files for website. Default: \$PWD -o DIR Directory for output files. Will be created. Default: \$PWD/out EOF exit ${1:-0} } cleanup() { while read f; do rm "$f" >/dev/null 2>&1 done <"$RMF" rm "$RMF" } main() { trap cleanup EXIT INT DOMAIN="${SHITE_DOMAIN:-${PWD##*/}}" SOURCE="$PWD" OUT=out RMF=/tmp/shite.rm while getopts d:C:o:h opt; do case "$opt" in d) DOMAIN="$OPTARG" ;; C) SOURCE="$OPTARG" ;; o) OUT="$OPTARG" ;; h) usage ;; *) usage 1 ;; esac done shift "$((OPTIND - 1))" cd "$SOURCE" mkdir -p "$OUT" alias body=cat test -f ./.shite.sh && . ./.shite.sh pages *.htm index *.htm feed *.htm for file in *; do test "${file#*.}" = htm && continue test "${file#*.}" = xml && continue test "$file" = "$OUT" && continue cp -r "$file" "$OUT"/ done } test -n "$DEBUG" && set -x test -n "$SOURCE" || main "$@"