fix(www): ignore translations whose English page was removed

This commit is contained in:
Jack 2026-10-14 23:27:03 +08:00
parent f05b35146f
commit 3892371b61
2 changed files with 6 additions and 2 deletions

View file

@ -15,6 +15,7 @@
- Translate a page by mirroring its English path under `content/<code>/`, 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 `<code>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.

View file

@ -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`)