aboutsummaryrefslogtreecommitdiff
path: root/blogrss
diff options
context:
space:
mode:
authorPhilip Wittamore <philip@wittamore.com>2026-07-01 17:16:17 +0200
committerPhilip Wittamore <philip@wittamore.com>2026-07-01 17:16:17 +0200
commitab6479dcb30299271c043dce268cffe229d0f039 (patch)
tree87f832e4424968ca424c42c781c95fcd182b2665 /blogrss
parent719171cfb9e50aa42137c91f62a0f3a6d93f4dc6 (diff)
update
Diffstat (limited to 'blogrss')
-rwxr-xr-xblogrss68
1 files changed, 40 insertions, 28 deletions
diff --git a/blogrss b/blogrss
index 2c98b59..36c90e3 100755
--- a/blogrss
+++ b/blogrss
@@ -1,24 +1,32 @@
#!/usr/bin/env bash
-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)"
+# settings
+TYEAR="$(date +%Y)"
+TITLE="Bloggings"
+YLINK="https://wittamore.fr/articles/$TYEAR"
+FDESC="Ramblings from Brittany"
+WSITE="https://wittamore.fr"
+RLINK="$WSITE/rss.xml"
+FEEDN="/home/philip/web/rss.xml"
+ARTDR="/home/philip/web/articles/$TYEAR"
+UPDAT="$(date --iso-8601=ns)"
+
+# convert tring to htmlentities
+htmlentities () {
+ echo $1 | sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g; s/"/\&quot;/g; s/'"'"'/\&#39;/g'
+}
# 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'>
<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' />
+<title>$TITLE</title>
+<link>$WSITE</link>
+<description>$FDESC</description>
+<lastBuildDate>$UPDAT</lastBuildDate>
+<atom:link href='$RLINK' rel='self' type='application/rss+xml' />
" >> ~/feedtop
}
@@ -33,11 +41,13 @@ echo "
builditem () {
echo "<item>
- <title>$FULLTITLE</title><pubDate>$POSTDATE</pubDate>
- <link>$LINKADDR</link>
- <guid>$LINKADDR</guid>
+ <title>$POSTTIT</title>
+ <pubDate>$POSTDAT</pubDate>
+ <author>Philip A. Wittamore</author>
+ <link>$POSTADD</link>
+ <guid>$POSTADD</guid>
<category> </category>
- <description>$DESC</description>
+ <description><![CDATA[$POSTDES]]></description>
</item>" >> ~/feed
}
@@ -47,27 +57,29 @@ combine () {
header
footer
cat ~/feedtop ~/feed > ~/feedtb
- cat ~/feedtb ~/feedbottom > $FEEDNAME
+ cat ~/feedtb ~/feedbottom > $FEEDN
rm ~/feedtop ~/feed ~/feedtb ~/feedbottom
}
# Run through files and create rss.xml
-if [[ -f $FEEDNAME ]]; then
- rm $FEEDNAME
+if [[ -f $FEEDN ]]; then
+ rm $FEEDN
fi
-touch $FEEDNAME
-mapfile -t POSTARRAY < <(ls -t "$POSTDIR"/*.html)
+touch $FEEDN
+mapfile -t ARTICLEARRAY < <(ls -t "$ARTDR"/*.html)
postNum=0
-for POSTS in "${POSTARRAY[@]}"; do
+for POSTS in "${ARTICLEARRAY[@]}"; do
((postNum+=1))
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' -e 's/^[ \t]*//;s/[ \t]*$//')"
+ POSTTIT="$(grep -o '<h2>.*</h2>' $POST | sed 's/\(<h2>\|<\/h2>\)//g')"
+ POSTDAT="$(grep -o '<h3>.*</h3>' $POST | sed 's/\(<h3>\|<\/h3>\)//g')"
+ # extract from first <h4> to last </p>
+ POSTDES="$(awk '/<h4>/,/<\/p>/' $POST)"
+ POSTNAM="$(htmlentities "${POST##*/}")"
+ POSTTIT="$(htmlentities "$POSTTIT")"
+ POSTDES="$(htmlentities "$POSTDES")"
+ POSTADD="$YLINK/$POSTNAM"
builditem "$POST"
done
combine