diff --git a/src/routes/sitemap.xml/+server.ts b/src/routes/sitemap.xml/+server.ts new file mode 100644 index 0000000..0d4e24f --- /dev/null +++ b/src/routes/sitemap.xml/+server.ts @@ -0,0 +1,41 @@ +import { SITE_URL } from '$lib/site-config'; + +/** @type {import('@sveltejs/kit').RequestHandler} */ +export async function GET() { + const pages = ['projects', 'toolbox']; + const body = sitemap(pages); + + return new Response(body, { + headers: { + 'Cache-Control': `public, max-age=${86400}`, // 24 hours + 'Content-Type': 'application/xml' + } + }); +} + +const sitemap = (pages: string[]) => ` + + + ${SITE_URL} + daily + 0.7 + + ${pages + .map( + (page) => ` + + ${SITE_URL}/${page} + daily + 0.7 + + ` + ) + .join('')} + `;