-
-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy path+server.ts
More file actions
42 lines (37 loc) · 1.12 KB
/
+server.ts
File metadata and controls
42 lines (37 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import * as config from '$lib/config'
import type { Post } from '$lib/types'
export const prerender = true
export async function GET({ fetch }) {
const response = await fetch('api/posts')
const posts: Post[] = await response.json()
const website = config.url
const headers = { 'Content-Type': 'application/xml' }
const xml = `
<?xml version="1.0" encoding="UTF-8" ?>
<urlset
xmlns="https://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:news="https://www.google.com/schemas/sitemap-news/0.9"
xmlns:xhtml="https://www.w3.org/1999/xhtml"
xmlns:mobile="https://www.google.com/schemas/sitemap-mobile/1.0"
xmlns:image="https://www.google.com/schemas/sitemap-image/1.1"
xmlns:video="https://www.google.com/schemas/sitemap-video/1.1"
>
<url>
<loc>${website}</loc>
<changefreq>daily</changefreq>
<priority>0.7</priority>
</url>
${posts
.map(
(post) =>
`<url>
<loc>${website}/${post.slug}</loc>
<changefreq>daily</changefreq>
<priority>0.7</priority>
</url>`
)
.join('')}
</urlset>
`.trim()
return new Response(xml, { headers })
}