From 61478edec677ea75523655a1d866a8a5652488a3 Mon Sep 17 00:00:00 2001 From: Michael Reed Date: Wed, 12 Jul 2017 19:32:32 -0400 Subject: www/index.sh: Replace cat(1) usage with faster bashism --- www/index.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'www') diff --git a/www/index.sh b/www/index.sh index 618b8fc5..45b9f575 100755 --- a/www/index.sh +++ b/www/index.sh @@ -38,7 +38,7 @@ meta() { # generate the index file # MANIFEST determines the order of news articles in news/index.md -FILES=$(cat news/MANIFEST) +FILES=$(< news/MANIFEST) cat news-list.md > news/index.md -- cgit v1.2.3-70-g09d2 From 82f4b0418bd6ecbd56253274cd4bbbfcb577a1fe Mon Sep 17 00:00:00 2001 From: Michael Reed Date: Wed, 12 Jul 2017 19:38:28 -0400 Subject: www/index.sh: Make meta() and title() take arguments It makes the code easier to understand than the global variables that were used before. --- www/index.sh | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'www') diff --git a/www/index.sh b/www/index.sh index 45b9f575..5cd15818 100755 --- a/www/index.sh +++ b/www/index.sh @@ -19,17 +19,20 @@ BLOGTITLE="Libreboot News" BLOGBASE="https://libreboot.org/" BLOGDESCRIPTION="News on Libreboot development" +# usage: title file title() { - sed -n 1p $f | sed -e s-^..-- + sed -n 1p "$1" | sed -e s-^..-- } +# usage: meta file meta() { - URL=$(printf '%s\n' ${f%.md}.html | sed -e s-news/--) + file=$1 + URL=$(printf '%s\n' "${file%.md}.html" | sed -e s-news/--) - printf '%s\n' "[$(title)]($URL){.title}" - printf '%s\n' "[$(sed -n 3p $f | sed -e s-^..--)]{.date}" + printf '%s\n' "[$(title "$file")]($URL){.title}" + printf '%s\n' "[$(sed -n 3p "$file" | sed -e s-^..--)]{.date}" printf '\n' - tail -n +5 $f | perl -p0e 's/(\.|\?|\!)( |\n)(.|\n)*/.../g' + tail -n +5 "$file" | perl -p0e 's/(\.|\?|\!)( |\n)(.|\n)*/.../g' printf '\n' printf '\n' @@ -44,7 +47,7 @@ cat news-list.md > news/index.md for f in $FILES do - meta >> news/index.md + meta "$f" >> news/index.md done # generate an RSS index @@ -64,7 +67,7 @@ rss() { url="${f%.md}.html" printf '%s\n' '' - printf '%s\n' "$(title)" + printf '%s\n' "$(title "$f")" printf '%s\n' "$BLOGBASE$url" printf '%s\n' "$desc" printf '%s\n' '' -- cgit v1.2.3-70-g09d2 From 21c93db2c5ae676ce1e3375d91ccd30a646abaa9 Mon Sep 17 00:00:00 2001 From: Michael Reed Date: Wed, 12 Jul 2017 20:04:35 -0400 Subject: www/index.sh: Organize in a less surprising manner I find it easier to read this file if all function definitions come first, then all the actual stuff we do comes at the end. --- www/index.sh | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'www') diff --git a/www/index.sh b/www/index.sh index 5cd15818..27549cc5 100755 --- a/www/index.sh +++ b/www/index.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash # # Copyright (C) 2017 Alyssa Rosenzweig +# Copyright (C) 2017 Michael Reed # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -19,6 +20,10 @@ BLOGTITLE="Libreboot News" BLOGBASE="https://libreboot.org/" BLOGDESCRIPTION="News on Libreboot development" +# MANIFEST determines the order of news articles in news/index.md +FILES=$(< news/MANIFEST) + + # usage: title file title() { sed -n 1p "$1" | sed -e s-^..-- @@ -38,20 +43,6 @@ meta() { printf '\n' } -# generate the index file - -# MANIFEST determines the order of news articles in news/index.md -FILES=$(< news/MANIFEST) - -cat news-list.md > news/index.md - -for f in $FILES -do - meta "$f" >> news/index.md -done - -# generate an RSS index - rss() { printf '%s\n' '' printf '%s\n' '' @@ -77,5 +68,14 @@ rss() { printf '%s\n' '' } + +# generate the index file +cat news-list.md > news/index.md +for f in $FILES +do + meta "$f" >> news/index.md +done + +# generate the RSS index rss > news/feed.xml cp news/feed.xml feed.xml -- cgit v1.2.3-70-g09d2 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') 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