blob: 15fde358c607aaddb9cf0c63112761f976c12d87 (
plain) (
blame)
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
|
import { RSS_ROOT } from '$/lib';
import { RSSChannelElement, RSSItemElement, RSSRootElement } from 'rsstrogen/rss';
import { XMLDeclaration, XMLDocumentRoot } from 'rsstrogen/xml'
import { dev } from '$app/environment';
import posts from '../posts';
export const prerender = true;
export const GET = async (req) => {
const doc = new XMLDocumentRoot().child(
new XMLDeclaration().version().encoding(),
new RSSRootElement()
.channel(
new RSSChannelElement(
'Latest blog posts for 7222e800',
'Some Fancy Description Here',
RSS_ROOT
)
.pubDate(new Date('2026-01-14T15:53:57Z') /* When the last item was published */)
.lastBuildDate(new Date() /* When this file was last updated - usually when your build process last ran */)
.language('en')
.generator()
.items(
...(await Promise.all(Object.values(posts)))
.filter(v => v.metadata.published === true || (dev && req.url.searchParams.has('include-unpublished')))
.map(({ metadata }) => {
const item = new RSSItemElement(`${metadata.published === true ? '' : metadata.published ? '🚧 ' : '🛑 '}${metadata.title}`, metadata.blurb, new URL(`${metadata.id}-${metadata.slug}`, RSS_ROOT));
if (metadata.author)
item.author(metadata.author);
item.pubDate(new Date(metadata.created));
item.guid(new URL(`${metadata.id}`, RSS_ROOT).href, true)
return item;
})
),
)
)
return new Response(doc.toString(), {
headers: {
'Content-Type': 'application/rss+xml;charset=utf-8'
}
})
}
|