Skip to content

fix(sitemap): list only self-canonical URLs - #2569

Open
NopeCharon wants to merge 1 commit into
expressjs:mainfrom
NopeCharon:fix/sitemap-canonical-urls
Open

NopeCharon wants to merge 1 commit into
expressjs:mainfrom
NopeCharon:fix/sitemap-canonical-urls

Conversation

@NopeCharon

@NopeCharon NopeCharon commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #2568

The sitemap lists 635 URLs whose rel="canonical" points to a different page. The filter now drops them, so the sitemap matches what the pages declare:

  • /en/, because the English homepage is served at /
  • unversioned copies of default-version docs and API pages, such as /es/guide/routing/
  • other locales' copies of the untranslated blog and API pages, such as /es/5x/api/express/

"Global" pages such as /es/guide/migrating-5/ only exist unversioned, so they stay listed. Redirect stubs are still excluded as before.

The filter moved from astro.config.mjs to src/utils/sitemap.mjs so it can be unit tested. It reuses the versioned sections and global pages from rewrite-localized-links-core.mjs, which now exports them.

Validation

  • New tests/unit/sitemap.test.mjs. One test checks every file in the pages collection, so a new page that isn't marked global in the menu fails instead of silently leaving the sitemap.
  • npm run test:unit passes, and Prettier and ESLint pass on the changed files.
  • I ran the filter over all 1,311 URLs in the live sitemap and compared the result with each page's actual rel="canonical". It keeps 676 and drops 635. No kept page points elsewhere, and no dropped page is its own canonical.
  • The sitemap generated on this PR's Netlify preview has exactly those 676 URLs: none extra and none missing compared with the self-canonical pages on the live site.

The sitemap filter removed redirect stubs but kept pages whose
rel="canonical" points elsewhere: /en/ (served at /), unversioned copies
of default-version docs and API pages, and other locales' copies of the
untranslated blog and API pages. Those made up 635 of the 1,311 URLs in
the published sitemap, contradicting the canonical tags on the pages.

Move the filter to src/utils/sitemap.mjs so it can be unit tested, and
make it follow the same rules as Layout.astro and [...slug].astro. The
versioned sections and "global" pages come from the link-localization
core, so a page marked global in the menu stays listed without further
configuration.

Fixes expressjs#2568

Signed-off-by: NopeCharon <115794254+NopeCharon@users.noreply.github.com>
@NopeCharon
NopeCharon requested a review from a team as a code owner November 6, 2026 14:28
@netlify

netlify Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for expressjscom-preview ready!

Name Link
🔨 Latest commit 0a4f39c
🔍 Latest deploy log https://app.netlify.com/projects/expressjscom-preview/deploys/6aede4150152a38c9c979158
😎 Deploy Preview https://deploy-preview-2569--expressjscom-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 97 (no change from production)
Accessibility: 100 (no change from production)
Best Practices: 100 (no change from production)
SEO: 100 (no change from production)
PWA: 80 (no change from production)
View the detailed breakdown and full score reports
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sitemap lists hundreds of URLs that declare a different canonical

1 participant