Skip to content
Draft
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
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,11 @@ Check out the full output format in [test/output/reddit.json](test/output/reddit
feedUrl: 'https://www.reddit.com/.rss'
title: 'reddit: the front page of the internet'
description: ""
subtitle: 'Front page highlights'
link: 'https://www.reddit.com/'
items:
- title: 'The water is too deep, so he improvises'
subtitle: 'A quick summary of the post'
link: 'https://www.reddit.com/r/funny/comments/3skxqc/the_water_is_too_deep_so_he_improvises/'
pubDate: 'Thu, 12 Nov 2015 21:16:39 +0000'
creator: "John Doe"
Expand All @@ -129,6 +131,7 @@ items:

##### Notes:
* The `contentSnippet` field strips out HTML tags and unescapes HTML entities
* `subtitle` is returned for both feeds and items when the source XML includes it (for example, Atom `<subtitle>` or RSS `<subtitle>` elements)
* The `dc:` prefix will be removed from all fields
* Both `dc:date` and `pubDate` will be available in ISO 8601 format as `isoDate`
* If `author` is specified, but not `dc:creator`, `creator` will be set to `author` ([see article](http://www.lowter.com/blogs/2008/2/9/rss-dccreator-author))
Expand All @@ -137,21 +140,23 @@ items:
## XML Options

### Custom Fields
If your RSS feed contains fields that aren't currently returned, you can access them using the `customFields` option.
If your RSS feed contains fields that aren't currently returned, you can access them using the `customFields` option. Built-in fields such as `title`, `description`, and `subtitle` do not need to be listed here.

```js
let parser = new Parser({
customFields: {
feed: ['otherTitle', 'extendedDescription'],
item: ['coAuthor','subtitle'],
item: ['coAuthor', 'readingTime'],
}
});

parser.parseURL('https://www.reddit.com/.rss', function(err, feed) {
console.log(feed.extendedDescription);
console.log(feed.subtitle); // built-in when present

feed.items.forEach(function(entry) {
console.log(entry.coAuthor + ':' + entry.subtitle);
console.log(entry.coAuthor + ':' + entry.readingTime);
console.log(entry.subtitle); // built-in when present
})
})
```
Expand Down
2 changes: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ declare namespace Parser {
link?: string;
guid?: string;
title?: string;
subtitle?: string;
pubDate?: string;
creator?: string;
summary?: string;
Expand Down Expand Up @@ -59,6 +60,7 @@ declare namespace Parser {
items: (U & Item)[];
feedUrl?: string;
description?: string;
subtitle?: string;
itunes?: {
[key: string]: any;
image?: string;
Expand Down
3 changes: 3 additions & 0 deletions lib/fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ fields.feed = [
['dc:type', 'type'],
'title',
'description',
// Common in Atom feeds and supported by some RSS feeds.
'subtitle',
'author',
'pubDate',
'webMaster',
Expand All @@ -35,6 +37,7 @@ fields.item = [
['dc:source', 'source'],
['dc:title', 'title'],
'title',
'subtitle',
'link',
'pubDate',
'author',
Expand Down
27 changes: 27 additions & 0 deletions test/input/subtitle.rss
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title>Example Blog</title>
<link>https://example.com/blog</link>
<description>A blog about technology and programming</description>
<subtitle>Tech insights and tutorials</subtitle>
<language>en-us</language>
<lastBuildDate>Mon, 15 Jan 2024 10:00:00 GMT</lastBuildDate>
<item>
<title>First Post</title>
<subtitle>An introduction to our blog</subtitle>
<link>https://example.com/blog/post-1</link>
<description>Welcome to our blog!</description>
<pubDate>Mon, 15 Jan 2024 10:00:00 GMT</pubDate>
<guid>https://example.com/blog/post-1</guid>
</item>
<item>
<title>Second Post</title>
<subtitle>More content for readers</subtitle>
<link>https://example.com/blog/post-2</link>
<description>Here is another post.</description>
<pubDate>Sun, 14 Jan 2024 09:00:00 GMT</pubDate>
<guid>https://example.com/blog/post-2</guid>
</item>
</channel>
</rss>
32 changes: 32 additions & 0 deletions test/output/subtitle.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"feed": {
"items": [
{
"title": "First Post",
"subtitle": "An introduction to our blog",
"link": "https://example.com/blog/post-1",
"pubDate": "Mon, 15 Jan 2024 10:00:00 GMT",
"content": "Welcome to our blog!",
"contentSnippet": "Welcome to our blog!",
"guid": "https://example.com/blog/post-1",
"isoDate": "2024-01-15T10:00:00.000Z"
},
{
"title": "Second Post",
"subtitle": "More content for readers",
"link": "https://example.com/blog/post-2",
"pubDate": "Sun, 14 Jan 2024 09:00:00 GMT",
"content": "Here is another post.",
"contentSnippet": "Here is another post.",
"guid": "https://example.com/blog/post-2",
"isoDate": "2024-01-14T09:00:00.000Z"
}
],
"title": "Example Blog",
"description": "A blog about technology and programming",
"subtitle": "Tech insights and tutorials",
"link": "https://example.com/blog",
"language": "en-us",
"lastBuildDate": "Mon, 15 Jan 2024 10:00:00 GMT"
}
}
4 changes: 4 additions & 0 deletions test/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,8 @@ describe('Parser', function() {
it('should parse atom:link pagination links', function (done) {
testParseForFile('pagination-links', 'rss', done);
});

it('should parse subtitle field in feed and items', function(done) {
testParseForFile('subtitle', 'rss', done);
});
})
Loading