Create the first sitemaps

This commit is contained in:
Quinn Hegeman
2026-03-07 20:52:23 +01:00
parent 5ac9285248
commit dc22676254
6 changed files with 396 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
import { getSettings } from "@/content/settings/settings";
import type { APIRoute } from "astro";
import minifyXML from "minify-xml";
export const GET = (async () => {
const settings = await getSettings();
let sitemapIndex: SitemapIndex[] = [
{
url: "/sitemap/pages.xml",
lastModified: new Date()
}
];
if (settings.blog.enabled) {
sitemapIndex.push({
url: "/sitemap/blogs.xml",
lastModified: new Date()
});
};
if (settings.project.enabled) {
sitemapIndex.push({
url: "/sitemap/projects.xml",
lastModified: new Date()
});
};
if (settings.photo.enabled) {
sitemapIndex.push({
url: "/sitemap/photos.xml",
lastModified: new Date()
})
};
let sitemapContent = `
<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
${sitemapIndex.map((item) => `
<sitemap>
<loc>${settings.website.domainName}${item.url}</loc>
<lastmod>${item.lastModified.toISOString()}</lastmod>
</sitemap>
`).join('')}
</sitemapindex>
`;
return new Response(minifyXML(sitemapContent), {
status: 200,
statusText: "OK",
headers: {
"Content-Type": "application/xml"
}
});
}) satisfies APIRoute;