Repository navigation
Fix SEO indexing: hreflang, canonicals, sitemap, trailing slash #2193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
a2563d8
9565f22
5dbf4ec
991ecc3
cc1aef4
a5245ca
fe8c44e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import { getTranslations } from "next-intl/server"; | ||
| import { buildAlternates } from "../../../i18n/seo"; | ||
| import { DocsNav } from "./docs-nav"; | ||
| import { SiteHeader } from "../components/site-header"; | ||
|
|
||
|
|
@@ -18,9 +19,7 @@ export async function generateMetadata({ | |
| siteName: "cmux", | ||
| type: "article" as const, | ||
| }, | ||
| alternates: { | ||
| canonical: "./", | ||
| }, | ||
| alternates: buildAlternates(locale, "/docs"), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Setting Useful? React with 👍 / 👎.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The docs layout sets Before this PR the layout used To fully fix this, each docs page's // e.g. getting-started/page.tsx
alternates: buildAlternates(locale, "/docs/getting-started"),The same gap applies to |
||
| }; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import { locales } from "./routing"; | ||
|
|
||
| const BASE = "https://cmux.com"; | ||
|
|
||
| /** | ||
| * Build the full alternates object (canonical + hreflang languages) | ||
| * for a given locale and path. Use in every generateMetadata that | ||
| * sets alternates so child metadata doesn't wipe parent hreflang. | ||
| */ | ||
| export function buildAlternates(locale: string, path: string) { | ||
| const languages: Record<string, string> = {}; | ||
| for (const loc of locales) { | ||
| languages[loc] = | ||
| loc === "en" ? `${BASE}${path}` : `${BASE}/${loc}${path}`; | ||
| } | ||
| languages["x-default"] = `${BASE}${path}`; | ||
|
|
||
| const canonical = | ||
| locale === "en" ? `${BASE}${path}` : `${BASE}/${locale}${path}`; | ||
|
|
||
| return { canonical, languages }; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The blog layout emits
alternates: buildAlternates(locale, "/blog"). Because individual blog post pages do define their ownalternatesthey correctly override this. The/bloglist page will also be correct since it has no page-levelgenerateMetadata. This is fine — just noting it here for contrast with the docs situation above, where sub-pages do not override the layout canonical.