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
|
import { SITE } from '@/consts'
import rss from '@astrojs/rss'
import type { APIContext } from 'astro'
import { getAllEvents, getAllPosts } from '@/lib/data-utils'
export async function GET(context: APIContext) {
try {
const posts = await getAllPosts()
const events = await getAllEvents()
const items = [
...posts.map((post) => ({
title: post.data.title,
description: post.data.description,
pubDate: post.data.date,
link: `/blog/${post.id}/`,
})),
...events.map((event) => ({
title: event.data.title,
description: event.data.description,
pubDate: event.data.date,
link: `/events/${event.id}/`,
}))
]
return rss({
title: SITE.title,
description: SITE.description,
site: context.site ?? SITE.href,
items: items
})
} catch (error) {
console.error('Error generating RSS feed:', error)
return new Response('Error generating RSS feed', { status: 500 })
}
}
|