From d32317ec8fcab5068047d5ba4cce4cbf1c8c73bc Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Fri, 6 Jan 2023 22:06:18 -0600 Subject: Change meta to two-stage process Now 'meta_init' must be run before attempting to access the meta file. The meta file name is now kept in the environment variable "$META". --- vienna | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/vienna b/vienna index 61366bf..b077970 100755 --- a/vienna +++ b/vienna @@ -263,7 +263,29 @@ phtml() { # phtml < INPUT s#.*#

&

#' } -meta() { # meta FIELD [FILE] < INPUT +meta_init() { # meta_init FILE + ## Extract metadata from FILE for later processing. + # Metadata should exist as colon-separated data in HTML comments in the + # input file. + metafile= + m=false + t=false + while read -r line; do + case "$line" in + '') m=false ;; + *title:*) t=true && print "$line" ;; + *) "$m" && print "$line" ;; + esac + done <"$1" + if ! "$t"; then + title="${1##*/}" + title="${title%.*}" + print "title: ${title%.*}" + fi +} + +meta() { # meta FIELD [FILE] ## Extract metadata FIELDS from INPUT. # FILE gives the filename to save metadata to in the $WORKD. It # defaults to the current value for $FILE. @@ -271,11 +293,8 @@ meta() { # meta FIELD [FILE] < INPUT # Metadata should exist as colon-separated data in an HTML comment at # the beginning of an input file. field="$1" - file="${2:-$FILE}" - metafile="${TMPD:=.}/${file}.meta" - test -f "$metafile" || - sed -n '//q' >"$metafile" - sed -n "s/^[ \t]*$field:[ \t]*//p" <"$metafile" + file="${2:-$META}" + sed -n "s/^[ \t]*$field:[ \t]*//p" <"$file" } ## Customizable bits @@ -316,7 +335,9 @@ genpage() { # genpage PAGE... outd="$OUTD/${FILE%.$PAGE_RAW_EXT}" outf="$outd/index.html" tmpf="$TMPD/$FILE.tmp" + META="$TMPD/$FILE.meta" mkdir -p "$outd" + meta_init "$FILE" >"$META" filters <"$FILE" >"$tmpf" expand "$PAGE_TEMPLATE" <"$tmpf" >"$outf" done @@ -335,6 +356,7 @@ genlist() { # genlist PERITEM_FUNC TEMPLATE_FILE PAGE... for FILE; do log genlist "$peritem_func" "$FILE" LINK="$DOMAIN${DOMAIN:+/}${FILE%.$PAGE_RAW_EXT}" + META="$TMPD/$FILE.meta" "$peritem_func" "$FILE" done | expand "$template_file" } -- cgit 1.4.1-21-gabe81