#!/bin/bash
cat > ~/blog/html/rss.xml <
Mathematical Field Notes
http://www.homepages.ucl.ac.uk/~ucahjde/blog/
Blog of the UCL-based mathematician Jonny Evans
EOF
headingnum=0
linked=0
rootaddress='https://www.homepages.ucl.ac.uk/~ucahjde/blog/'
while read -r line
do
if echo "$line" | grep "^\*\s" &> /dev/null
then
if [ $linked == 0 ];
then
echo "$rootaddress" >> ~/blog/html/rss.xml
fi
linked=0
if [ $headingnum != 0 ];
then
echo "" >> ~/blog/html/rss.xml
fi
let headingnum=$headingnum+1
title=$(echo "$line" |
perl -pe 's|^\*\s(.*?)\s*:[a-zA-Z:]*:|\1|' |
gawk '{print "- ",$0,""}'
)
tags=$(echo "$line" |
perl -pe 's|^.*?(:[a-zA-Z:]*:)|\1|' |
gawk -F':' '{for (k=2;k<=NF-1;k++) print "",$k,""}'
)
echo "$title" >> ~/blog/html/rss.xml
echo "$tags" >> ~/blog/html/rss.xml
fi
if echo "$line" | grep "\[[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}\s[A-Za-z]\{3\}\]" &> /dev/null
then
pubdate=$(echo "$line" |
sed 's|\[\(.*\)\]|\1|' |
gawk '{print "",$0,""}'
)
echo "$pubdate" >> ~/blog/html/rss.xml
fi
if echo "$line" | grep "\[Read on.*\]\]" &> /dev/null
then
linked=1
link=$(echo "$line" |
sed 's|^\[\[\./\(.*\)\.org\]\[Read on.*\]\].*$|\1|' |
gawk -v x=$rootaddress '{print ""x$0".html"}'
)
echo "$link" >> ~/blog/html/rss.xml
fi
done < ~/blog/org/index.org
if [ $linked == 0 ];
then
echo "$rootaddress" >> ~/blog/html/rss.xml
fi
cat >> ~/blog/html/rss.xml <
EOF