Skip to content

Commit d0ee357

Browse files
authored
fix(docs): emit the locale-independent .mdx URL from the docs page (#211)
The Copy Markdown button and the Open popover derived their target as page.url plus .mdx. On a locale-prefixed route page.url carries the prefix, and next.config.mjs rewrites exactly one shape, so every prefixed variant fell through to the docs route and 404'd -- roughly 400 dead links across 79 pages and six locales. The target now derives from page.slugs and is bound once, so both controls take the same value and a future third inherits it rather than re-deriving from page.url. The prefix is dropped rather than the rewrite widened because /llms.mdx is English-only by construction: its handler calls source.getPage(slug) with no language argument, so a locale-prefixed rewrite could not deliver translated markdown. Verified across all 553 page renders: 79 distinct targets, 0 locale-prefixed, 0 English targets moved, 0 non-200. next.config.mjs untouched. A third consumer -- llms.txt advertising a rule composition that 404s -- is filed as #210, not fixed here. Closes #207
1 parent ffe36c5 commit d0ee357

1 file changed

Lines changed: 47 additions & 2 deletions

File tree

  • apps/docs/app/[lang]/docs/[[...slug]]

‎apps/docs/app/[lang]/docs/[[...slug]]/page.tsx‎

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,42 @@ function docsPath(slugs: string[]): string {
2929
return ['docs', ...slugs].join('/');
3030
}
3131

32+
/**
33+
* Site-relative URL of a page's Markdown form, and deliberately the
34+
* locale-independent one — `/docs/architecture.mdx` on every locale route, not
35+
* `/zh-Hans/docs/architecture.mdx`.
36+
*
37+
* Built from `page.slugs` rather than from `page.url` because `page.url`
38+
* carries whatever locale prefix the route was resolved under, and the `.mdx`
39+
* surface has no prefixed form to point at. `next.config.mjs` rewrites exactly
40+
* one shape, `/docs/:path*.mdx` to `/llms.mdx/docs/:path*`; a prefixed URL
41+
* matches no rewrite, falls through to this route with `architecture.mdx` as a
42+
* slug, and is answered by `/_not-found` under `dynamicParams = false`. That was
43+
* six of seven locales on all 79 pages — roughly 400 rendered links, every one
44+
* of them 404, and only ever on the locales an English-speaking maintainer does
45+
* not click.
46+
*
47+
* The prefix is dropped rather than the rewrite widened, and that is a
48+
* conformance decision rather than the cheaper of two repairs. The
49+
* machine-facing markdown surface here is English-only by AGENTS.md rule 1, the
50+
* same pin `llms.txt` and `llms-full.txt` carry, and `check-locale-surface.mjs`
51+
* fails the build if either drifts off it. `/llms.mdx/docs/[[...slug]]` is
52+
* English-only by construction too — its handler calls `source.getPage(slug)`
53+
* with no language, so the default language is the only thing it can serve, and
54+
* it prerenders 79 bodies rather than 553. Adding a `/:lang/docs/:path*.mdx`
55+
* rewrite would therefore not deliver translated markdown; it would either
56+
* serve English from a URL claiming a locale, or turn `/llms.mdx` into a
57+
* locale-aware surface and put it out of step with the two `llms` files beside
58+
* it. Reversing that policy is a decision about the whole markdown surface, not
59+
* a 404 fix.
60+
*
61+
* Byte-identical to the previous expression on the default locale, where
62+
* `page.url` has no prefix to carry: the English link target does not move.
63+
*/
64+
function markdownUrl(page: DocsPageData): string {
65+
return `/${docsPath(page.slugs)}.mdx`;
66+
}
67+
3268
/**
3369
* The string the `<title>` tag should carry. A page may declare `seoTitle` when
3470
* its H1 noun is too short to match anything a reader would search for; most
@@ -206,6 +242,15 @@ export default async function Page(props: {
206242

207243
const MDX = page.data.body;
208244

245+
// Resolved once and handed to both controls, so they cannot drift apart and
246+
// so a third control added below inherits the locale-independent URL instead
247+
// of re-deriving one from `page.url`. That re-derivation is the whole defect:
248+
// it is invisible in the rendered markup — `markdownUrl` reaches the browser
249+
// only as a client-component prop in the RSC payload — so a broken value
250+
// produces no build error, no console warning and no failing gate, and shows
251+
// up only when a reader clicks.
252+
const pageMarkdownUrl = markdownUrl(page);
253+
209254
// The locale this page's content really lives in — `params.lang` for a real
210255
// translation, English for a fumadocs fallback. `url` and `inLanguage` are
211256
// properties of one `TechArticle` node, so they resolve together: a node that
@@ -242,9 +287,9 @@ export default async function Page(props: {
242287
<DocsTitle>{page.data.title}</DocsTitle>
243288
<DocsDescription className="mb-0">{page.data.description}</DocsDescription>
244289
<div className="flex flex-row gap-2 items-center border-b pb-6">
245-
<LLMCopyButton markdownUrl={`${page.url}.mdx`} />
290+
<LLMCopyButton markdownUrl={pageMarkdownUrl} />
246291
<ViewOptions
247-
markdownUrl={`${page.url}.mdx`}
292+
markdownUrl={pageMarkdownUrl}
248293
githubUrl={`https://github.com/${gitConfig.user}/${gitConfig.repo}/blob/${gitConfig.branch}/content/docs/${page.path}`}
249294
/>
250295
</div>

0 commit comments

Comments
 (0)