S03: Consistent site origin — trailingSlash never, canonical URLs
- Add trailingSlash: 'never' to Astro config - Normalize sitemap paths to never use trailing slash - Ensures consistent canonical URLs across all pages - Prevents duplicate content from / vs /path/ variants
This commit is contained in:
@@ -24,7 +24,9 @@ export const GET: APIRoute = async ({ site }) => {
|
||||
if (paths.size > 49000) throw new Error("Sitemap index required");
|
||||
if (rows.length < 1000) break;
|
||||
}
|
||||
const xml = `<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">${[...paths].map(path => `<url><loc>${escapeXml(new URL(path, origin).toString())}</loc></url>`).join("")}</urlset>`;
|
||||
// Normalize paths: never use trailing slash (S03)
|
||||
const normalized = [...paths].map(p => p.replace(/\/$/, "") || "/");
|
||||
const xml = `<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">${normalized.map(path => `<url><loc>${escapeXml(new URL(path, origin).toString())}</loc></url>`).join("")}</urlset>`;
|
||||
lastGood = { origin, xml, at: Date.now() };
|
||||
return output(xml);
|
||||
} catch {
|
||||
|
||||
Reference in New Issue
Block a user