import { defaultLocale, getLocalizedPagePath, sitemapPages, supportedLocales } from "~/data/i18n"; import { screenshots } from "~/data/screenshots"; 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").replace(/\/+$/, ""); const toSiteUrl = (path: string) => `${siteUrl}${path === "/" ? "/" : `/${path.replace(/^\/+/, "")}`}`; const ogImagePath = "og-image-agent-teams-v6.png"; const homeImagePaths = [ogImagePath, ...screenshots.map((screenshot) => screenshot.path)]; const downloadImagePaths = [ogImagePath, "logo-192.png"]; setHeader(event, "content-type", "application/xml; charset=utf-8"); const entries = sitemapPages.flatMap((page) => supportedLocales.map((locale) => ({ path: getLocalizedPagePath(page, locale.code), page })) ); const body = ` ${entries .map( ({ path, page }) => { const alternates = supportedLocales .map((locale) => { const href = toSiteUrl(getLocalizedPagePath(page, locale.code)); return ` `; }) .join("\n"); const imagePaths = page === "/" ? homeImagePaths : downloadImagePaths; const images = imagePaths .map((imagePath) => ` \n ${escapeXml(toSiteUrl(imagePath))}\n `) .join("\n"); const defaultHref = toSiteUrl(getLocalizedPagePath(page, defaultLocale)); return ` \n ${escapeXml(toSiteUrl(path))}\n${alternates}\n \n${images}\n ${buildDate}\n `; } ) .join("\n")} `; return body; });