-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
ActivityFeed.js
65 lines (56 loc) · 1.66 KB
/
ActivityFeed.js
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { Importer } from "@11ty/import";
import pluginRss from "@11ty/eleventy-plugin-rss";
class ActivityFeed {
#importer;
get importer() {
if(!this.#importer) {
this.#importer = new Importer();
this.#importer.setDryRun(true);
this.#importer.setAssetReferenceType("disabled");
// TODO make this an option
this.#importer.setVerbose(false); // --quiet
}
return this.#importer;
}
setCacheDuration(duration) {
this.importer.setCacheDuration(duration);
}
addSource(type, label, identifier) {
this.importer.addSource(type, {
url: identifier,
label,
});
}
async getEntries() {
return this.importer.getEntries({
contentType: "html",
});
}
async toRssFeed(metadata = {}) {
let entries = await this.getEntries();
let url = metadata.url?.home || metadata.url;
let feedUrl = metadata.url?.feed || url;
return `<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xml:base="${url}" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>${metadata.title}</title>
<link>${url}</link>
<atom:link href="${feedUrl}" rel="self" type="application/rss+xml" />
<description>${metadata.subtitle}</description>
<language>${metadata.language}</language>
${entries.map(entry => {
return `
<item>
<title>${entry.sourceLabel}: ${entry.title}</title>
<link>${entry.url}</link>
<description><![CDATA[${entry.content || ""}]]></description>
<pubDate>${pluginRss.dateToRfc822(entry.date)}</pubDate>
${entry.authors.map(author => ` <dc:creator>${author.name}</dc:creator>\n`)}
<guid>${entry.url}</guid>
</item>`;
}).join("\n")}
</channel>
</rss>`
}
}
export {ActivityFeed};