From c22c2add6d38397c676eee1c36ba90c39e7c62fe Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Thu, 22 Sep 2022 13:04:56 -0500 Subject: Changes --- shite | 71 ++++++++++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 51 insertions(+), 20 deletions(-) diff --git a/shite b/shite index ebd9e1e..aed47c0 100755 --- a/shite +++ b/shite @@ -2,30 +2,36 @@ # shite --- shit out a site # by C. Duckworth +dog() { + while IFS= read -r line; do + printf '%s\n' "$line" + done +} + expand() { end="expand_$(date +%s)_${count:=0}" eval "$( - echo "cat <<$end" - cat "$@" + echo "dog <<$end" + dog <"$@" echo echo "$end" )" && count=$((count + 1)) } body() { - awk 'NR==1{next;}{print;}' + sed 1n } phtml() { - awk 'BEGIN{RS="";}/^[ \t]*"$0"

";}' + sed -e '/./{H;1h;d;};x;s,^[ \n\t]\+,,;s,^[^<].*,

&

,' } title() { - awk 'BEGIN{FS=" ";}NR==1{print $1;quit;}' + sed '1s/\t.*$//;q' } pubdate() { - awk 'BEGIN{FS=" ";}NR==1{print $2;quit;}' + sed '1s/^[^\t]*\t//;q' } filters() { @@ -35,8 +41,9 @@ filters() { pages() { for file; do echo >&2 "$file" + mkdir -p "$OUT"/"${file%.htm}" filters <"$file" | - expand .template.html >out/"${1%.html}"/index.html + expand .template.html >"$OUT"/"${file%.htm}"/index.html done } @@ -44,7 +51,7 @@ index() { for file; do echo >&2 "index: $file" echo "
  • $(title "$file")
  • " - done | expand .index.html >out/index.html + done | expand .index.html >"$OUT"/index.html } feed() { @@ -52,37 +59,61 @@ feed() { echo >&2 "feed: $file" echo "" echo " $(title "$file")" - echo " $DOMAIN/${file%.html}/" - echo " $DOMAIN/${file%.html}/" + 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 + done | expand .feed.xml >"$OUT"/feed.xml +} + +usage() { + dog < +:: 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} } main() { DOMAIN="${SHITE_DOMAIN:-${PWD##*/}}" SOURCE="$PWD" - while getopts d:C: opt; do + OUT=out + while getopts d:C:o:h opt; do case "$opt" in d) DOMAIN="$OPTARG" ;; C) SOURCE="$OPTARG" ;; - *) exit 1 ;; + o) OUT="$OPTARG" ;; + h) usage ;; + *) usage 1 ;; esac done shift "$((OPTIND - 1))" cd "$SOURCE" - mkdir -p out - test -f .shite.sh && . .shite.sh - pages *.html - index *.html - feed *.html + mkdir -p "$OUT" + test -f ./.shite.sh && . ./.shite.sh + pages *.htm + index *.htm + feed *.htm for file in *; do - test "${file#*.}" = html && continue + test "${file#*.}" = htm && continue test "${file#*.}" = xml && continue - cp -r "$file" out/ + test "$file" = "$OUT" && continue + cp -r "$file" "$OUT"/ done } -- cgit 1.4.1-21-gabe81