29 lines
748 B
TypeScript
29 lines
748 B
TypeScript
import meta from "@/const/meta"
|
|
import { getAllPostsMeta } from "@/lib/posts"
|
|
|
|
export async function GET() {
|
|
const posts = getAllPostsMeta()
|
|
const items = posts
|
|
.map(
|
|
(p) => `
|
|
<item>
|
|
<title>${p.title}</title>
|
|
<link>https://yourdomain.com/blog/${p.slug}</link>
|
|
<description>${p.description}</description>
|
|
<pubDate>${new Date(p.date).toUTCString()}</pubDate>
|
|
</item>`,
|
|
)
|
|
.join("")
|
|
|
|
const feed = `<?xml version="1.0" encoding="UTF-8"?>
|
|
<rss version="2.0"><channel>
|
|
<title>${meta.title}</title>
|
|
<link>https://yourdomain.com</link>
|
|
<description>Latest posts</description>
|
|
${items}
|
|
</channel></rss>`
|
|
|
|
return new Response(feed, {
|
|
headers: { "Content-Type": "application/xml" },
|
|
})
|
|
}
|