-
Notifications
You must be signed in to change notification settings - Fork 1
/
rss.mjs
44 lines (38 loc) · 1.1 KB
/
rss.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import url from 'url';
const URL = url.URL;
import RSS from 'rss';
class RSSFeed {
constructor(feedUrl) {
this.feedUrl = feedUrl;
}
create(posts) {
const siteOrigin = 'https://ericbidelman.com';
const feed = new RSS({
/* eslint-disable camelcase */
title: 'Eric Bidelman',
description: 'Posts from Eric Bidelman',
feed_url: this.feedUrl,
site_url: siteOrigin,
image_url: `${siteOrigin}/img/icon_400x400.png`,
pubDate: new Date(),
ttl: 180,// mins for feed to be cached.
// custom_namespaces: {
// content: 'http://purl.org/rss/1.0/modules/content/'
// }
});
posts.forEach(post => {
const url = post.href.startsWith('http') ? post.href : `${siteOrigin}${post.href}`;
feed.item({
title: post.data.title,
description: post.excerpt,
author: 'Eric Bidelman',
url,
date: post.data.published,
//custom_elements: [{'content:encoded': JSON.stringify(pwa)}]
});
});
/* eslint-enable camelcase */
return feed.xml({indent: true});
}
}
export default RSSFeed;