32 lines
921 B
TypeScript
32 lines
921 B
TypeScript
import { generateSitemapRoutes } from "~/data/i18n";
|
|
|
|
const escapeXml = (value: string) =>
|
|
value
|
|
.replaceAll("&", "&")
|
|
.replaceAll("<", "<")
|
|
.replaceAll(">", ">")
|
|
.replaceAll('"', """)
|
|
.replaceAll("'", "'");
|
|
|
|
const buildDate = new Date().toISOString().split("T")[0];
|
|
|
|
export default defineEventHandler((event) => {
|
|
const config = useRuntimeConfig();
|
|
const siteUrl = (config.public.siteUrl as string) || "https://777genius.github.io/agent-teams-ai";
|
|
|
|
setHeader(event, "content-type", "application/xml; charset=utf-8");
|
|
|
|
const routes = generateSitemapRoutes();
|
|
const body = `<?xml version="1.0" encoding="UTF-8"?>
|
|
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
${routes
|
|
.map(
|
|
(path) =>
|
|
` <url>\n <loc>${escapeXml(`${siteUrl}${path}`)}</loc>\n <lastmod>${buildDate}</lastmod>\n </url>`
|
|
)
|
|
.join("\n")}
|
|
</urlset>
|
|
`;
|
|
|
|
return body;
|
|
});
|