diff options
author | Philip Wittamore <philip@wittamore.com> | 2025-05-07 21:34:07 +0200 |
---|---|---|
committer | Philip Wittamore <philip@wittamore.com> | 2025-05-07 21:34:07 +0200 |
commit | 66d9ecaa26925ffcc0947e887cc7a94f79268644 (patch) | |
tree | cde639475dfa226ad8d5353a7a5142fa23f0649b /blogrss | |
download | blog-66d9ecaa26925ffcc0947e887cc7a94f79268644.tar.gz blog-66d9ecaa26925ffcc0947e887cc7a94f79268644.tar.bz2 blog-66d9ecaa26925ffcc0947e887cc7a94f79268644.zip |
blog scripts
Diffstat (limited to 'blogrss')
-rwxr-xr-x | blogrss | 94 |
1 files changed, 94 insertions, 0 deletions
@@ -0,0 +1,94 @@ +#!/bin/bash + +title=Bloggings +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) + +# correct file date to match blog post date +#cd $postDir +#postArray=( $(ls *.html) ) +#for posts in "${postArray[@]}"; do +# post=$posts +# postdate=$(grep -o '>.*</h5>' $post | sed 's/\(>\|<\/h5>\)//g') +# #[[CC]YY]MMDDhhmm[.ss] +# postdate="${postdate//-}0000" +# echo Date=$postdate +# echo Item=$post +# touch -a -m -t $postdate $post +#done + +# 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> + <enclosure> </enclosure> + </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 +postArray=( $(ls -t "$postDir"/*.html) ) +numPosts=$(ls "$postDir"/*.html | wc -l) +postNum=0 +for posts in "${postArray[@]}"; do + let 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" + guid=$postNum + 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 + |