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:
@@ -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 },
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user