diff --git a/README.md b/README.md index bc36f07..8326109 100644 --- a/README.md +++ b/README.md @@ -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" @@ -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 `` or RSS `` 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)) @@ -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 }) }) ``` diff --git a/index.d.ts b/index.d.ts index 45b237a..ad89c72 100644 --- a/index.d.ts +++ b/index.d.ts @@ -29,6 +29,7 @@ declare namespace Parser { link?: string; guid?: string; title?: string; + subtitle?: string; pubDate?: string; creator?: string; summary?: string; @@ -59,6 +60,7 @@ declare namespace Parser { items: (U & Item)[]; feedUrl?: string; description?: string; + subtitle?: string; itunes?: { [key: string]: any; image?: string; diff --git a/lib/fields.js b/lib/fields.js index b3f8d7b..fae0953 100644 --- a/lib/fields.js +++ b/lib/fields.js @@ -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', @@ -35,6 +37,7 @@ fields.item = [ ['dc:source', 'source'], ['dc:title', 'title'], 'title', + 'subtitle', 'link', 'pubDate', 'author', diff --git a/test/input/subtitle.rss b/test/input/subtitle.rss new file mode 100644 index 0000000..07ddd6d --- /dev/null +++ b/test/input/subtitle.rss @@ -0,0 +1,27 @@ + + + + Example Blog + https://example.com/blog + A blog about technology and programming + Tech insights and tutorials + en-us + Mon, 15 Jan 2024 10:00:00 GMT + + First Post + An introduction to our blog + https://example.com/blog/post-1 + Welcome to our blog! + Mon, 15 Jan 2024 10:00:00 GMT + https://example.com/blog/post-1 + + + Second Post + More content for readers + https://example.com/blog/post-2 + Here is another post. + Sun, 14 Jan 2024 09:00:00 GMT + https://example.com/blog/post-2 + + + diff --git a/test/output/subtitle.json b/test/output/subtitle.json new file mode 100644 index 0000000..01aec06 --- /dev/null +++ b/test/output/subtitle.json @@ -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" + } +} diff --git a/test/parser.js b/test/parser.js index 034c72f..fd7b06a 100644 --- a/test/parser.js +++ b/test/parser.js @@ -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); + }); })