Skip to content

Commit cda8ec3

Browse files
committed
Add support for content:encoded with rssv2 feeds
1 parent 9f8e7ef commit cda8ec3

File tree

7 files changed

+347
-14
lines changed

7 files changed

+347
-14
lines changed

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -138,18 +138,18 @@ return fetch('http://www.nasa.gov/rss/dyn/breaking_news.rss')
138138

139139
### Item / Entry Level elements
140140

141-
| Parsed Value | RSS v2.0 | Atom v1.0 |
142-
| ------------- | ------------- | ------------- |
143-
| id | guid | id |
144-
| title | title | title |
145-
| imageUrl | | icon |
146-
| links | link | link |
147-
| description | description | summary |
148-
| content | | content |
149-
| categories | category | category |
150-
| authors | author | contributor |
151-
| published | pubDate | published |
152-
| enclosures | enclosures | link |
141+
| Parsed Value | RSS v2.0 | Atom v1.0 |
142+
| ------------- | --------------- | ------------- |
143+
| id | guid | id |
144+
| title | title | title |
145+
| imageUrl | | icon |
146+
| links | link | link |
147+
| description | description | summary |
148+
| content | content:encoded | content |
149+
| categories | category | category |
150+
| authors | author | contributor |
151+
| published | pubDate | published |
152+
| enclosures | enclosures | link |
153153

154154
## Development setup
155155

package-lock.json

Lines changed: 201 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-rss-parser",
3-
"version": "1.2.0",
3+
"version": "1.3.0",
44
"description": "React Native compatible package to parse RSS feeds",
55
"main": "index.js",
66
"scripts": {

parsers/namespaces.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
exports.itunes = 'http://www.itunes.com/dtds/podcast-1.0.dtd';
1+
exports.itunes = 'http://www.itunes.com/dtds/podcast-1.0.dtd';
2+
exports.content = 'http://purl.org/rss/1.0/modules/content/';

parsers/rssv2.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var utils = require('./utils');
22
var model = require('../model/rss');
3+
var namespaces = require('./namespaces');
34
var itunesParser = require('./itunes');
45

56
exports.parse = function(document) {
@@ -134,6 +135,10 @@ function getItemDescription(node) {
134135
return utils.getElementTextContent(node, 'description');
135136
}
136137

138+
function getItemContent(node) {
139+
return utils.getElementTextContent(node, 'encoded', namespaces.content);
140+
}
141+
137142
function getItemAuthors(node) {
138143
const authors = utils.getElementTextContentArray(node, 'author');
139144

@@ -182,6 +187,7 @@ function mapItems(document) {
182187
title: getItemTitle(item),
183188
links: getItemLinks(item),
184189
description: getItemDescription(item),
190+
content: getItemContent(item),
185191
id: getItemId(item),
186192
authors: getItemAuthors(item),
187193
categories: getItemCategories(item),

test/samples/rssv2-with-content.js

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
exports.feed = `
2+
<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
3+
xmlns:content="http://purl.org/rss/1.0/modules/content/"
4+
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
5+
xmlns:dc="http://purl.org/dc/elements/1.1/"
6+
xmlns:atom="http://www.w3.org/2005/Atom"
7+
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
8+
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
9+
xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
10+
>
11+
12+
<channel>
13+
<title>The WordPress.com Blog</title>
14+
<atom:link href="https://en.blog.wordpress.com/feed/" rel="self" type="application/rss+xml" />
15+
<link>https://en.blog.wordpress.com</link>
16+
<description>The latest news on WordPress.com and the WordPress community.</description>
17+
<lastBuildDate>
18+
Fri, 07 Sep 2018 19:30:56 +0000 </lastBuildDate>
19+
<language>en</language>
20+
<sy:updatePeriod>
21+
hourly </sy:updatePeriod>
22+
<sy:updateFrequency>
23+
1 </sy:updateFrequency>
24+
<generator>http://wordpress.com/</generator>
25+
<cloud domain='en.blog.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
26+
<image>
27+
<url>https://secure.gravatar.com/blavatar/e6392390e3bcfadff3671c5a5653d95b?s=96&#038;d=https%3A%2F%2Fs0.wp.com%2Fi%2Fbuttonw-com.png</url>
28+
<title>The WordPress.com Blog</title>
29+
<link>https://en.blog.wordpress.com</link>
30+
</image>
31+
<atom:link rel="search" type="application/opensearchdescription+xml" href="https://en.blog.wordpress.com/osd.xml" title="The WordPress.com Blog" />
32+
<atom:link rel='hub' href='https://en.blog.wordpress.com/?pushpress=hub'/>
33+
<item>
34+
<title>New in the WordPress.com Business Plan: Jetpack Search</title>
35+
<link>https://en.blog.wordpress.com/2018/08/31/new-in-the-wordpress-com-business-plan-jetpack-search/</link>
36+
<comments>https://en.blog.wordpress.com/2018/08/31/new-in-the-wordpress-com-business-plan-jetpack-search/#comments</comments>
37+
<pubDate>Fri, 31 Aug 2018 17:24:06 +0000</pubDate>
38+
<dc:creator><![CDATA[Greg Ichneumon Brown]]></dc:creator>
39+
<category><![CDATA[Customization]]></category>
40+
<category><![CDATA[Jetpack]]></category>
41+
<category><![CDATA[New Features]]></category>
42+
<category><![CDATA[search]]></category>
43+
<category><![CDATA[WordPress.com]]></category>
44+
<category><![CDATA[algorithm]]></category>
45+
<category><![CDATA[Jetpack Search]]></category>
46+
47+
<guid isPermaLink="false">http://en.blog.wordpress.com/?p=40675</guid>
48+
<description><![CDATA[The WordPress.com Business plan combines fully managed hosting with the freedom to grow and scale your site without limits. Today we&#8217;re adding Jetpack Search to WordPress.com Business so you can enjoy powerful and fast on-site search functionality as part of your plan. &#160; Once you activate Jetpack Search, you&#8217;ll be &#8230;]]></description>
49+
<content:encoded><![CDATA[This is test item 1]]></content:encoded>
50+
<wfw:commentRss>https://en.blog.wordpress.com/2018/08/31/new-in-the-wordpress-com-business-plan-jetpack-search/feed/</wfw:commentRss>
51+
<slash:comments>21</slash:comments>
52+
53+
<media:thumbnail url="https://en-blog.files.wordpress.com/2018/08/search-featured-image.png" />
54+
<media:content url="https://en-blog.files.wordpress.com/2018/08/search-featured-image.png" medium="image">
55+
<media:title type="html">search-featured-image</media:title>
56+
</media:content>
57+
58+
<media:content url="https://0.gravatar.com/avatar/915ee4efbd21f12b55b6362cf4f7c42f?s=96&#38;d=retro" medium="image">
59+
<media:title type="html">gibrown</media:title>
60+
</media:content>
61+
62+
<media:content url="https://en-blog.files.wordpress.com/2018/08/jetpack-search-corrected.png" medium="image">
63+
<media:title type="html">jetpack-search-corrected.png</media:title>
64+
</media:content>
65+
66+
<media:content url="https://en-blog.files.wordpress.com/2018/08/jetpack-search-sidebar1.png" medium="image">
67+
<media:title type="html">jetpack-search-sidebar.png</media:title>
68+
</media:content>
69+
</item>
70+
<item>
71+
<title>Introducing the Simple Payment Widget</title>
72+
<link>https://en.blog.wordpress.com/2018/08/14/introducing-the-simple-payment-widget/</link>
73+
<comments>https://en.blog.wordpress.com/2018/08/14/introducing-the-simple-payment-widget/#comments</comments>
74+
<pubDate>Tue, 14 Aug 2018 12:00:27 +0000</pubDate>
75+
<dc:creator><![CDATA[Rodrigo]]></dc:creator>
76+
<category><![CDATA[New Features]]></category>
77+
<category><![CDATA[Widgets]]></category>
78+
<category><![CDATA[WordPress.com]]></category>
79+
<category><![CDATA[Simple Payment]]></category>
80+
81+
<guid isPermaLink="false">http://en.blog.wordpress.com/?p=40644</guid>
82+
<description><![CDATA[Take payments anywhere on your site.]]></description>
83+
<content:encoded><![CDATA[This is test item 2]]></content:encoded>
84+
<wfw:commentRss>https://en.blog.wordpress.com/2018/08/14/introducing-the-simple-payment-widget/feed/</wfw:commentRss>
85+
<slash:comments>24</slash:comments>
86+
87+
<media:thumbnail url="https://en-blog.files.wordpress.com/2017/08/featured-image-x22.jpg" />
88+
<media:content url="https://en-blog.files.wordpress.com/2017/08/featured-image-x22.jpg" medium="image">
89+
<media:title type="html">featured-image-x2</media:title>
90+
</media:content>
91+
92+
<media:content url="https://1.gravatar.com/avatar/4a8ca7e63853594d35148222ec87eac8?s=96&#38;d=retro" medium="image">
93+
<media:title type="html">okenobi</media:title>
94+
</media:content>
95+
96+
<media:content url="https://en-blog.files.wordpress.com/2018/08/screen-shot-2018-08-06-at-11-40-15.png" medium="image">
97+
<media:title type="html">Screen Shot 2018-08-06 at 11.40.15</media:title>
98+
</media:content>
99+
100+
<media:content url="https://en-blog.files.wordpress.com/2018/08/screen-shot-2018-08-06-at-15-06-55.png" medium="image">
101+
<media:title type="html">Screen Shot 2018-08-06 at 15.06.55</media:title>
102+
</media:content>
103+
104+
<media:content url="https://en-blog.files.wordpress.com/2018/08/screen-shot-2018-08-07-at-16-05-10.png" medium="image">
105+
<media:title type="html">Screen Shot 2018-08-07 at 16.05.10</media:title>
106+
</media:content>
107+
108+
<media:content url="https://en-blog.files.wordpress.com/2018/08/screen-shot-2018-08-07-at-15-11-30.png" medium="image">
109+
<media:title type="html">Screen Shot 2018-08-07 at 15.11.30</media:title>
110+
</media:content>
111+
</item>
112+
</channel>
113+
</rss>`;

0 commit comments

Comments
 (0)