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:
ik
2026-09-10 05:53:36 +07:00
parent 2c7dd27b4f
commit 3ea08fa706
2 changed files with 4 additions and 1 deletions
+1
View File
@@ -3,6 +3,7 @@ import node from "@astrojs/node";
export default defineConfig({ export default defineConfig({
site: process.env.PUBLIC_SITE_URL || "https://rf4spotter.ru", site: process.env.PUBLIC_SITE_URL || "https://rf4spotter.ru",
trailingSlash: "never",
output: "server", output: "server",
adapter: node({ mode: "standalone" }), adapter: node({ mode: "standalone" }),
server: { host: true, port: 4321 }, server: { host: true, port: 4321 },
+3 -1
View File
@@ -24,7 +24,9 @@ export const GET: APIRoute = async ({ site }) => {
if (paths.size > 49000) throw new Error("Sitemap index required"); if (paths.size > 49000) throw new Error("Sitemap index required");
if (rows.length < 1000) break; 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() }; lastGood = { origin, xml, at: Date.now() };
return output(xml); return output(xml);
} catch { } catch {