diff --git a/lib/rss.js b/lib/rss.js index 7e132bc..5981cce 100644 --- a/lib/rss.js +++ b/lib/rss.js @@ -13,6 +13,14 @@ function RSS (options, items) { this.site_url = options.site_url; this.image_url = options.image_url; this.author = options.author; + this.categories = options.categories; + this.pubDate = options.pubDate; + this.docs = options.docs; + this.copyright = options.copyright; + this.language = options.language; + this.managingEditor = options.managingEditor; + this.webMaster = options.webMaster; + this.ttl = options.ttl; this.items = items || []; this.item = function (options) { @@ -58,9 +66,22 @@ function generateXML (data){ channel.push({ generator: 'NodeJS RSS Module' }); channel.push({ lastBuildDate: new Date().toGMTString() }); - ifTruePush(data.feed_url, channel, { 'atom:link': { _attr: { href: data.feed_url, rel: 'self', type: 'application/rss+xml' } } }); - // { updated: new Date().toGMTString() } + ifTruePush(data.feed_url, channel, { 'atom:link': { _attr: { href: data.feed_url, rel: 'self', type: 'application/rss+xml' } } }); + ifTruePush(data.author, channel, { 'author': { _cdata: data.author } }); + ifTruePush(data.pubDate, channel, { 'pubDate': new Date(data.pubDate).toGMTString() }); + ifTruePush(data.copyright, channel, { 'copyright': { _cdata: data.copyright } }); + ifTruePush(data.language, channel, { 'language': { _cdata: data.language } }); + ifTruePush(data.managingEditor, channel, { 'managingEditor': { _cdata: data.managingEditor } }); + ifTruePush(data.webMaster, channel, { 'webMaster': { _cdata: data.webMaster } }); + ifTruePush(data.docs, channel, { 'docs': data.docs }); + ifTruePush(data.ttl, channel, { 'ttl': data.ttl }); + if (data.categories) { + data.categories.forEach(function(category) { + ifTruePush(category, channel, { category: { _cdata: category } }); + }); + } + // { updated: new Date().toGMTString() } data.items.forEach(function(item) { var item_values = [ diff --git a/readme.md b/readme.md index e7c158c..c666faf 100644 --- a/readme.md +++ b/readme.md @@ -24,7 +24,15 @@ feed_url: 'http://example.com/rss.xml', site_url: 'http://example.com', image_url: 'http://example.com/icon.png', - author: 'Dylan Greene' + docs: 'http://example.com/rss/docs.html', + author: 'Dylan Greene', + managingEditor: 'Dylan Green', + webMaster: 'Dylan Green', + copyright: '2013 Dylan Green', + language: 'en', + categories: ['Category 1','Category 2','Category 3'], + pubDate: 'May 20, 2012 04:00:00 GMT', + ttl: '60' }); /* loop over data and add to feed */ @@ -48,7 +56,15 @@ * _feed_url_ Url to the rss feed. * _site_url_ Url to the site that the feed is for. * _image_url_ Optional. Small image for feed readers to use. + * _docs_ Optional. Url to documentation on this feed. * _author_ Who owns this feed. + * _managingEditor_ Optional. Who manages content in this feed. + * _webMaster_ Optional. Who manages feed availability and technical support. + * _copyright_ Optional. Copyright information for this feed. + * _language_ Optional. The language of the content of this feed. + * _categories_ Optional. One or more categories this feed belongs to. + * _pubDate_ Optional. The publication date for content in the feed + * _ttl_ Optional. Number of minutes feed can be cached before refreshing from source. ### Item Options diff --git a/test/test.js b/test/test.js index 5faa7fd..598d710 100644 --- a/test/test.js +++ b/test/test.js @@ -22,7 +22,15 @@ module.exports = { feed_url: 'http://example.com/rss.xml', site_url: 'http://example.com', image_url: 'http://example.com/icon.png', - author: 'Dylan Greene' + author: 'Dylan Greene', + categories: ['Category 1','Category 2','Category 3'], + pubDate: 'May 20, 2012 04:00:00 GMT', + docs: 'http://example.com/rss/docs.html', + copyright: '2013 Dylan Green', + language: 'en', + managingEditor: 'Dylan Green', + webMaster: 'Dylan Green', + ttl: '60' }); feed.item({ @@ -60,7 +68,7 @@ module.exports = { date: 'May 28, 2012 04:00:00 GMT' }); - var expectedResult = '\n<![CDATA[title]]>http://example.comhttp://example.com/icon.pngtitlehttp://example.comNodeJS RSS Module' + new Date().toUTCString() +'<![CDATA[item 1]]>http://example.com/article1http://example.com/article1Thu, 24 May 2012 04:00:00 GMT<![CDATA[item 2]]>http://example.com/article2http://example.com/article2Fri, 25 May 2012 04:00:00 GMT<![CDATA[item 3]]>http://example.com/article3item3Sat, 26 May 2012 04:00:00 GMT<![CDATA[item 4 & html test with <strong>]]>html]]>http://example.com/article4?this&thathttp://example.com/article4?this&thatSun, 27 May 2012 04:00:00 GMT<![CDATA[item 5 & test for categories]]>http://example.com/article5http://example.com/article5Mon, 28 May 2012 04:00:00 GMT'; + var expectedResult = '\n<![CDATA[title]]>http://example.comhttp://example.com/icon.pngtitlehttp://example.comNodeJS RSS Module' + new Date().toUTCString() +'Sun, 20 May 2012 04:00:00 GMThttp://example.com/rss/docs.html60<![CDATA[item 1]]>http://example.com/article1http://example.com/article1Thu, 24 May 2012 04:00:00 GMT<![CDATA[item 2]]>http://example.com/article2http://example.com/article2Fri, 25 May 2012 04:00:00 GMT<![CDATA[item 3]]>http://example.com/article3item3Sat, 26 May 2012 04:00:00 GMT<![CDATA[item 4 & html test with <strong>]]>html]]>http://example.com/article4?this&thathttp://example.com/article4?this&thatSun, 27 May 2012 04:00:00 GMT<![CDATA[item 5 & test for categories]]>http://example.com/article5http://example.com/article5Mon, 28 May 2012 04:00:00 GMT'; var result = feed.xml(); test.equal(result.length, expectedResult.length); @@ -74,7 +82,15 @@ module.exports = { description: 'description', feed_url: 'http://example.com/rss.xml', site_url: 'http://example.com', - author: 'Dylan Greene' + author: 'Dylan Greene', + categories: ['Category 1','Category 2','Category 3'], + pubDate: 'May 20, 2012 04:00:00 GMT', + docs: 'http://example.com/rss/docs.html', + copyright: '2013 Dylan Green', + language: 'en', + managingEditor: 'Dylan Green', + webMaster: 'Dylan Green', + ttl: '60' }); feed.item({ @@ -112,7 +128,7 @@ module.exports = { date: 'May 28, 2012 04:00:00 GMT' }); - var expectedResult = '\n<![CDATA[title]]>http://example.comNodeJS RSS Module' + new Date().toUTCString() +'<![CDATA[item 1]]>http://example.com/article1http://example.com/article1Thu, 24 May 2012 04:00:00 GMT<![CDATA[item 2]]>http://example.com/article2http://example.com/article2Fri, 25 May 2012 04:00:00 GMT<![CDATA[item 3]]>http://example.com/article3item3Sat, 26 May 2012 04:00:00 GMT<![CDATA[item 4 & html test with <strong>]]>html]]>http://example.com/article4?this&thathttp://example.com/article4?this&thatSun, 27 May 2012 04:00:00 GMT<![CDATA[item 5 & test for categories]]>http://example.com/article5http://example.com/article5Mon, 28 May 2012 04:00:00 GMT'; + var expectedResult = '\n<![CDATA[title]]>http://example.comNodeJS RSS Module' + new Date().toUTCString() +'Sun, 20 May 2012 04:00:00 GMThttp://example.com/rss/docs.html60<![CDATA[item 1]]>http://example.com/article1http://example.com/article1Thu, 24 May 2012 04:00:00 GMT<![CDATA[item 2]]>http://example.com/article2http://example.com/article2Fri, 25 May 2012 04:00:00 GMT<![CDATA[item 3]]>http://example.com/article3item3Sat, 26 May 2012 04:00:00 GMT<![CDATA[item 4 & html test with <strong>]]>html]]>http://example.com/article4?this&thathttp://example.com/article4?this&thatSun, 27 May 2012 04:00:00 GMT<![CDATA[item 5 & test for categories]]>http://example.com/article5http://example.com/article5Mon, 28 May 2012 04:00:00 GMT'; var result = feed.xml(); test.equal(result.length, expectedResult.length);