import { SITE, authors, categories, sortedPosts, tags } from "../lib/blog-data.js";
const BASE_URL = SITE.url || "";
export async function GET() {
const posts = await sortedPosts();
const entries = [
{ path: "/", changefreq: "weekly", priority: "1.0" },
{ path: "/blog", changefreq: "daily", priority: "0.9" },
{ path: "/about", changefreq: "monthly", priority: "0.6" },
{ path: "/contact", changefreq: "monthly", priority: "0.5" },
...posts.map((post) => ({
path: `/blog/${post.slug}`,
lastmod: post.updated || post.date,
changefreq: "monthly",
priority: "0.8",
})),
...categories.map((category) => ({
path: `/categories/${category.slug}`,
changefreq: "weekly",
priority: "0.6",
})),
...tags.map((tag) => ({
path: `/tags/${tag.slug}`,
changefreq: "weekly",
priority: "0.4",
})),
...authors.map((author) => ({
path: `/authors/${author.slug}`,
changefreq: "monthly",
priority: "0.5",
})),
];
const urls = entries.map((entry) =>
[
" ",
` ${BASE_URL}${entry.path}`,
entry.lastmod ? ` ${entry.lastmod}` : null,
entry.changefreq ? ` ${entry.changefreq}` : null,
entry.priority ? ` ${entry.priority}` : null,
" ",
]
.filter(Boolean)
.join("\n"),
);
const xml = [
'',
'',
...urls,
"",
].join("\n");
return new Response(xml, {
headers: {
"Content-Type": "application/xml",
"Cache-Control": "public, max-age=3600",
},
});
}