aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xblogrss59
1 files changed, 30 insertions, 29 deletions
diff --git a/blogrss b/blogrss
index 5e83aeb..528e450 100755
--- a/blogrss
+++ b/blogrss
@@ -1,43 +1,43 @@
#!/usr/bin/env bash
-link=https://wittamore.fr/articles/2026
-description='Ramblings from Brittany, France'
-rsslink=https://wittamore.fr/rss.xml
-feedname=/home/philip/web/rss.xml
-postDir=/home/philip/web/articles/2026
-updated=$(date --iso-8601=ns)
+YEAR="$(date +%Y)"
+
+YLINK="https://wittamore.fr/articles/$YEAR"
+DESC="Ramblings from Brittany, France"
+RSSLINK="https://wittamore.fr/rss.xml"
+FEEDNAME="/home/philip/web/rss.xml"
+POSTDIR="/home/philip/web/articles/$YEAR"
+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 "
+<rss version='2.0' xmlns:atom='http://www.w3.org/2005/Atom'>
<channel>
<title>Bloggings - wittamore.fr</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' />
+<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 () {
+builditem () {
echo "<item>
- <title>$fullTitle</title><pubDate>$postdate</pubDate>
- <link>$linkadd</link>
- <guid>$linkadd</guid>
+ <title>$FULLTITLE</title><pubDate>$POSTDATE</pubDate>
+ <link>$LINKADDR</link>
+ <guid>$LINKADDR</guid>
<category> </category>
- <description>$description</description>
+ <description>$DESC</description>
</item>" >> ~/feed
}
@@ -47,27 +47,28 @@ combine () {
header
footer
cat ~/feedtop ~/feed > ~/feedtb
- cat ~/feedtb ~/feedbottom > $feedname
+ cat ~/feedtb ~/feedbottom > $FEEDNAME
rm ~/feedtop ~/feed ~/feedtb ~/feedbottom
}
# Run through files and create rss.xml
-if [[ -f $feedname ]]; then
- rm $feedname
+if [[ -f $FEEDNAME ]]; then
+ rm $FEEDNAME
fi
-touch $feedname
-mapfile -t postArray < <(ls -t "$postDir"/*.html)
+touch $FEEDNAME
+mapfile -t POSTARRAY < <(ls -t "$POSTDIR"/*.html)
postNum=0
-for posts in "${postArray[@]}"; do
+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"
+ POST=$POSTS
+ FULLTITLE=$(grep -o '>.*</h2>' "$POST" | sed 's/\(>\|<\/h2>\)//g')
+ POSTDATE=$(grep -o '>.*</h3>' "$POST" | sed 's/\(>\|<\/h3>\)//g')
+ POSTNAME=${POST##*/}
+ LINKADDR="$YLINK/$POSTNAME"
+ DESC="$(sed -n '/<h4>.*/,/*.<\/h4>/{p;q;}' "$POST" | sed -e 's/<[^>]\+>/ /g' -e 's|<h4>||g' -e 's|</h4>||g' -e 's|"||g')"
+ DESC="$(echo $DESC | sed 's/^[ \t]*//;s/[ \t]*$//')"
+ builditem "$POST"
done
combine
exit