aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Reed <michael@michaelreed.io>2017-07-12 20:14:08 -0400
committerMichael Reed <michael@michaelreed.io>2017-07-13 01:30:25 -0400
commit8beec9311e609f502f331c5e9b8d686a09f8fb60 (patch)
tree9c7e1e2cbb8275925f8e2d08e82c152a5ebda645
parent21c93db2c5ae676ce1e3375d91ccd30a646abaa9 (diff)
downloadlibrebootfr-8beec9311e609f502f331c5e9b8d686a09f8fb60.tar.gz
librebootfr-8beec9311e609f502f331c5e9b8d686a09f8fb60.zip
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.
-rwxr-xr-xwww/index.sh40
1 files changed, 26 insertions, 14 deletions
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' '<rss version="2.0">'
printf '%s\n' '<channel>'
printf '%s\n' "<title>$BLOGTITLE</title>"
- printf '%s\n' "<link>"$BLOGBASE"news/</link>"
+ printf '%s\n' "<link>${BLOGBASE}news/</link>"
printf '%s\n' "<description>$BLOGDESCRIPTION</description>"
+}
+
+# usage: rss_main file
+rss_main() {
+ file=$1
- for f in $FILES
- do
- # render content and escape
- desc=$(sed -e 's/</\&lt;/g' ${f%.md}.bare.html | sed -e 's/>/\&gt;/g')
- url="${f%.md}.html"
+ # render content and escape
+ desc=$(sed -e 's/</\&lt;/g' "${file%.md}.bare.html" | sed -e 's/>/\&gt;/g')
+ url="${file%.md}.html"
- printf '%s\n' '<item>'
- printf '%s\n' "<title>$(title "$f")</title>"
- printf '%s\n' "<link>$BLOGBASE$url</link>"
- printf '%s\n' "<description>$desc</description>"
- printf '%s\n' '</item>'
- done
+ printf '%s\n' '<item>'
+ printf '%s\n' "<title>$(title "$file")</title>"
+ printf '%s\n' "<link>$BLOGBASE$url</link>"
+ printf '%s\n' "<description>$desc</description>"
+ printf '%s\n' '</item>'
+}
+# usage: rss_footer
+rss_footer() {
printf '%s\n' '</channel>'
printf '%s\n' '</rss>'
}
@@ -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