From 25bd93eafa55e8f43baebd6a03eacf69002e743e Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Fri, 30 Sep 2022 11:26:32 -0500 Subject: add logging function --- vienna | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/vienna b/vienna index 3077dcb..578a4b8 100755 --- a/vienna +++ b/vienna @@ -51,24 +51,23 @@ configure() { FEED_TEMPLATE="${VIENNA_FEED_TEMPLATE:-.feed.tmpl.xml}" # File extensions PAGE_RAW_EXT="${VIENNA_PAGE_RAW_EXT:-htm}" - ## Source ./.vienna.sh, if it exists. - # Sourcing it here lets it override any environment variables, and it to - # be overridden by command-line flags. - test -f "$CONFIG" && . "$CONFIG" + # Logging + LOG=true ## Parse command line arguments - while getopts d:C:o:h opt; do + while getopts d:C:o:hq opt; do case "$opt" in d) DOMAIN="$OPTARG" ;; C) WORKD="$OPTARG" ;; o) OUTD="$OPTARG" ;; h) usage 0 ;; + q) LOG=false ;; *) exit 1 ;; esac done ## Log configuration variables - echo >&2 "[config] domain: $DOMAIN" - echo >&2 "[config] workdir: $WORKD" - echo >&2 "[config] output: $OUTD" + log config "domain: $DOMAIN" + log config "workdir: $WORKD" + log config "output: $OUTD" ## Initialize state FILE= ## Cleanup after we're done @@ -87,7 +86,7 @@ main() { case "${1:-ok}" in ok) ;; clean) - echo >&2 "[vienna] clean" + log vienna "clean" rm -r "$OUTD" exit ;; @@ -114,15 +113,15 @@ main() { case "${1:-ok}" in ok) ;; publish) - echo >&2 "[vienna] publish" + log vienna "publish" publish "$OUTD" ;; preview) - echo >&2 "[vienna] preview" + log vienna "preview" preview "$OUTD" ;; *) - echo >&2 "[vienna] Don't know command \`$1'." + log vienna "Don't know command \`$1'." exit 1 ;; esac @@ -159,6 +158,16 @@ EOF exit 3 } +### Utility + +log() { + if "$LOG"; then + t="$1" + shift + echo >&2 "[$t]" "$@" + fi +} + ### File processing ## Building block functions @@ -230,7 +239,7 @@ build() { # build PAGE... # Outputs a file of the format $OUTD//index.html. test -f "$PAGE_TEMPLATE" || return 1 for FILE; do - echo >&2 "[build] $FILE" + log build "$FILE" outd="$OUTD/${FILE%.$PAGE_RAW_EXT}" outf="$outd/index.html" tmpf="$TMPD/$FILE.tmp" @@ -245,7 +254,7 @@ index() { # index PAGE... # Wraps each PAGE in a
  • structure. test -f "$INDEX_TEMPLATE" || return 1 for FILE; do - echo >&2 "[index] $FILE" + log index "$FILE" link="$DOMAIN${DOMAIN:+/}${FILE%.$PAGE_RAW_EXT}" echo "
  • $(meta title "$FILE")
  • " done | expand "$INDEX_TEMPLATE" >"$OUTD/index.html" @@ -255,7 +264,7 @@ feed() { # feed PAGE... ## Build an RSS 2.0 feed from PAGE(s). test -f "$FEED_TEMPLATE" || return 1 for FILE; do - echo >&2 "[feed] $FILE" + log feed "$FILE" link="$DOMAIN${DOMAIN:+/}${FILE%.$PAGE_RAW_EXT}" date="$(meta pubdate "$FILE")" echo "" -- cgit 1.4.1-21-gabe81