File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments