@@ -8,7 +8,7 @@ function isAtomFeed(doc) {
88}
99
1010function isRssFeed ( doc ) {
11- return doc . documentElement . localName === 'channel ' ;
11+ return doc . documentElement . localName === 'rss ' ;
1212}
1313
1414function processAtomFeed ( doc ) {
@@ -40,13 +40,38 @@ function processAtomFeed(doc) {
4040 return ret ;
4141 }
4242 ) ;
43- // console.log(entries);
4443 return entries ;
4544}
4645
4746function 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 ;
5075}
5176
5277export function isFeed ( doc ) {
0 commit comments