44 lines
1.1 KiB
TypeScript
44 lines
1.1 KiB
TypeScript
import { json } from '@sveltejs/kit';
|
|
import { browseAllPost } from "$lib/content/contentApi";
|
|
|
|
export async function GET() {
|
|
|
|
const allPosts = await browseAllPost();
|
|
|
|
|
|
/** @type {import('@sveltejs/kit').RequestHandler} */
|
|
const createSitemap = () => {
|
|
|
|
let xml = ''
|
|
xml += '<?xml version="1.0" encoding="UTF-8"?>'
|
|
xml += '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'
|
|
|
|
|
|
allPosts.map((_post) => {
|
|
xml += '<url>'
|
|
xml += `<loc>${_post.url}</loc>`
|
|
xml += `<lastmod>${_post.updated_at}</lastmod>`
|
|
xml += `<changefreq>always</changefreq>`
|
|
xml += `<priority>0.5</priority>`
|
|
xml += '</url>'
|
|
});
|
|
|
|
xml += '</urlset>'
|
|
|
|
console.log(`Wrote Sitemap`);
|
|
return xml;
|
|
|
|
}
|
|
const xmlSitemap = createSitemap();
|
|
// Suggestion (check for correctness before using):
|
|
// return json(xml, {
|
|
// headers: {
|
|
// 'access-control-allow-origin': '*'
|
|
// }
|
|
// });
|
|
return new Response(xmlSitemap, {
|
|
headers: {
|
|
'access-control-allow-origin': '*'
|
|
},
|
|
});
|
|
} |