fix: sitemap

This commit is contained in:
Torsten Dittmann
2025-02-24 13:20:28 +04:00
parent fb3e4a26ed
commit d4e1a98f14
2 changed files with 26 additions and 9 deletions

1
.gitignore vendored
View File

@@ -3,6 +3,7 @@ node_modules
/build
/.svelte-kit
/.idea
/.zed
/package
.env
.env.*

View File

@@ -6,17 +6,33 @@ import { defineEventHandler, setResponseHeader } from 'h3';
*/
export async function sitemap() {
console.info('Preparing Sitemap...');
const manifest = await import('../build/server/manifest.js');
const prerendered = manifest.prerendered;
const file_route_extensions = ['.json', '.xml'];
const routes = [...prerendered, ...collectThreads()].filter(
(route) => !file_route_extensions.some((ext) => route.endsWith(ext))
const { manifest } = await import('../build/server/manifest.js');
const sveltekit_routes = manifest._.routes
.filter((route) => route.params.length === 0)
.map((route) => route.id);
const threads = collectThreads();
const all_routes = [...sveltekit_routes, ...threads];
const document_routes = all_routes.filter(
(route) => !['.json', '.xml'].some((ext) => route.endsWith(ext))
);
const routes = new Set(document_routes);
console.info(`Sitemap loaded with ${routes.length} routes!`);
console.group();
console.info(`sveltekit: ${sveltekit_routes.length}`);
console.info(`threads: ${threads.length}`);
console.groupEnd();
const sitemap = `<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
${routes
const sitemap = `
<?xml version="1.0" encoding="UTF-8" ?>
<urlset
xmlns="https://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xhtml="https://www.w3.org/1999/xhtml"
xmlns:mobile="https://www.google.com/schemas/sitemap-mobile/1.0"
xmlns:news="https://www.google.com/schemas/sitemap-news/0.9"
xmlns:image="https://www.google.com/schemas/sitemap-image/1.1"
xmlns:video="https://www.google.com/schemas/sitemap-video/1.1"
>
${[...routes]
.map(
(route) => `<url>
<loc>https://appwrite.io${route}</loc>
@@ -24,7 +40,7 @@ export async function sitemap() {
`
)
.join('')}
</urlset>`;
</urlset>`.trim();
return defineEventHandler((event) => {
setResponseHeader(event, 'Content-Type', 'application/xml');