Skip to content

Commit b62c99f

Browse files
authored
fix(docs): derive the sitemap's static-page locales from the pages that own the copy (#195)
Fixes #173 sitemap.ts restated the locale surface of privacy and terms as a hand-maintained constant. Correct today, and silently wrong the moment a key is added to either page's content record: the translation would exist, be reachable, render — and never be advertised, with no gate failing. It was the one hand-maintained thing left in a file #169 otherwise made fully derived. Each route module now exports the keys of its own content record, and sitemap.ts reads the two of them separately rather than restating the pair. Read separately because they are separate records: they agree today and nothing makes them have to, which the old shared constant could not express. Derived from content rather than from i18n.languages because the renderer still serves English for any other locale, and that fallback is not a translation and must not be advertised as one. The advertised set does not move: 346 entries before and after, with the sorted url entries hashing to a57adad5 on both trees. Raw bytes differ because entry order is not reproducible — pre-existing, measured with two builds of an untouched tree, filed as #194. Derivation exercised rather than assumed: adding a ja key to privacy's record alone, with sitemap.ts untouched, advertises /ja/privacy and leaves terms at two. Probe reverted and the revert proven on disk.
1 parent d6355de commit b62c99f

3 files changed

Lines changed: 44 additions & 12 deletions

File tree

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,22 @@ const content = {
5151
},
5252
};
5353

54+
/**
55+
* The locales this page is actually written in: the keys of the `content`
56+
* record above, which is where this page's copy lives.
57+
*
58+
* `app/sitemap.ts` reads this rather than restating the pair, so a translation
59+
* added to `content` is advertised to crawlers by that edit alone. The renderer
60+
* below still serves English for any other locale, but that fallback is not a
61+
* translation and must not be advertised as one — which is why this is derived
62+
* from `content`, not from `i18n.languages`.
63+
*
64+
* A named export next to a page's default is valid App Router: Next's generated
65+
* route validator (`.next/types/validator.ts`) constrains the *known* page
66+
* exports and ignores additional ones.
67+
*/
68+
export const contentLocales = Object.keys(content);
69+
5470
export default async function PrivacyPage({
5571
params,
5672
}: {

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,22 @@ const content = {
5959
},
6060
};
6161

62+
/**
63+
* The locales this page is actually written in: the keys of the `content`
64+
* record above, which is where this page's copy lives.
65+
*
66+
* `app/sitemap.ts` reads this rather than restating the pair, so a translation
67+
* added to `content` is advertised to crawlers by that edit alone. The renderer
68+
* below still serves English for any other locale, but that fallback is not a
69+
* translation and must not be advertised as one — which is why this is derived
70+
* from `content`, not from `i18n.languages`.
71+
*
72+
* A named export next to a page's default is valid App Router: Next's generated
73+
* route validator (`.next/types/validator.ts`) constrains the *known* page
74+
* exports and ignores additional ones.
75+
*/
76+
export const contentLocales = Object.keys(content);
77+
6278
export default async function TermsPage({
6379
params,
6480
}: {

‎apps/docs/app/sitemap.ts‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,11 @@ import type { MetadataRoute } from 'next';
22
import { source } from '@/lib/source';
33
import { i18n } from '@/lib/i18n';
44
import { languageAlternates, localeUrl, translatedLocales } from '@/lib/seo';
5+
import { contentLocales as privacyLocales } from './[lang]/privacy/page';
6+
import { contentLocales as termsLocales } from './[lang]/terms/page';
57

68
export const revalidate = false;
79

8-
/**
9-
* Locales in which `privacy` and `terms` are actually written. Those two pages
10-
* carry their copy in a `content` record inside their own route component
11-
* (`app/[lang]/privacy/page.tsx`, `app/[lang]/terms/page.tsx`), which falls back
12-
* to English (`content[lang] ?? content.en`) for anything not listed there —
13-
* the same fallback-shaped defect the docs pages have. Keep this in sync with
14-
* those two records.
15-
*/
16-
const STATIC_PAGE_LOCALES = ['en', 'zh-Hans'];
17-
1810
export default function sitemap(): MetadataRoute.Sitemap {
1911
const entries: MetadataRoute.Sitemap = [];
2012

@@ -23,8 +15,16 @@ export default function sitemap(): MetadataRoute.Sitemap {
2315
// The root exists in every locale: it is a language dispatch page that
2416
// redirects to that locale's /docs.
2517
{ path: '', priority: 1, locales: i18n.languages },
26-
{ path: 'privacy', priority: 0.3, locales: STATIC_PAGE_LOCALES },
27-
{ path: 'terms', priority: 0.3, locales: STATIC_PAGE_LOCALES },
18+
// `privacy` and `terms` carry their copy in a `content` record inside their
19+
// own route component, and render `content[lang] ?? content.en` for every
20+
// other locale — the same fallback shape the docs pages had. So the locales
21+
// they can honestly advertise are the keys of those records, and each module
22+
// exports its own: this file derives the set instead of restating it, and a
23+
// translation added to either record reaches the sitemap by that edit alone.
24+
// Read separately because they are separate records — they agree today, and
25+
// nothing makes them have to.
26+
{ path: 'privacy', priority: 0.3, locales: privacyLocales },
27+
{ path: 'terms', priority: 0.3, locales: termsLocales },
2828
];
2929

3030
// Documentation pages. `source.getPages()` with no argument returns every

0 commit comments

Comments
 (0)