From 486fa615aab03c9998737b9851a433ed8f873055 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Tue, 4 Oct 2022 22:48:31 -0500 Subject: refactor listing (index/feed) generation both an index and a feed are instances of what i'm calling a "listing" of pages. this should make it easier to also write tag pages and stuff like that later on. --- vienna | 49 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/vienna b/vienna index 90e5c03..8c3c92f 100755 --- a/vienna +++ b/vienna @@ -109,15 +109,15 @@ main() { mkdir -p "$TMPD" || exit 2 # Build pages alias pagep=true - build *."$PAGE_RAW_EXT" || exit 2 + genpage *."$PAGE_RAW_EXT" || exit 2 alias pagep=false # Build index alias indexp=true - index *."$PAGE_RAW_EXT" || exit 2 + genlist index_item "$INDEX_TEMPLATE" *."$PAGE_RAW_EXT" >"$OUTD/index.html" || exit 2 alias indexp=false # Build feed alias feedp=true - feed *."$PAGE_RAW_EXT" || exit 2 + genlist feed_item "$FEED_TEMPLATE" *."$PAGE_RAW_EXT" >"$OUTD/feed.xml" || exit 2 alias feedp=false # Copy static files static * || exit 2 @@ -261,12 +261,12 @@ filters() { # filters < INPUT ### Site building -build() { # build PAGE... +genpage() { # genpage PAGE... ## Compile PAGE(s) into $OUTD for publication. # Outputs a file of the format $OUTD//index.html. test -f "$PAGE_TEMPLATE" || return 1 for FILE; do - log build "$FILE" + log genpage "$FILE" outd="$OUTD/${FILE%.$PAGE_RAW_EXT}" outf="$outd/index.html" tmpf="$TMPD/$FILE.tmp" @@ -276,14 +276,40 @@ build() { # build PAGE... done } +genlist() { # genlist PERITEM_FUNC TEMPLATE_FILE PAGE... + peritem_func="$1" + template_file="$2" + shift 2 || return 2 + test -f "$template_file" || return 1 + for FILE; do + log genlist "$peritem_func/$template_file: $FILE" + LINK="$DOMAIN${DOMAIN:+/}${1%.PAGE_RAW_EXT}" + done | expand "$template_file" +} + +index_item() { # index_item PAGE + ## Construct a single item in an index.html. + echo "
  • $(meta title "$1")
  • " +} + +feed_item() { # feed_item PAGE + ## Construct a single item in an RSS feed. + date="$(pubdate "$1")" + echo "" + echo "$(meta title "$1")" + echo "$LINK" + echo "$LINK" + test -n "$date" && echo "$date" + echo "" +} + index() { # index PAGE... ## Build a site index from all PAGE(s) passed to it. # Wraps each PAGE in a
  • structure. test -f "$INDEX_TEMPLATE" || return 1 for FILE; do log index "$FILE" - link="$DOMAIN${DOMAIN:+/}${FILE%.$PAGE_RAW_EXT}" - echo "
  • $(meta title "$FILE")
  • " + index_item "$FILE" done | expand "$INDEX_TEMPLATE" >"$OUTD/index.html" } @@ -292,14 +318,7 @@ feed() { # feed PAGE... test -f "$FEED_TEMPLATE" || return 1 for FILE; do log feed "$FILE" - link="$DOMAIN${DOMAIN:+/}${FILE%.$PAGE_RAW_EXT}" - date="$(meta pubdate "$FILE")" - echo "" - echo "$(meta title "$FILE")" - echo "$link" - echo "$link" - test -n "$date" && echo "$date" - echo "" + feed_item "$FILE" done | expand "$FEED_TEMPLATE" >"$OUTD/feed.xml" } -- cgit 1.4.1-21-gabe81