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
export const dataToRSS = function (data: Item[], settings: Setting) {
let { title, link, description, rssLink } = settings;
let rss = [
`<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>${title || ""}</title>
<description>${description || ""}</description>
<link>${link || ""}</link>
<atom:link href="${rssLink}" rel="self" type="application/rss+xml" />`,
];
data.forEach((item) => {
rss.push(`
<item>
<title>${item.title}</title>
<description>${item.description}</description>
<link>${item.link}</link>
<guid>${item.link}</guid>
<pubDate>${new Date(item.pubDate).toUTCString()}</pubDate>
</item>`);
});
rss.push(`</channel>
</rss>`);
return rss.join("");
};
interface Item {
title?: string;
description?: string;
link?: string;
pubDate?: string | Date;
}
interface Setting {
title: string;
description?: string;
link?: string;
rssLink: string;
}
// forked from @Glench.dataToRSS & @joshmock.dataToRSS
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
October 23, 2023