-
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
Closed
Closed
Changes from 5 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
1fab44d
Merge from upstream master
23aa233
Allowing selective disabling of CDATA wrapping by field name. Adding …
ab2ab66
Update readme.md
rv-kip 87e0c77
Everyone loves an example
6ac9af9
Didn't end up using underscore.
3070e49
Changing param name to no_encode_fields in all needed places
f0fc81f
... plus one more place
6fba453
Going back to 'no_cdata_fields' for name. Clarifying use case in docs…
38363d1
Fixing typo in example
e23f8f6
README cleanup for custom_namespaces and custom_elements
f528b84
Fixing bug. Items passed in on RSS obj creation did not get processed…
ff24ee9
Merge branch 'master' of https://github.com/dylang/node-rss into reap…
ce46bbf
Moving tests from defunct PR into new branch
5993cd5
Added tests for new functionality
rv-kip 6478f12
Missing mime dependency and a dupe dep
rv-kip 65a9d42
Removing old mocha test
rv-kip fa4d015
Documentation update and readme generation
rv-kip 5450f8d
Moving mime to dependencies
rv-kip c1f6460
Indenting change on example. Commenting.
rv-kip File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: [ | ||
| {'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', | ||
| 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: [ | ||
| {'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(" "); | ||
|
|
||
| console.log(xml); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,18 +38,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. Default is to wrap | ||
|
|
||
| #### 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 +62,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 +88,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,6 +108,7 @@ var feed = new RSS({ | |
| 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' | ||
| }, | ||
|
|
@@ -139,7 +149,8 @@ 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 | ||
| enclosure: {url:'https://www.google.com/images/srpr/logo11w.png'}, | ||
| // enclosure: {file:'path-to-file'}, // optional enclosure | ||
| custom: [ | ||
| {'itunes:author': 'John Doe'}, | ||
| {'itunes:subtitle': 'A short primer on table spices'}, | ||
|
|
@@ -153,7 +164,52 @@ feed.item({ | |
| }); | ||
|
|
||
| // cache the xml to send to clients | ||
| var xml = feed.xml(); | ||
| var xml = feed.xml(" "); | ||
| 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> | ||
| ``` | ||
|
|
||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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