Skip to content

fix/seo: Emit a per-page canonical URL - #2001

Draft
marcleblanc2 wants to merge 1 commit into
mainfrom
marc/fix/per-page-canonical
Draft

marcleblanc2 wants to merge 1 commit into
mainfrom
marc/fix/per-page-canonical

Conversation

@marcleblanc2

Copy link
Copy Markdown
Contributor

Problem

Every docs page ships <link rel="canonical" href="https://sourcegraph.com/docs"> (the root layout's canonical), so search engines are told all 500+ pages are duplicates of the landing page.

Fix

generateMetadata in src/app/[...slug]/page.tsx sets alternates.canonical to /docs${post.url}; metadataBase in src/app/layout.tsx resolves it to an absolute URL. The landing page keeps /docs.

Verification

npx tsc --noEmit clean. Check the preview: curl -s <preview>/docs/cody | grep canonical should show .../docs/cody.

Related: #1977 fixes basePath on images but leaves the canonical site-wide.

Found by the docs site audit in this Amp thread; rebuilt locally in this one.

Every docs page shipped <link rel=canonical href=https://sourcegraph.com/docs>,
so search engines treat all 500+ pages as duplicates of the landing page.
generateMetadata now sets alternates.canonical to the page's own path;
metadataBase in layout.tsx resolves it to an absolute URL.

Found by the docs site audit in
https://ampcode.com/threads/T-01a0ae50-f7f0-779c-aa66-3887c9953e33

Amp-Thread-ID: https://ampcode.com/threads/T-01a0aed2-5fbe-7768-85ea-1378bf98f9ff
Co-authored-by: Amp <amp@ampcode.com>
@vercel

vercel Bot commented Sep 17, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
sourcegraph-docs Ready Ready Preview Sep 17, 2026 10:43am UTC

Request Review

@github-actions

Copy link
Copy Markdown
Contributor

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.

1 participant