From 8beec9311e609f502f331c5e9b8d686a09f8fb60 Mon Sep 17 00:00:00 2001 From: Michael Reed Date: Wed, 12 Jul 2017 20:14:08 -0400 Subject: www/index.sh: Refactor and simplify rss() Splitting rss() into 3 smaller functions allows factoring the for-loop out of rss() This is done by having the new rss_main() function take an argument instead of operating on a global variable, as rss() did before. --- www/index.sh | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) (limited to 'www/index.sh') diff --git a/www/index.sh b/www/index.sh index 27549cc5..587c5d8e 100755 --- a/www/index.sh +++ b/www/index.sh @@ -43,27 +43,33 @@ meta() { printf '\n' } -rss() { +# usage: rss_header +rss_header() { printf '%s\n' '' printf '%s\n' '' printf '%s\n' "$BLOGTITLE" - printf '%s\n' ""$BLOGBASE"news/" + printf '%s\n' "${BLOGBASE}news/" printf '%s\n' "$BLOGDESCRIPTION" +} + +# usage: rss_main file +rss_main() { + file=$1 - for f in $FILES - do - # render content and escape - desc=$(sed -e 's//\>/g') - url="${f%.md}.html" + # render content and escape + desc=$(sed -e 's//\>/g') + url="${file%.md}.html" - printf '%s\n' '' - printf '%s\n' "$(title "$f")" - printf '%s\n' "$BLOGBASE$url" - printf '%s\n' "$desc" - printf '%s\n' '' - done + printf '%s\n' '' + printf '%s\n' "$(title "$file")" + printf '%s\n' "$BLOGBASE$url" + printf '%s\n' "$desc" + printf '%s\n' '' +} +# usage: rss_footer +rss_footer() { printf '%s\n' '' printf '%s\n' '' } @@ -77,5 +83,11 @@ do done # generate the RSS index -rss > news/feed.xml +rss_header > news/feed.xml +for f in $FILES +do + rss_main "$f" >> news/feed.xml +done +rss_footer >> news/feed.xml + cp news/feed.xml feed.xml -- cgit v1.2.3-70-g09d2