feat: add sitemap (#9)
This commit is contained in:
parent
cc1fd12bb5
commit
53c26805bf
1 changed files with 23 additions and 0 deletions
23
src/pages/sitemap.xml.ts
Normal file
23
src/pages/sitemap.xml.ts
Normal file
|
@ -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 = `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
|
||||
<url><loc>${context.site}</loc></url>
|
||||
<url><loc>${context.site}services</loc></url>
|
||||
<url><loc>${context.site}cinema</loc></url>`
|
||||
|
||||
notes.forEach(note => {
|
||||
sitemap += `<url><loc>${context.site}notes/${note.slug}</loc></url>`
|
||||
})
|
||||
|
||||
sitemap += '</urlset>'
|
||||
|
||||
const resp = new Response(sitemap)
|
||||
resp.headers.set("Content-Type", "application/xml")
|
||||
return resp
|
||||
}
|
Loading…
Reference in a new issue