Diffuse
npm install diffuse
A fast and simple RSS generator for Node.
var RSS = ; var feed = RSS; feed; feed;
Usage
Usage is fairly simple. The Diffuse
API is mostly compatible with node-rss module.
var RSS = ;
Creating a feed
Just call #createFeed
with an object containing elements & their contents. Some elements are required according to RSS spec, and these are created for you automatically. Usually you would at least prefer to specify a title
, link
and a description
, but diffuse will accept anything you throw at it. The title
and description
of the feed as well as items within it are wrapped in CDATA blocks, so your descriptions may contain HTML. Give her hell.
var feed = RSS;
Adding feed elements
Just call appendChild
var feed = RSS; var link = RSS; feed;
Adding items
Call #addItem
to add an item to your feed. This behaves similarly to createFeed
, by building whatever elements you provide it. Unlike createFeed
, this does not have any defaults.
var item = feed;
Rendering your feed
To render your feed, call #render
. This returns the generated XML of your RSS feed, and accepts a callback. 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.
var data = feed; feed;
More item configuration
After you've created an item, you can still modify it using a simple API.
var item = feed; item
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 = RSS;anchor; var mine = RSS; anchor; var content = anchor; // <a href='http://www.google.com'>My anchor. <strong>Mine.</strong></a>
Another example for adding an image
to your feed:
var RSS = ;var element = RSScreateElement; var feed = RSS; var image = { var image = ; var link = ; var title = ); var url = ; return image;}; feed;
Contributors
License
MIT