-
Notifications
You must be signed in to change notification settings - Fork 0
/
feed.xml.ts
64 lines (55 loc) · 1.6 KB
/
feed.xml.ts
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
import { createUrl } from "@acdh-oeaw/lib";
import rss, { type RSSFeedItem } from "@astrojs/rss";
import type { APIContext } from "astro";
import { type Locale, locales } from "@/config/i18n.config";
import { createI18n } from "@/lib/i18n";
import { createCollectionResource } from "@/lib/keystatic/resources";
export function getStaticPaths() {
return locales.map((locale) => {
return { params: { locale } };
});
}
export async function GET(context: APIContext) {
const locale = context.params.locale as Locale;
const { t } = await createI18n(locale);
const metadata = t("metadata");
const events = await createCollectionResource("events", locale).all();
const news = await createCollectionResource("news", locale).all();
return rss({
title: metadata.title,
description: metadata.description,
site: context.site!,
/** @see https://docs.astro.build/en/guides/rss/#generating-items */
items: [
...events.map(({ data, id }) => {
const item: RSSFeedItem = {
link: String(
createUrl({
baseUrl: import.meta.env.SITE,
pathname: `/${locale}/events/${id}`,
}),
),
title: data.title,
pubDate: new Date(data.date),
description: data.summary,
};
return item;
}),
...news.map(({ data, id }) => {
const item: RSSFeedItem = {
link: String(
createUrl({
baseUrl: import.meta.env.SITE,
pathname: `/${locale}/news/${id}`,
}),
),
title: data.title,
pubDate: new Date(data.date),
description: data.summary,
};
return item;
}),
],
customData: `<language>${locale}</language>`,
});
}