-
Notifications
You must be signed in to change notification settings - Fork 131
CDATA filtering options, new item addition functions, unit tests #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 11 commits
1fab44d
23aa233
ab2ab66
87e0c77
6ac9af9
3070e49
f0fc81f
6fba453
38363d1
e23f8f6
f528b84
ff24ee9
ce46bbf
5993cd5
6478f12
65a9d42
fa4d015
5450f8d
c1f6460
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| var RSS = require('../lib/rss'); | ||
|
|
||
| /* let's create an rss feed */ | ||
| var feed = new RSS({ | ||
| title: 'title', | ||
| description: 'description', | ||
| feed_url: 'http://example.com/rss.xml', | ||
| site_url: 'http://example.com', | ||
| image_url: 'http://example.com/icon.png', | ||
| docs: 'http://example.com/rss/docs.html', | ||
| managingEditor: 'Dylan Greene', | ||
| webMaster: 'Dylan Greene', | ||
| copyright: '2013 Dylan Greene', | ||
| language: 'en', | ||
| categories: ['Category 1','Category 2','Category 3'], | ||
| pubDate: 'May 20, 2012 04:00:00 GMT', | ||
| ttl: '60', | ||
| no_cdata_fields: ['title', 'category'], | ||
| customNamespaces: { | ||
| 'itunes': 'http://www.itunes.com/dtds/podcast-1.0.dtd' | ||
| }, | ||
| custom_elements: [ | ||
| {'itunes:subtitle': 'A show about everything'}, | ||
| {'itunes:author': 'John Doe'}, | ||
| {'itunes:summary': 'All About Everything is a show about everything. Each week we dive into any subject known to man and talk about it as much as we can. Look for our podcast in the Podcasts app or in the iTunes Store'}, | ||
| {'itunes:owner': [ | ||
| {'itunes:name': 'John Doe'}, | ||
| {'itunes:email': '[email protected]'} | ||
| ]}, | ||
| {'itunes:image': { | ||
| _attr: { | ||
| href: 'http://example.com/podcasts/everything/AllAboutEverything.jpg' | ||
| } | ||
| }}, | ||
| {'itunes:category': [ | ||
| {_attr: { | ||
| text: 'Technology' | ||
| }}, | ||
| {'itunes:category': { | ||
| _attr: { | ||
| text: 'Gadgets' | ||
| } | ||
| }} | ||
| ]} | ||
| ] | ||
| }); | ||
|
|
||
| /* loop over data and add to feed */ | ||
| feed.item({ | ||
| title: 'item title & fun', | ||
| description: 'use this for the content. It can include html.', | ||
| url: 'http://example.com/article4?this&that', // link to the item | ||
| guid: '1123', // optional - defaults to url | ||
| categories: ['Category 1','Category 2','Category 3','Category 4'], // optional - array of item categories | ||
| author: 'Guest Author', // optional - defaults to feed author property | ||
| date: 'May 27, 2012', // any format that js Date can parse. | ||
| lat: 33.417974, //optional latitude field for GeoRSS | ||
| long: -111.933231, //optional longitude field for GeoRSS | ||
| enclosure: {url:'https://www.google.com/images/srpr/logo11w.png'}, | ||
| // enclosure: {file:'path-to-file'}, // optional enclosure | ||
| custom_elements: [ | ||
| {'itunes:author': 'John Doe'}, | ||
| {'itunes:subtitle': 'A short primer on table spices'}, | ||
| {'itunes:image': { | ||
| _attr: { | ||
| href: 'http://example.com/podcasts/everything/AllAboutEverything/Episode1.jpg' | ||
| } | ||
| }}, | ||
| {'itunes:duration': '7:04'} | ||
| ] | ||
| }); | ||
|
|
||
| // cache the xml to send to clients | ||
| var xml = feed.xml("\t"); | ||
|
|
||
| console.log(xml); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,13 +2,6 @@ | |
|
|
||
| > RSS feed generator. Add RSS feeds to any project. Supports enclosures and GeoRSS. | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| ### Usage | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The readme file is generated.
The files it uses are in |
||
|
|
||
| #### Create a new feed | ||
|
|
@@ -38,18 +31,13 @@ var feed = new RSS(feedOptions); | |
| * `hub` _optional_ **PubSubHubbub hub url** Where is the PubSubHub hub located. | ||
| * `custom_namespaces` _optional_ **object** Put additional namespaces in <rss> element (without 'xmlns:' prefix) | ||
| * `custom_elements` _optional_ **array** Put additional elements in the feed (node-xml syntax) | ||
| * `no_cdata_fields` _optional_ **array** Field names that shouldn't be wrapped with CDATA tag. The data will be escaped for XML. Default is to wrap with CDATA. You should only use this to work around problematic XML clients. | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make this change in |
||
|
|
||
| #### Add items to a feed | ||
|
|
||
| An item can be used for a blog entry, project update, log entry, etc. Your RSS feed | ||
| can have any number of items. Most feeds use 20 or fewer items. | ||
|
|
||
| ```js | ||
| feed.item(itemOptions); | ||
| ``` | ||
|
|
||
| ##### itemOptions | ||
|
|
||
| * `title` **string** Title of this particular item. | ||
| * `description` **string** Content for the item. Can contain html but link and image urls must be absolute path including hostname. | ||
| * `url` **url string** Url to the item. This could be a blog entry. | ||
|
|
@@ -67,7 +55,20 @@ feed.item(itemOptions); | |
| * `long` _optional_ **number** The longitude coordinate of the item. | ||
| * `custom_elements` _optional_ **array** Put additional elements in the item (node-xml syntax) | ||
|
|
||
| ##### Feed XML | ||
| ##### Add single item | ||
| ```js | ||
| feed.item(itemOptions); | ||
| ``` | ||
| ##### Concatenate an array of items | ||
| ```js | ||
| feed.concat_items(arrayOfItemOptions); | ||
| ``` | ||
| ##### Replace items with a new array of items | ||
| ```js | ||
| feed.replace_items(arrayOfItemOptions); | ||
| ``` | ||
|
|
||
| #### Feed XML | ||
|
|
||
| ```js | ||
| var xml = feed.xml(indent); | ||
|
|
@@ -80,11 +81,12 @@ This returns the XML as a string. | |
|
|
||
|
|
||
| ### Example Usage | ||
| (examples/simple.js) | ||
|
||
|
|
||
| ```js | ||
| var RSS = require('rss'); | ||
| var RSS = require('../lib/rss'); | ||
|
|
||
| /* lets create an rss feed */ | ||
| /* let's create an rss feed */ | ||
| var feed = new RSS({ | ||
| title: 'title', | ||
| description: 'description', | ||
|
|
@@ -99,10 +101,11 @@ var feed = new RSS({ | |
| categories: ['Category 1','Category 2','Category 3'], | ||
| pubDate: 'May 20, 2012 04:00:00 GMT', | ||
| ttl: '60', | ||
| customNamespaces: { | ||
| no_cdata_fields: ['title', 'category'], | ||
| custom_namespaces: { | ||
| 'itunes': 'http://www.itunes.com/dtds/podcast-1.0.dtd' | ||
| }, | ||
| custom: [ | ||
| custom_elements: [ | ||
| {'itunes:subtitle': 'A show about everything'}, | ||
| {'itunes:author': 'John Doe'}, | ||
| {'itunes:summary': 'All About Everything is a show about everything. Each week we dive into any subject known to man and talk about it as much as we can. Look for our podcast in the Podcasts app or in the iTunes Store'}, | ||
|
|
@@ -128,7 +131,6 @@ var feed = new RSS({ | |
| ] | ||
| }); | ||
|
|
||
| /* loop over data and add to feed */ | ||
| feed.item({ | ||
| title: 'item title', | ||
| description: 'use this for the content. It can include html.', | ||
|
|
@@ -139,8 +141,9 @@ feed.item({ | |
| date: 'May 27, 2012', // any format that js Date can parse. | ||
| lat: 33.417974, //optional latitude field for GeoRSS | ||
| long: -111.933231, //optional longitude field for GeoRSS | ||
| enclosure: {url:'...', file:'path-to-file'}, // optional enclosure | ||
| custom: [ | ||
| enclosure: {url:'https://www.google.com/images/srpr/logo11w.png'}, | ||
| // enclosure: {file:'path-to-file'}, // optional enclosure | ||
| custom_elements: [ | ||
| {'itunes:author': 'John Doe'}, | ||
| {'itunes:subtitle': 'A short primer on table spices'}, | ||
| {'itunes:image': { | ||
|
|
@@ -153,7 +156,52 @@ feed.item({ | |
| }); | ||
|
|
||
| // cache the xml to send to clients | ||
| var xml = feed.xml(); | ||
| var xml = feed.xml("\t"); | ||
| console.log(xml); | ||
| ``` | ||
| #### XML Output: | ||
| ```xml | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"> | ||
| <channel> | ||
| <title>title</title> | ||
| <description><![CDATA[description]]></description> | ||
| <link>http://example.com</link> | ||
| <image> | ||
| <url>http://example.com/icon.png</url> | ||
| <title>title</title> | ||
| <link>http://example.com</link> | ||
| </image> | ||
| <generator>RSS for Node</generator> | ||
| <lastBuildDate>Sat, 13 Dec 2014 01:44:19 GMT</lastBuildDate> | ||
| <atom:link href="http://example.com/rss.xml" rel="self" type="application/rss+xml"/> | ||
| <pubDate>Sun, 20 May 2012 04:00:00 GMT</pubDate> | ||
| <copyright><![CDATA[2013 Dylan Greene]]></copyright> | ||
| <language><![CDATA[en]]></language> | ||
| <managingEditor><![CDATA[Dylan Greene]]></managingEditor> | ||
| <webMaster><![CDATA[Dylan Greene]]></webMaster> | ||
| <docs>http://example.com/rss/docs.html</docs> | ||
| <ttl>60</ttl> | ||
| <category>Category 1</category> | ||
| <category>Category 2</category> | ||
| <category>Category 3</category> | ||
| <item> | ||
| <title>item title</title> | ||
| <description><![CDATA[use this for the content. It can include html.]]></description> | ||
| <link>http://example.com/article4?this&that</link> | ||
| <guid isPermaLink="false">1123</guid> | ||
| <category>Category 1</category> | ||
| <category>Category 2</category> | ||
| <category>Category 3</category> | ||
| <category>Category 4</category> | ||
| <dc:creator><![CDATA[Guest Author]]></dc:creator> | ||
| <pubDate>Sun, 27 May 2012 07:00:00 GMT</pubDate> | ||
| <geo:lat>33.417974</geo:lat> | ||
| <geo:long>-111.933231</geo:long> | ||
| <enclosure url="https://www.google.com/images/srpr/logo11w.png" length="0" type="image/png"/> | ||
| </item> | ||
| </channel> | ||
| </rss> | ||
| ``` | ||
|
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Example of specifying a field for no CDATA wrapping