feat: 动态sitemap.xml

This commit is contained in:
2026-08-14 23:55:52 +08:00
parent d7bbb7b70b
commit e4c362030d
9 changed files with 99 additions and 61 deletions

View File

@@ -0,0 +1,33 @@
import type {APIRoute} from 'astro';
import {metadata} from "@/consts";
const site = metadata.site
const staticUrls = [
'',
'/archives',
'/search',
];
export const GET: APIRoute = async () => {
const urls = staticUrls
.filter((url, index, array) => {
return array.indexOf(url) === index;
});
const xml = `<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
${urls.map((url) => `<url>
<loc>${site}${url}</loc>
</url>`
)
.join('\n')}
</urlset>`;
return new Response(xml, {
status: 200,
headers: {
'Content-Type': 'application/xml; charset=utf-8',
'Cache-Control': 'public, max-age=3600, s-maxage=3600',
},
});
};