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
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ declare namespace Parser {
items: (U & Item)[];
feedUrl?: string;
description?: string;
subtitle?: string;
itunes?: {
[key: string]: any;
image?: string;
Expand Down
1 change: 1 addition & 0 deletions lib/fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ fields.feed = [
['dc:type', 'type'],
'title',
'description',
'subtitle',
'author',
'pubDate',
'webMaster',
Expand Down
6 changes: 6 additions & 0 deletions lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ class Parser {
if (title._) title = title._
if (title) feed.title = title;
}
// The subtitle field is used in Atom feeds to provide a secondary description or tagline for the feed
if (xmlObj.feed.subtitle) {
let subtitle = xmlObj.feed.subtitle[0] || '';
if (subtitle._) subtitle = subtitle._;
if (subtitle) feed.subtitle = subtitle;
}
if (xmlObj.feed.updated) {
feed.lastBuildDate = xmlObj.feed.updated[0];
}
Expand Down
30 changes: 30 additions & 0 deletions test/input/subtitle-atom.atom
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Test Atom Feed with Subtitle</title>
<subtitle>A secondary description for the Atom feed</subtitle>
<link href="http://example.com" rel="alternate"/>
<link href="http://example.com/feed.atom" rel="self"/>
<updated>2024-01-02T12:00:00Z</updated>
<id>http://example.com/feed</id>
<author>
<name>Test Author</name>
</author>
<entry>
<title>Test Entry 1</title>
<link href="http://example.com/entry1" rel="alternate"/>
<id>http://example.com/entry1</id>
<updated>2024-01-01T12:00:00Z</updated>
<published>2024-01-01T12:00:00Z</published>
<summary>Summary of entry 1</summary>
<content type="html">Content of entry 1</content>
</entry>
<entry>
<title>Test Entry 2</title>
<link href="http://example.com/entry2" rel="alternate"/>
<id>http://example.com/entry2</id>
<updated>2024-01-02T12:00:00Z</updated>
<published>2024-01-02T12:00:00Z</published>
<summary>Summary of entry 2</summary>
<content type="html">Content of entry 2</content>
</entry>
</feed>
21 changes: 21 additions & 0 deletions test/input/subtitle-rss.rss
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title>Test RSS Feed with Subtitle</title>
<subtitle>A secondary description for the RSS feed</subtitle>
<description>Main description of the feed</description>
<link>http://example.com</link>
<item>
<title>Test Item 1</title>
<link>http://example.com/item1</link>
<description>Description of item 1</description>
<pubDate>Mon, 01 Jan 2024 12:00:00 GMT</pubDate>
</item>
<item>
<title>Test Item 2</title>
<link>http://example.com/item2</link>
<description>Description of item 2</description>
<pubDate>Tue, 02 Jan 2024 12:00:00 GMT</pubDate>
</item>
</channel>
</rss>
1 change: 1 addition & 0 deletions test/output/feedburner.json
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@
"link": "http://googleadsdeveloper.blogspot.com/search/label/adwords_api",
"feedUrl": "http://www.blogger.com/feeds/7815614485808579332/posts/default/-/adwords_api/-/adwords_api?start-index=26&max-results=25",
"title": "Google Ads Developer Blog",
"subtitle": "The official blog for information about the AdWords, AdSense, DoubleClick and AdMob APIs and SDKs.",
"lastBuildDate": "2016-06-27T07:36:54.007-07:00"
}
}
1 change: 1 addition & 0 deletions test/output/heise.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
"link": "http://www.heise.de/developer/",
"feedUrl": "http://www.heise.de/developer/rss/news-atom.xml",
"title": "heise developer neueste Meldungen",
"subtitle": "Informationen für Entwickler",
"lastBuildDate": "2016-02-01T17:54:50+01:00"
}
}
1 change: 1 addition & 0 deletions test/output/many-links.json
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@
"link": "http://testing.googleblog.com/",
"feedUrl": "http://www.blogger.com/feeds/15045980/posts/default?start-index=26&max-results=25&redirect=false",
"title": "Google Testing Blog",
"subtitle": "If it ain't broke, you're not trying hard enough.",
"lastBuildDate": "2017-10-18T03:40:38.732-07:00"
}
}
31 changes: 31 additions & 0 deletions test/output/subtitle-atom.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"feed": {
"items": [
{
"title": "Test Entry 1",
"link": "http://example.com/entry1",
"pubDate": "2024-01-01T12:00:00.000Z",
"content": "Content of entry 1",
"contentSnippet": "Content of entry 1",
"summary": "Summary of entry 1",
"id": "http://example.com/entry1",
"isoDate": "2024-01-01T12:00:00.000Z"
},
{
"title": "Test Entry 2",
"link": "http://example.com/entry2",
"pubDate": "2024-01-02T12:00:00.000Z",
"content": "Content of entry 2",
"contentSnippet": "Content of entry 2",
"summary": "Summary of entry 2",
"id": "http://example.com/entry2",
"isoDate": "2024-01-02T12:00:00.000Z"
}
],
"link": "http://example.com",
"feedUrl": "http://example.com/feed.atom",
"title": "Test Atom Feed with Subtitle",
"subtitle": "A secondary description for the Atom feed",
"lastBuildDate": "2024-01-02T12:00:00Z"
}
}
26 changes: 26 additions & 0 deletions test/output/subtitle-rss.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"feed": {
"items": [
{
"title": "Test Item 1",
"link": "http://example.com/item1",
"pubDate": "Mon, 01 Jan 2024 12:00:00 GMT",
"content": "Description of item 1",
"contentSnippet": "Description of item 1",
"isoDate": "2024-01-01T12:00:00.000Z"
},
{
"title": "Test Item 2",
"link": "http://example.com/item2",
"pubDate": "Tue, 02 Jan 2024 12:00:00 GMT",
"content": "Description of item 2",
"contentSnippet": "Description of item 2",
"isoDate": "2024-01-02T12:00:00.000Z"
}
],
"title": "Test RSS Feed with Subtitle",
"description": "Main description of the feed",
"subtitle": "A secondary description for the RSS feed",
"link": "http://example.com"
}
}
8 changes: 8 additions & 0 deletions test/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,12 @@ describe('Parser', function() {
it('should parse atom:link pagination links', function (done) {
testParseForFile('pagination-links', 'rss', done);
});

it('should parse subtitle field from RSS feed', function(done) {
testParseForFile('subtitle-rss', 'rss', done);
});

it('should parse subtitle field from Atom feed', function(done) {
testParseForFile('subtitle-atom', 'atom', done);
});
})