aboutsummaryrefslogtreecommitdiff
path: root/blogrss
diff options
context:
space:
mode:
authorPhilip Wittamore <philip@wittamore.com>2026-05-05 21:42:52 +0200
committerPhilip Wittamore <philip@wittamore.com>2026-05-05 21:42:52 +0200
commitfd5ca9551ce75d8856451de7928b000cb3b1c779 (patch)
treea7e9f7113dfb383f4514d3c1dc88161561590e72 /blogrss
update
Diffstat (limited to 'blogrss')
-rwxr-xr-xblogrss74
1 files changed, 74 insertions, 0 deletions
diff --git a/blogrss b/blogrss
new file mode 100755
index 0000000..da84d0f
--- /dev/null
+++ b/blogrss
@@ -0,0 +1,74 @@
+#!/usr/bin/env bash
+
+link=https://wittamore.com/articles/2025
+description='Ramblings from Brittany, France'
+rsslink=https://wittamore.com/rss.xml
+feedname=/home/philip/web/rss.xml
+postDir=/home/philip/web/articles/2025
+updated=$(date --iso-8601=ns)
+
+# Build RSS header & footer
+header () {
+echo "<?xml version='1.0' encoding='UTF-8' ?>
+<rss version='2.0' xmlns:atom='http://www.w3.org/2005/Atom'>" > ~/feedtop
+echo "
+<channel>
+<title>Bloggings - wittamore.com</title>
+<link>https://wittamore.com</link>
+<description>Ramblings from Brittany, France</description>
+<lastBuildDate>$updated</lastBuildDate>
+<atom:link href='$rsslink' rel='self' type='application/rss+xml' />
+" >> ~/feedtop
+}
+
+footer () {
+echo "
+</channel>
+
+</rss>
+" >> ~/feedbottom
+}
+
+# Function: Build Item add to feed
+
+item () {
+ echo "<item>
+ <title>$fullTitle</title><pubDate>$postdate</pubDate>
+ <link>$linkadd</link>
+ <guid>$linkadd</guid>
+ <category> </category>
+ <description>$description</description>
+</item>" >> ~/feed
+}
+
+# Function: Concatenate everything
+
+combine () {
+ header
+ footer
+ cat ~/feedtop ~/feed > ~/feedtb
+ cat ~/feedtb ~/feedbottom > $feedname
+ rm ~/feedtop ~/feed ~/feedtb ~/feedbottom
+}
+
+# Run through files and create rss.xml
+
+if [[ -f $feedname ]]; then
+ rm $feedname
+fi
+touch $feedname
+mapfile -t postArray < <(ls -t "$postDir"/*.html)
+postNum=0
+for posts in "${postArray[@]}"; do
+ ((postNum+=1))
+ post=$posts
+ fullTitle=$(grep -o '>.*</h2>' "$post" | sed 's/\(>\|<\/h2>\)//g')
+ postdate=$(grep -o '>.*</h5>' "$post" | sed 's/\(>\|<\/h5>\)//g')
+ postname=${post##*/}
+ linkadd="$link"/"$postname"
+ description=$(sed -n '/<h4>.*/,/*.<\/h4>/{p;q;}' "$post" | sed -e 's/<[^>]\+>/ /g' -e 's|<h4>||g' -e 's|</h4>||g' -e 's|"||g')
+ item "$post"
+done
+ combine
+exit
+