implement sitemap.xml (#815)

This commit is contained in:
Madison 2025-08-01 17:15:32 -05:00 committed by GitHub
parent e79ebda8d5
commit 4fd5da2ae8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -0,0 +1,31 @@
import { apiSource, source } from '../../../lib/source';
export const GET = async () => {
const rootUrl = "https://docs.stack-auth.com";
// Get pages from both sources
const docsPages = source.getPages();
const apiPages = apiSource.getPages();
const allPages = [...docsPages, ...apiPages];
const sitemap = `<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
${allPages
.map((page) => {
const url = new URL(page.url, rootUrl);
return ` <url>
<loc>${url.toString()}</loc>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
</url>`;
})
.join("\n")}
</urlset>`;
return new Response(sitemap, {
headers: {
"Content-Type": "application/xml",
"Cache-Control": "public, max-age=3600",
},
});
};