Coffee Space


Listen:

RSS Feed

Preview Image

Preview Image

Introduction

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:

Implementation

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:

# rss()
#
# Creates an RSS feed for a contents page.
#
# @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.

function rss {
  rm $1.xml

Remove any previous version of this.

  readarray -t content < $1.md

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

  feed="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
<rss version=\"2.0\">
<channel>
  <title>Coffee Space $1</title>
  <link>http://coffeespace.org.uk</link>"

Create the first part of the RSS feed.

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

C++ style iteration over the content array.

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

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

      feed_date="${content[i]#*[}"
      feed_date="${feed_date%]*}"
      feed_link="${content[i]#*(}"
      feed_link="${feed_link%)*}"
      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".

      feed="$feed
  <item>
    <title>$feed_title</title>
    <link>http://coffeespace.org.uk/$feed_link</link>
    <description>Date: $feed_date</description>
  </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.

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

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

Conclusion

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: