how would you clean my sitemap up:
function formatDate(date: Date) {
return date.getFullYear() + '-' +
String(date.getMonth() + 1).padStart(2, '0') + '-' +
String(date.getDate()).padStart(2, '0') + 'T' +
String(date.getHours()).padStart(2, '0') + ':' +
String(date.getMinutes()).padStart(2, '0') + ':' +
String(date.getSeconds()).padStart(2, '0') +
'+03:00';
}
export async function GET() {
const siteUrl = import.meta.env.SITE;
const posts = await getCollection('posts');
const hubs = await getCollection('hubs');
const renderedPosts = await Promise.all(posts.map(async post => await render(post)));
const renderedHubs = await Promise.all(hubs.map(async hub => await render(hub)));
const result = `
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
<url><loc>${siteUrl}/</loc></url>
${posts
.map((post, index) => {
const date = new Date(renderedPosts[index].remarkPluginFrontmatter.lastModified);
return `<url><loc>${siteUrl}/${post.id}</loc><lastmod>${formatDate(date)}</lastmod></url>`;
})
.join('\n')}
${hubs
.map((hub, index) => {
const date = new Date(renderedHubs[index].remarkPluginFrontmatter.lastModified);
return `<url><loc>${siteUrl}/${hub.id}</loc><lastmod>${formatDate(date)}</lastmod></url>`;
})
.join('\n')}
</urlset>
`.trim();
return new Response(result, {
headers: {
'Content-Type': 'application/xml',
},
});
}```