diff options
| -rwxr-xr-x | blogrss | 68 |
1 files changed, 40 insertions, 28 deletions
@@ -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/&/\&/g; s/</\</g; s/>/\>/g; s/"/\"/g; s/'"'"'/\'/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 |
