-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathrss.xml.js
42 lines (36 loc) · 1.1 KB
/
rss.xml.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
import get_posts from '../api/blog/_posts.js';
const months = ',Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec'.split( ',' );
function formatPubdate ( str ) {
const [ y, m, d ] = str.split( '-' );
return `${d} ${months[+m]} ${y}`;
}
const rss = `
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title>Svelte blog</title>
<link>https://v2.svelte.dev/blog</link>
<description>News and information about the magical disappearing UI framework</description>
<image>
<url>https://v2.svelte.dev/favicon.png</url>
<title>Svelte</title>
<link>https://v2.svelte.dev/blog</link>
</image>
${get_posts().map( post => `
<item>
<title>${post.metadata.title}</title>
<link>https://v2.svelte.dev/blog/${post.slug}</link>
<description>${post.metadata.description}</description>
<pubDate>${formatPubdate(post.metadata.pubdate)}</pubDate>
</item>
` )}
</channel>
</rss>
`.replace( />[^\S]+/gm, '>' ).replace( /[^\S]+</gm, '<' ).trim();
export function get(req, res) {
res.set({
'Cache-Control': `max-age=${30 * 60 * 1e3}`,
'Content-Type': 'application/rss+xml'
});
res.end(rss);
}