From 54049168dcfaf9f28a94d0db83222b8224a5ab3d Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sun, 8 Jan 2023 00:12:07 -0600 Subject: Change variable names OUTD => OUTDIR TEMPD => TEMPDIR WORKD => WORKDIR ... and added PLUGINDIR The new variables are more immediately understandable. --- vienna | 88 ++++++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 48 insertions(+), 40 deletions(-) diff --git a/vienna b/vienna index f4c1e65..ca35c39 100755 --- a/vienna +++ b/vienna @@ -44,9 +44,10 @@ EOF configure() { ## Set up environment DOMAIN="${VIENNA_DOMAIN:-https://www.example.com}" - TMPD="${VIENNA_TMPD:-/tmp/vienna}" - WORKD="${VIENNA_WORKD:-$PWD}" - OUTD="${VIENNA_OUTD:-out}" + TEMPDIR="${VIENNA_TEMPDIR:-/tmp/vienna}" + WORKDIR="${VIENNA_WORKDIR:-$PWD}" + OUTDIR="${VIENNA_OUTDIR:-out}" + PLUGINDIR="${VIENNA_PLUGINDIR:-.plugins}" CONFIG="${VIENNA_CONFIG:-./.vienna.sh}" # Templates PAGE_TEMPLATE="${VIENNA_PAGE_TEMPLATE:-.page.tmpl.html}" @@ -59,7 +60,7 @@ configure() { ## Parse command line arguments while getopts C:c:d:ho:q opt; do case "$opt" in - C) WORKD="$OPTARG" ;; + C) WORKDIR="$OPTARG" ;; c) CONFIG="$OPTARG" # To error later if a config is specified on the command @@ -68,7 +69,7 @@ configure() { ;; d) DOMAIN="$OPTARG" ;; h) usage 0 ;; - o) OUTD="$OPTARG" ;; + o) OUTDIR="$OPTARG" ;; q) LOG=false ;; *) exit 1 ;; esac @@ -88,7 +89,10 @@ main() { configure "$@" shift "$((OPTIND - 1))" # Prepare - cd "$WORKD" || exit 2 + cd "$WORKDIR" || exit 2 + # Further argument processing --- pre-build + preprocess "$@" || shift + # Source config if test -f "$CONFIG"; then # Source ./.vienna.sh, if it exists. . "$CONFIG" @@ -104,31 +108,32 @@ main() { preprocess "$@" || shift ## Log configuration variables log config domain: "$DOMAIN" - log config workdir: "$WORKD" - log config output: "$OUTD" - log config page.tmpl: "$PAGE_TEMPLATE" - log config index.tmpl: "$INDEX_TEMPLATE" - log config feed.tmpl: "$FEED_TEMPLATE" - ## Plugins - # Plugins are *.sh files in $WORKD/.plugins/. They're sourced here. - for plugin in ./.*.sh; do + log config workdir: "$WORKDIR" + log config output: "$OUTDIR" + log template page: "$PAGE_TEMPLATE" + log template index: "$INDEX_TEMPLATE" + log template feed: "$FEED_TEMPLATE" + # Plugins + for plugin in "$PLUGINDIR"/*.sh; do test -f "$plugin" || continue log plugin "$plugin" . "$plugin" done - mkdir -p "$OUTD" || exit 2 - mkdir -p "$TMPD" || exit 2 + # Prepare output directories + mkdir -p "$OUTDIR" || exit 2 + mkdir -p "$TEMPDIR" || exit 2 + log vienna build # Build pages alias pagep=true genpage *."$PAGE_RAW_EXT" || exit 2 alias pagep=false # Build index alias indexp=true - genlist index_item "$INDEX_TEMPLATE" *."$PAGE_RAW_EXT" >"$OUTD/index.html" || exit 2 + genlist index_item "$INDEX_TEMPLATE" *."$PAGE_RAW_EXT" >"$OUTDIR/index.html" || exit 2 alias indexp=false # Build feed alias feedp=true - genlist feed_item "$FEED_TEMPLATE" *."$PAGE_RAW_EXT" >"$OUTD/feed.xml" || exit 2 + genlist feed_item "$FEED_TEMPLATE" *."$PAGE_RAW_EXT" >"$OUTDIR/feed.xml" || exit 2 alias feedp=false # Copy static files static * || exit 2 @@ -152,7 +157,7 @@ preprocess() { ;; clean) log vienna clean - rm -r "$OUTD" + rm -r "$OUTDIR" cleanup if [ $# -eq 0 ]; then exit # Quit when only cleaning @@ -168,11 +173,11 @@ postprocess() { ok) ;; publish) log vienna publish - publish "$OUTD" + publish "$OUTDIR" ;; preview) log vienna preview - preview "$OUTD" + preview "$OUTDIR" ;; *) log error "Don't know command \`$1'." @@ -184,7 +189,7 @@ postprocess() { cleanup() { test -z "$DEBUG" && test -z "$NODEP_RM" && - rm -r "$TMPD" + rm -r "$TEMPDIR" } _publish() { @@ -221,7 +226,8 @@ initialize() { # initialize cat >"$CONFIG" </dev/null 2>&1; - vienna && "$_PYTHON" -m http.server -d "$OUTD"' + vienna && "$_PYTHON" -m http.server -d "$OUTDIR"' else log error "\`python' not found." _preview @@ -247,16 +253,18 @@ preview() { publish() { if [ -n "$WWW_ROOT" ]; then - rsync -avzP --delete "$OUTD/" "$WWW_ROOT/" + rsync -avzP --delete "$OUTDIR/" "$WWW_ROOT/" else _preview fi } EOF + log init "$PAGE_TEMPLATE" cat >"$PAGE_TEMPLATE" <<\EOF $$(title) $$(body) EOF + log init "$INDEX_TEMPLATE" cat >"$INDEX_TEMPLATE" <<\EOF a home page!

hey! it's a home page of some sort!

@@ -356,7 +364,7 @@ meta_init() { # meta_init FILE meta() { # meta FIELD [FILE] ## Extract metadata FIELDS from INPUT. - # FILE gives the filename to save metadata to in the $WORKD. It + # FILE gives the filename to save metadata to in the $WORKDIR. It # defaults to the current value for $FILE. # # Metadata should exist as colon-separated data in an HTML comment at @@ -375,16 +383,16 @@ filters() { # filters < INPUT ### Site building genpage() { # genpage PAGE... - ## Compile PAGE(s) into $OUTD for publication. - # Outputs a file of the format $OUTD//index.html. + ## Compile PAGE(s) into $OUTDIR for publication. + # Outputs a file of the format $OUTDIR//index.html. test -f "$PAGE_TEMPLATE" || return 1 for FILE; do test -f "$FILE" || continue log genpage "$FILE" - outd="$OUTD/${FILE%.$PAGE_RAW_EXT}" + outd="$OUTDIR/${FILE%.$PAGE_RAW_EXT}" outf="$outd/index.html" - tmpf="$TMPD/$FILE.tmp" - META="$TMPD/$FILE.meta" + tmpf="$TEMPDIR/$FILE.tmp" + META="$TEMPDIR/$FILE.meta" mkdir -p "$outd" meta_init "$FILE" >"$META" filters <"$FILE" >"$tmpf" @@ -396,15 +404,15 @@ genlist() { # genlist PERITEM_FUNC TEMPLATE_FILE PAGE... ## Generate a list. peritem_func="$1" template_file="$2" - tmpf="$TMPD/$1" + tmpf="$TEMPDIR/$1" shift 2 || return 2 test -f "$template_file" || return 1 printf '%s\n' "$@" | sort_items | while read -r FILE; do test -f "$FILE" || continue - log genlist "$peritem_func" "$FILE" + log genlist "$peritem_func:" "$FILE" LINK="$DOMAIN${DOMAIN:+/}${FILE%.$PAGE_RAW_EXT}" - META="$TMPD/$FILE.meta" + META="$TEMPDIR/$FILE.meta" "$peritem_func" "$FILE" done | expand "$template_file" } @@ -432,7 +440,7 @@ feed_item() { # feed_item PAGE } static() { # static FILE... - ## Copy static FILE(s) to $OUTD as-is. + ## Copy static FILE(s) to $OUTDIR as-is. # Performs a simple heuristic to determine whether to copy a file or # not. for FILE; do @@ -440,8 +448,8 @@ static() { # static FILE... case "$FILE" in .*) continue ;; *.htm) continue ;; - "$OUTD") continue ;; - *) cp -r "$FILE" "$OUTD/" ;; + "$OUTDIR") continue ;; + *) cp -r "$FILE" "$OUTDIR/" ;; esac done } -- cgit 1.4.1-21-gabe81