Skip to content

Commit 11b109b

Browse files
committed
release sitemap
1 parent 532741f commit 11b109b

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

src/pages/sitemap.xml.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { getCollection } from 'astro:content';
2+
3+
export async function GET() {
4+
const posts = await getCollection('blog');
5+
const pages = await getCollection('pages');
6+
7+
const sitemapXml = `<?xml version="1.0" encoding="UTF-8"?>
8+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
9+
<url>
10+
<loc>https://blockchain-dresden.de/</loc>
11+
<lastmod>${new Date().toISOString()}</lastmod>
12+
<changefreq>daily</changefreq>
13+
<priority>1.0</priority>
14+
</url>
15+
${posts
16+
.map(
17+
(post) => `
18+
<url>
19+
<loc>https://blockchain-dresden.de/blog/${post.slug}</loc>
20+
<lastmod>${post.data.pubDate ? new Date(post.data.pubDate).toISOString() : new Date().toISOString()}</lastmod>
21+
<changefreq>weekly</changefreq>
22+
<priority>0.7</priority>
23+
</url>`
24+
)
25+
.join('')}
26+
${pages
27+
.map(
28+
(page) => `
29+
<url>
30+
<loc>https://blockchain-dresden.de/${page.slug}</loc>
31+
<lastmod>${new Date().toISOString()}</lastmod>
32+
<changefreq>monthly</changefreq>
33+
<priority>0.5</priority>
34+
</url>`
35+
)
36+
.join('')}
37+
</urlset>`;
38+
39+
return new Response(sitemapXml, {
40+
headers: {
41+
'Content-Type': 'application/xml',
42+
'Cache-Control': 'public, max-age=3600',
43+
},
44+
});
45+
}

0 commit comments

Comments
 (0)