#!/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)" # Build RSS header & footer header () { echo " Bloggings - wittamore.fr https://wittamore.com Ramblings from Brittany, France $UPDATED " >> ~/feedtop } footer () { echo " " >> ~/feedbottom } # Function: Build Item add to feed builditem () { echo " $FULLTITLE$POSTDATE $LINKADDR $LINKADDR $DESC " >> ~/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 '>.*' "$POST" | sed 's/\(>\|<\/h2>\)//g') POSTDATE=$(grep -o '>.*' "$POST" | sed 's/\(>\|<\/h3>\)//g') POSTNAME=${POST##*/} LINKADDR="$YLINK/$POSTNAME" DESC="$(sed -n '/

.*/,/*.<\/h4>/{p;q;}' "$POST" | sed -e 's/<[^>]\+>/ /g' -e 's|

||g' -e 's|

||g' -e 's|"||g' -e 's/^[ \t]*//;s/[ \t]*$//')" builditem "$POST" done combine exit