@@ -8,7 +8,7 @@ function isAtomFeed(doc) {
8
8
}
9
9
10
10
function isRssFeed ( doc ) {
11
- return doc . documentElement . localName === 'channel ' ;
11
+ return doc . documentElement . localName === 'rss ' ;
12
12
}
13
13
14
14
function processAtomFeed ( doc ) {
@@ -40,13 +40,38 @@ function processAtomFeed(doc) {
40
40
return ret ;
41
41
}
42
42
) ;
43
- // console.log(entries);
44
43
return entries ;
45
44
}
46
45
47
46
function processRssFeed ( doc ) {
48
- console . error ( 'TODO: process RSS' ) ;
49
- return [ ] ;
47
+ const feedLink = doc . querySelector (
48
+ 'channel > link:not([rel]), channel > link[rel=alternate]'
49
+ ) ?. textContent ;
50
+ const feedAuthor = doc . querySelector ( 'channel > author' ) ?. textContent ;
51
+ const entries = Array . from ( doc . querySelectorAll ( 'channel > item' ) ) . map (
52
+ entry => {
53
+ const ret = {
54
+ title : entry . querySelector ( 'title' ) ?. textContent ?? '' ,
55
+ published : entry . querySelector ( 'pubDate' ) ?. textContent ,
56
+ updated : entry . querySelector ( 'atom\\:updated' ) ?. textContent ,
57
+ byline :
58
+ entry . querySelector ( 'author' ) ?. textContent ?? feedAuthor ,
59
+ url :
60
+ entry . querySelector ( 'link:not([rel]), link[rel=alternate]' )
61
+ ?. textContent ?? '' ,
62
+ content : entry . querySelector ( 'description' ) ?. textContent ?? ''
63
+ } ;
64
+ if ( isURL ( ret . link ) ) {
65
+ // Resolve relative entry link, TODO: also use xml:base
66
+ ret . link = new URL ( ret . link , feedLink ) . href ;
67
+ }
68
+ if ( ret . updated && ! ret . published ) {
69
+ ret . published = ret . updated ;
70
+ }
71
+ return ret ;
72
+ }
73
+ ) ;
74
+ return entries ;
50
75
}
51
76
52
77
export function isFeed ( doc ) {
0 commit comments