npm install diffuse
A fast and simple RSS generator for Node.
var RSS = require'diffuse';var http = require'http';var feed = RSScreateFeedtitle: 'Amphibious Rodents'link: ''description: 'Where we share our thoughts about amphibiosu rodents';feedaddItemtitle: 'Let me introduce myself'description: 'My name is Bobby Stevenson and I command several fleets of amphibious rodents. Come with me on a journey to learn more about them. <p>My RSS feed can contain HTML in case I would like to <strong>emphasize</strong> my interest in rodents.'guid: '2013-1-20'pubDate: toUTCString;
Usage is fairly simple. The
Diffuse API is mostly compatible with node-rss module.
var RSS = require'diffuse';
Creating a feed
#createFeed with an object containing elements & their contents.
var feed = RSScreateFeedtitle: 'my feed'link: 'www.example.com'// Not limited to text!description:text: 'A description of my feed'attrs:href: 'www.example.com';
Some elements are required according to RSS spec, and these are created for you automatically. Usually you would at least prefer to specify a
link and a
description, but diffuse will accept anything you throw at it. Unlike
createItem does not have any defaults.
#addItem to add an item to your feed. This behaves similarly to
createFeed, by building whatever elements you provide it.
var item = feedaddItemtitle: 'The color white considered harmful'description: 'Here is the content of my RSS article. I hope you are ready for grammatical mistakes and poor word-flow.';
description of the feed as well as items within it are wrapped in CDATA blocks, so your descriptions may contain HTML. Give her hell.
Rendering your feed
To render your feed, call
#render. This returns the generated XML of your RSS feed, and accepts a callback.
var data = feedrender;feedrender//Do stuff;
Diffuse has an internal caching mechanism. Diffuse watches its document structure for modifications, and caches your generated XML. Re-rendering only needs to occur when the document has been modified. This happens either when you add a new item, or items have been modified using
item#set. This gives it a significant performance advantage.
More item configuration
After you've created an item, you can still modify it using a simple API.
var item = feedaddItemtitle: 'Butt';itemset'title' 'My modified title. I didn\'t mean to say butt. Silly me.'itemtitleset'text' 'Hello ';itemtitleset'text' itemtitleget'text' + 'world';itemtitleset'attrs' href: 'www.example.com' ;
Building new Elements
Internally, Diffuse has a simple API for building its document structure. That is exposed to you if you need to build a more complicated structure.
var anchor = RSScreateElement'a' href: '' ;anchorappendText'My anchor.';var mine = RSScreateElement'strong' ' Mine.';anchorappendChildmine;var content = anchortoString; // <a href=''>My anchor. <strong>Mine.</strong></a>