Skip to content

Commit d80cac0

Browse files
committed
Add basic support for RSS
1 parent 4c367cb commit d80cac0

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

src/util/feeds.js

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function isAtomFeed(doc) {
88
}
99

1010
function isRssFeed(doc) {
11-
return doc.documentElement.localName === 'channel';
11+
return doc.documentElement.localName === 'rss';
1212
}
1313

1414
function processAtomFeed(doc) {
@@ -40,13 +40,38 @@ function processAtomFeed(doc) {
4040
return ret;
4141
}
4242
);
43-
// console.log(entries);
4443
return entries;
4544
}
4645

4746
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;
5075
}
5176

5277
export function isFeed(doc) {

templates/default.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ <h1 class="article__title">{{ item.title }}</h1>
6262
Published
6363
<time datetime="{{item.published}}">
6464
{{item.published | humandate(true) }} </time
65-
>{%- if item.updated and item.updated !== item.published
66-
-%}, updated
65+
>{% if item.updated and item.updated !== item.published %}
66+
&middot; Updated
6767
<time datetime="{{item.updated}}">
6868
{{item.updated | humandate(true) }}
6969
</time>
70-
{%- endif -%}
70+
{% endif %}
7171
</p>
7272
{% endif %}
7373
<p class="article__url">

0 commit comments

Comments
 (0)