import { getPosts } from '$lib/posts';
import siteMetadata from '$content/metadata.json';
import type { Post } from '$lib/types'
export const prerender = true;
export async function GET() {
const posts: Post[] = await getPosts();
const headers = { 'Content-Type': 'application/xml' }
const description = siteMetadata?.description
? `${siteMetadata?.description || ""}`
: "";
const url = siteMetadata?.url || "";
const urlXml = siteMetadata?.url ? `
${url}
` : "";
const xml = `
${siteMetadata.blogName}
${description}
${urlXml}
${posts
.map(
(post) => `
-
${post.title}
${post.description}
${url}/post/${post.slug}
${url}/post/${post.slug}
${new Date(post.date).toUTCString()}
`
)
.join('')}
`.trim()
return new Response(xml, { headers })
}