39 lines
956 B
TypeScript
39 lines
956 B
TypeScript
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 xml = createSitemap();
|
|
return {
|
|
status: 200,
|
|
headers: {
|
|
'access-control-allow-origin': '*'
|
|
},
|
|
body: xml,
|
|
};
|
|
} |