fix/seo: Emit a per-page canonical URL - #2001
Draft
marcleblanc2 wants to merge 1 commit into
Draft
marcleblanc2 wants to merge 1 commit into
marcleblanc2 wants to merge 1 commit into
Conversation
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>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
generateMetadatainsrc/app/[...slug]/page.tsxsetsalternates.canonicalto/docs${post.url};metadataBaseinsrc/app/layout.tsxresolves it to an absolute URL. The landing page keeps/docs.Verification
npx tsc --noEmitclean. Check the preview:curl -s <preview>/docs/cody | grep canonicalshould 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.