#!/usr/bin/env bash # create a gopher rss feed year="$(date +%Y)" root="$HOME/src/gopher/phlog/$year" phloglink="gopher://spike.nagatha.fr/0/phlog/$year" description="Phil's Phlog" rsslink="gopher://spike.nagatha.fr/0/phlog/rss.xml" filename="$HOME/src/gopher/phlog/rss.xml" builddate=$(date --iso-8601=ns) buildyear=$(date +%Y) cd $root || exit # Build RSS header & footer build_header () { echo " " > ~/header echo " Phil's Phlog gopher://spike.nagatha.fr/1/phlog en-us ©$buildyear Philip A. Wittamore © $buildyear Philip A. Wittamore - All Rights Reserved $builddate A Gopher phlog from Brittany, France " >> ~/header } build_footer () { echo " " >> ~/footer } build_item () { echo " $title $postdate $linkadd $linkadd " >> ~/feed } build_xml_file () { build_header build_footer cat ~/header ~/feed > ~/rss_tmp cat ~/rss_tmp ~/footer > "$filename" rm ~/header ~/feed ~/rss_tmp ~/footer } # list files and create rss.xml if [[ -f $filename ]]; then rm "$filename" fi touch "$filename" postNum=0 files=$(ls -r *.txt) for file in $files; do ((postNum+=1)) title=$(head -n1 "$file") postdate=$(cat "$file" | sed -n '2p') linkadd="$phloglink/$file" description="$(cat "$file" | sed -n "/^$/,/^$/p" | head -n 3 )..." build_item "$file" done # put it all together build_xml_file exit