31 lines
789 B
TypeScript
31 lines
789 B
TypeScript
import { posts } from '$lib/blog/posts';
|
|
import { canonical } from '$lib/config/site';
|
|
|
|
const staticPages = ['/', '/about', '/blog', '/dashboard'];
|
|
|
|
export const GET = () => {
|
|
const urls = [
|
|
...staticPages.map((path) => ({ loc: canonical(path), lastmod: undefined })),
|
|
...posts.map((post) => ({ loc: canonical(`/blog/${post.slug}`), lastmod: post.date }))
|
|
];
|
|
|
|
const body = `<?xml version="1.0" encoding="UTF-8"?>
|
|
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
${urls
|
|
.map(
|
|
(url) => ` <url>
|
|
<loc>${url.loc}</loc>${url.lastmod ? `\n <lastmod>${url.lastmod}</lastmod>` : ''}
|
|
</url>`
|
|
)
|
|
.join('\n')}
|
|
</urlset>
|
|
`;
|
|
|
|
return new Response(body, {
|
|
headers: {
|
|
'content-type': 'application/xml; charset=utf-8',
|
|
'cache-control': 'public, max-age=3600'
|
|
}
|
|
});
|
|
};
|