RSS Feed Live

12/20/14

I've just added an RSS feed to the site. As I try to increase the amount I write, having a feed is a plus.

The feed is available at http://ordinaryrobot.com/rss

I made use of a great little node library node-rss to setup the feed as a route on my express server.

For now I'm using a json file to configure my feed items. I will probably start tracking the items in a DB soon instead.

The module to expose my feed:

      
  var RSS = require('rss');
  var feed_json = JSON.parse(require('fs').readFileSync('./rss_feed.json', 'utf-8'));
    
  function createRSSFeed() {
    var feed = new RSS({
      title: 'Ordinary Robot',
      description: 'Ordinary Robot Blog Posts',
      feed_url: 'http://ordinaryrobot.com/rss',
      site_url: 'http://ordinaryrobot.com',
      managingEditor: 'Matthew Parke',
      webMaster: 'Matthew Parke',
      copyright: '2014 Matthew Parke',
      language: 'en',
      categories: ['HTML','CSS','JavaScript'],
      pubDate: new Date().toString(),
      ttl: '60'
    });
    
    var feed_items = feed_json.items;
    var length = feed_items.length;
    for (var i = 0; i < length; i++) {
      feed.item(feed_items[i]);
    }

    return feed.xml();
  }

  var xml = createRSSFeed();

  module.exports = function() {
    return xml;
  };
      
    

The route using the module:

      
  router.get('/rss', function (req, res) {
    res.send(rss());
  });
      
    
comments powered by Disqus