Skip to content

Commit c843a5a

Browse files
Document subtitle support
Co-authored-by: openhands <openhands@all-hands.dev>
1 parent 0cbbc99 commit c843a5a

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,11 @@ Check out the full output format in [test/output/reddit.json](test/output/reddit
113113
feedUrl: 'https://www.reddit.com/.rss'
114114
title: 'reddit: the front page of the internet'
115115
description: ""
116+
subtitle: 'Front page highlights'
116117
link: 'https://www.reddit.com/'
117118
items:
118119
- title: 'The water is too deep, so he improvises'
120+
subtitle: 'A quick summary of the post'
119121
link: 'https://www.reddit.com/r/funny/comments/3skxqc/the_water_is_too_deep_so_he_improvises/'
120122
pubDate: 'Thu, 12 Nov 2015 21:16:39 +0000'
121123
creator: "John Doe"
@@ -129,6 +131,7 @@ items:
129131
130132
##### Notes:
131133
* The `contentSnippet` field strips out HTML tags and unescapes HTML entities
134+
* `subtitle` is returned for both feeds and items when the source XML includes it (for example, Atom `<subtitle>` or RSS `<subtitle>` elements)
132135
* The `dc:` prefix will be removed from all fields
133136
* Both `dc:date` and `pubDate` will be available in ISO 8601 format as `isoDate`
134137
* 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:
137140
## XML Options
138141

139142
### Custom Fields
140-
If your RSS feed contains fields that aren't currently returned, you can access them using the `customFields` option.
143+
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.
141144

142145
```js
143146
let parser = new Parser({
144147
customFields: {
145148
feed: ['otherTitle', 'extendedDescription'],
146-
item: ['coAuthor','subtitle'],
149+
item: ['coAuthor', 'readingTime'],
147150
}
148151
});
149152
150153
parser.parseURL('https://www.reddit.com/.rss', function(err, feed) {
151154
console.log(feed.extendedDescription);
155+
console.log(feed.subtitle); // built-in when present
152156
153157
feed.items.forEach(function(entry) {
154-
console.log(entry.coAuthor + ':' + entry.subtitle);
158+
console.log(entry.coAuthor + ':' + entry.readingTime);
159+
console.log(entry.subtitle); // built-in when present
155160
})
156161
})
157162
```

index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ declare namespace Parser {
2929
link?: string;
3030
guid?: string;
3131
title?: string;
32+
subtitle?: string;
3233
pubDate?: string;
3334
creator?: string;
3435
summary?: string;
@@ -59,6 +60,7 @@ declare namespace Parser {
5960
items: (U & Item)[];
6061
feedUrl?: string;
6162
description?: string;
63+
subtitle?: string;
6264
itunes?: {
6365
[key: string]: any;
6466
image?: string;

lib/fields.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ fields.feed = [
99
['dc:type', 'type'],
1010
'title',
1111
'description',
12+
// Common in Atom feeds and supported by some RSS feeds.
1213
'subtitle',
1314
'author',
1415
'pubDate',

0 commit comments

Comments
 (0)