From 53c26805bfabb229636a6cf40febdc4da804eca5 Mon Sep 17 00:00:00 2001 From: Ivan Reshetnikov Date: Tue, 27 Feb 2024 22:45:45 +0500 Subject: [PATCH] feat: add sitemap (#9) --- src/pages/sitemap.xml.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/pages/sitemap.xml.ts diff --git a/src/pages/sitemap.xml.ts b/src/pages/sitemap.xml.ts new file mode 100644 index 0000000..e86cf4e --- /dev/null +++ b/src/pages/sitemap.xml.ts @@ -0,0 +1,23 @@ +import type { APIContext } from 'astro' +import { getCollection } from 'astro:content' + + +export async function GET(context: APIContext) { + const notes = await getCollection('notes') + + let sitemap = ` + + ${context.site} + ${context.site}services + ${context.site}cinema` + + notes.forEach(note => { + sitemap += `${context.site}notes/${note.slug}` + }) + + sitemap += '' + + const resp = new Response(sitemap) + resp.headers.set("Content-Type", "application/xml") + return resp +}