import { getCollection } from "astro:content";
const localPages = ["/", "/archive/", "/method/"];
function escapeXml(value: string) {
return value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
}
export async function GET() {
const posts = await getCollection("posts", ({ data }) => data.status === "published");
const urls = [
...localPages.map((path) => ({ loc: new URL(path, "https://blog.k1412.top").href, lastmod: "2026-08-10" })),
...posts.map((post) => ({ loc: post.data.canonicalUrl, lastmod: post.data.updated }))
];
const entries = urls.map(({ loc, lastmod }) => `${escapeXml(loc)}${escapeXml(lastmod)}`).join("");
const xml = `${entries}`;
return new Response(xml, { headers: { "Content-Type": "application/xml; charset=utf-8" } });
}