Skip to content

Added source support to V2 #18

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ return fetch('http://www.nasa.gov/rss/dyn/breaking_news.rss')
order: undefined, // item order number
subtitle: undefined, // item subtitle
summary: undefined, // item summary
}
},
source: {
url: undefined, // item source url
text: undefined // item source inner text
}
}]
}
```
Expand Down
13 changes: 13 additions & 0 deletions parsers/rssv2.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ const getChannelImage = (node) => {
};
};

const getItemSource = (node) => {
const sources = utils.getChildElements(node, 'source');
if (!sources || sources.length === 0) {
return undefined;
}
const source = sources[0];
return {
url: source.getAttribute('url'),
text: source.textContent
};
}

const getItemTitle = (node) => utils.getElementTextContent(node, 'title');

const getItemLinks = (node) => {
Expand Down Expand Up @@ -164,6 +176,7 @@ const mapItems = (document) => {
published: getItemPublished(item),
enclosures: getItemEnclosures(item),
itunes: itunesParser.parseItem(item),
source: getItemSource(item),
}));
};

Expand Down
10 changes: 10 additions & 0 deletions test/__snapshots__/feeds.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Object {
},
],
"published": "Tue, 30 Jan 2018 12:29:57 -0500",
"source": undefined,
"title": "U.S. general says North Korea not demonstrated all components of ICBM",
},
Object {
Expand Down Expand Up @@ -78,6 +79,7 @@ Object {
},
],
"published": "Tue, 30 Jan 2018 16:13:20 -0500",
"source": undefined,
"title": "Publication of Russia 'oligarch list' may affect investors: group",
},
Object {
Expand Down Expand Up @@ -111,6 +113,7 @@ Object {
},
],
"published": "Tue, 30 Jan 2018 17:49:58 -0500",
"source": undefined,
"title": "Democrats blast Trump decision to hold off on Russia sanctions",
},
Object {
Expand Down Expand Up @@ -144,6 +147,7 @@ Object {
},
],
"published": "Tue, 30 Jan 2018 15:32:07 -0500",
"source": undefined,
"title": "Suspected Russian warplanes hit busy market in Idlib, kill 15: rescuers, residents",
},
Object {
Expand Down Expand Up @@ -177,6 +181,7 @@ Object {
},
],
"published": "Tue, 30 Jan 2018 12:49:08 -0500",
"source": undefined,
"title": "Saudi Arabia says it has seized over $100 billion in corruption purge",
},
Object {
Expand Down Expand Up @@ -210,6 +215,7 @@ Object {
},
],
"published": "Tue, 30 Jan 2018 16:46:13 -0500",
"source": undefined,
"title": "Rocky Syria talks in Russia end, ignore key opposition demands",
},
Object {
Expand Down Expand Up @@ -243,6 +249,7 @@ Object {
},
],
"published": "Tue, 30 Jan 2018 17:33:18 -0500",
"source": undefined,
"title": "Trump administration drops Cha as pick for Seoul envoy: U.S. officials",
},
Object {
Expand Down Expand Up @@ -276,6 +283,7 @@ Object {
},
],
"published": "Tue, 30 Jan 2018 16:10:41 -0500",
"source": undefined,
"title": "Russian spy chief met U.S. officials in U.S. last week: sources",
},
Object {
Expand Down Expand Up @@ -309,6 +317,7 @@ Object {
},
],
"published": "Tue, 30 Jan 2018 13:02:25 -0500",
"source": undefined,
"title": "Vatican rebukes cardinal over 'selling out' to China accusations",
},
Object {
Expand Down Expand Up @@ -342,6 +351,7 @@ Object {
},
],
"published": "Tue, 30 Jan 2018 15:08:44 -0500",
"source": undefined,
"title": "One person killed in attack Turkish convoy in Idlib: Turkish army",
},
],
Expand Down
Loading