#!/usr/bin/env bash
# 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/&/\&/g; s/\</g; s/>/\>/g; s/"/\"/g; s/'"'"'/\'/g'
}
# Build RSS header & footer
header () {
echo "
$TITLE
$WSITE
$FDESC
$UPDAT
" >> ~/feedtop
}
footer () {
echo "
" >> ~/feedbottom
}
# Function: Build Item add to feed
builditem () {
echo "-
$POSTTIT
$POSTDAT
Philip A. Wittamore
$POSTADD
$POSTADD
" >> ~/feed
}
# Function: Concatenate everything
combine () {
header
footer
cat ~/feedtop ~/feed > ~/feedtb
cat ~/feedtb ~/feedbottom > $FEEDN
rm ~/feedtop ~/feed ~/feedtb ~/feedbottom
}
# Run through files and create rss.xml
if [[ -f $FEEDN ]]; then
rm $FEEDN
fi
touch $FEEDN
mapfile -t ARTICLEARRAY < <(ls -t "$ARTDR"/*.html)
postNum=0
for POSTS in "${ARTICLEARRAY[@]}"; do
((postNum+=1))
POST=$POSTS
POSTTIT="$(grep -o '
.*
' $POST | sed 's/\(\|<\/h2>\)//g')"
POSTDAT="$(grep -o '.*
' $POST | sed 's/\(\|<\/h3>\)//g')"
# extract from first to last
POSTDES="$(awk '//,/<\/p>/' $POST)"
POSTNAM="$(htmlentities "${POST##*/}")"
POSTTIT="$(htmlentities "$POSTTIT")"
POSTDES="$(htmlentities "$POSTDES")"
POSTADD="$YLINK/$POSTNAM"
builditem "$POST"
done
combine
exit