import { SITE } from '@/consts'
import rss from '@astrojs/rss'
import type { APIContext } from 'astro'
import { getAllPosts } from '@/lib/data-utils'
export async function GET(context: APIContext) {
try {
const posts = await getAllPosts()
return rss({
title: `${SITE.title} - Tech Blog`,
description: SITE.description,
site: context.site ?? SITE.href,
trailingSlash: false,
items: posts.map((post) => ({
title: post.data.title,
description: post.data.description,
pubDate: post.data.date,
link: `/blog/${post.id}/`,
categories: post.data.tags || [],
author: post.data.authors ? post.data.authors.join(', ') : SITE.author,
customData: `
${SITE.locale}
${new Date().toUTCString()}
${post.data.tags ? `${post.data.tags.join(', ')}` : ''}
`.trim(),
})),
customData: `
${SITE.locale}
${new Date().toUTCString()}
60
${new URL('/ogImage.png', SITE.href).toString()}
${SITE.title}
${SITE.href}
`.trim(),
})
} catch (error) {
console.error('Error generating RSS feed:', error)
return new Response('Error generating RSS feed', { status: 500 })
}
}