diff --git a/services/www/src/docs/AGENTS.md b/services/www/src/docs/AGENTS.md index 69e3e088232..bba6958e583 100644 --- a/services/www/src/docs/AGENTS.md +++ b/services/www/src/docs/AGENTS.md @@ -15,6 +15,7 @@ - Translate a page by mirroring its English path under `content//`, for example `content/config.mdx` becomes `content/zh/config.mdx`. Untranslated pages fall back to English under the locale URL. - Keep links in translated pages identical to the English page, for example `/config`; the locale segment is added at render time. - Keep the English heading structure in translations: the same headings at the same levels, in the same order. `remark-translated-headings.ts` reuses the English heading IDs so `#anchor` links work in every locale. +- Removing or moving an English page leaves its translations unused but does not break the build; delete or move them in the same change when convenient. - English changes may ship before translations. When an English page's heading structure changes, its translations are treated as outdated: the build warns, and the locale URL serves the English page until the translation is updated. - UI strings follow the website dictionaries: `i18n/en.ts` defines every key, and each locale spreads English and overrides its strings with `satisfies Dict`. Register new locales in `i18n/index.ts`. A locale's `Nav` map translates header and sidebar labels by their English text from `lib/navigation.ts`. - Build all docs links with `docsHref(slug, locale)` or `localizeDocsHref` so readers stay in their language. diff --git a/services/www/src/docs/remark-translated-headings.ts b/services/www/src/docs/remark-translated-headings.ts index b0eed58fda2..6367b876265 100644 --- a/services/www/src/docs/remark-translated-headings.ts +++ b/services/www/src/docs/remark-translated-headings.ts @@ -1,4 +1,4 @@ -import { readFileSync } from "node:fs" +import { existsSync, readFileSync } from "node:fs" import path from "node:path" import { markdownHeadings } from "./lib/headings" @@ -20,8 +20,11 @@ export default function remarkTranslatedHeadings(options: { content: string; loc const relative = path.relative(options.content, file.history[0] ?? "") const [locale, ...rest] = relative.split(path.sep) if (!locale || !options.locales.includes(locale) || rest.length === 0) return + // A translation left behind after its English page was removed or moved is never routed. + const source = path.join(options.content, ...rest) + if (!existsSync(source)) return - const english = markdownHeadings(readFileSync(path.join(options.content, ...rest), "utf8")) + const english = markdownHeadings(readFileSync(source, "utf8")) const headings = collect(tree) if (headings.map((heading) => heading.depth).join() !== english.map((heading) => heading.depth).join()) { console.warn(`[docs] ${relative} is outdated: its headings differ from English, so the English page is served`)