Andy McKay

Mar 04, 2009

Easy RSS Widgets


One thing that I looked at a while back, but didn't have chance to play with was Google Ajax Feeds. These give you an interface to easily read RSS feeds in Javascript.

A few years ago I tried this in Javascript using ClearRSS for Plone. The only problem with that was that I used a generic server side proxy (now redundant thanks to JSONP) and found myself hitting all the inconsistencies with feeds and programming that in Javascript. This API removes the first problem and solves the second by normalising all the data so that it is accessible consistently.

The result is that it's easy to read feeds in Javascript. As an example I just created a widget for Cleartrain, so that all trainings can be easily embedded on a page. For example all the Django training can be pulled using this:

<div id="cleartrain-feed" />
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="http://media.cleartrain.ca/widget/cleartrain.js"></script>	
<script type="text/javascript">
    cleartrain.url = "http://cleartrain.ca/atom/topics/4/";
    cleartrain.content = false;
</script>

Cleartrain is itself a Django site and required no modification above and beyond having RSS feeds for everything. The Javascript to allow this to be embedable is really easy, all we do is read the Ajax API, loop through the entries and then add into the innerHTML. The source for that is here: http://media.cleartrain.ca/widget/cleartrain.js.

Definitely a neat API from Google and a very quick and easy way to create an RSS widget.