Coffee Space


RSS Feed

Preview Image


RSS starts for “Really Simple Syndication”, an XML file that allows for a very simple “notifications feed” for your website. The idea being that people can get several of these together (using an RSS aggregator) for content they are interested in and ultimately know when you update your website.

The idea of RSS feeds was born in 1997 by Dave Winer at UserLand. Since then, many versions have been released although the standard itself has never been too standard - with many different implementations existing. For more information, please see w3schools write-up.

There are several reasons why I believe this to be a good decision:


The build script for the site is implemented in bash, although not the most secure or fastest scripting language, it works nicely with Linux and I control all of the site’s content. We start by defining some comments about how to use this new function:

0001 # rss()
0002 #
0003 # Creates an RSS feed for a contents page.
0004 #
0005 # @param $1 Name of page.

I use Java type comments in any language, in my opinion Java has some of the better documentation styles. All this comment says, is that you have to call rss to use it, that it’s responsible for handling RSS and it takes one parameter - which is the name of the page.

0006 function rss {
0007   rm $1.xml

Remove any previous version of this.

0008   readarray -t content < $

Create a line-by-line array on the markdown page.

0009   feed="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
0010 <rss version=\"2.0\">
0011 <channel>
0012   <title>Coffee Space $1</title>
0013   <link></link>"

Create the first part of the RSS feed.

0014   for (( i=0; i<${#content[*]}; i++ )); do

C++ style iteration over the content array.

0015     if [[ ${content[i]} == [* ]]; then

Make sure the array at least contains the beginnings of an article link.

0016       feed_date="${content[i]#*[}"
0017       feed_date="${feed_date%]*}"
0018       feed_link="${content[i]#*(}"
0019       feed_link="${feed_link%)*}"
0020       feed_title="${content[i]#*) }"

Break up the line and pull out the important parts. # means “cut everything before this” and “%” means “cut everything after this”.

0021       feed="$feed
0022   <item>
0023     <title>$feed_title</title>
0024     <link>$feed_link</link>
0025     <description>Date: $feed_date</description>
0026   </item>"

Create the feed item. Note that the description is not very descriptive, but it’s the only information we provide ourselves on the same line.

0027     fi
0028   done
0029   echo -e "$feed\n</channel>\n</rss>" >> $1.xml
0030 }

Finally, write the entire thing to file with the expected closing XML.


The resulting RSS feeds can be found here and here - as you can hopefully see (depending on how well your browser is able to read XML files), it generates a nicely spaced file that is a standardized RSS feed. Everything appears to work correctly and it is pretty lean - so far I am very happy with the results.

A few future improvements: