fix(docs): keep source dirs in i18n route index

This commit is contained in:
Peter Steinberger 2026-04-23 07:15:32 +01:00
parent 3ccaa1b2f1
commit 5bd8254f61
No known key found for this signature in database
2 changed files with 44 additions and 0 deletions

View file

@ -136,6 +136,9 @@ func discoverLocalePrefixes(docsRoot string) (map[string]struct{}, error) {
if !localeDirRe.MatchString(name) {
continue
}
if _, err := os.Stat(filepath.Join(docsRoot, name, ".i18n", "README.md")); err != nil {
continue
}
locales[name] = struct{}{}
}
return locales, nil

View file

@ -112,6 +112,47 @@ func TestPostprocessLocalizedDocsRewritesPublishedPageLinksForEachLocale(t *test
}
}
func TestPostprocessLocalizedDocsDoesNotTreatThreeLetterSourceDirsAsLocales(t *testing.T) {
t.Parallel()
docsRoot := t.TempDir()
writeFile(t, filepath.Join(docsRoot, "docs.json"), `{"redirects":[]}`)
writeFile(t, filepath.Join(docsRoot, "cli", "index.md"), "# CLI\n")
writeFile(t, filepath.Join(docsRoot, "cli", "AGENTS.md"), "# CLI docs guide\n")
writeFile(t, filepath.Join(docsRoot, "web", "index.md"), "# Web\n")
writeFile(t, filepath.Join(docsRoot, "zh-CN", "AGENTS.md"), "# zh-CN\n")
writeFile(t, filepath.Join(docsRoot, "zh-CN", ".i18n", "README.md"), "# zh-CN i18n\n")
writeFile(t, filepath.Join(docsRoot, "zh-CN", "cli", "index.md"), "# CLI 本地化\n")
writeFile(t, filepath.Join(docsRoot, "zh-CN", "web", "index.md"), "# Web 本地化\n")
pagePath := filepath.Join(docsRoot, "zh-CN", "gateway", "index.md")
writeFile(t, pagePath, stringsJoin(
"---",
"title: 网关",
"x-i18n:",
" source_hash: test",
"---",
"",
"See [CLI](/cli).",
"",
"See [Web](/web).",
))
if err := postprocessLocalizedDocs(docsRoot, "zh-CN", []string{pagePath}); err != nil {
t.Fatalf("postprocessLocalizedDocs failed: %v", err)
}
got := mustReadFile(t, pagePath)
for _, want := range []string{
"See [CLI](/zh-CN/cli).",
"See [Web](/zh-CN/web).",
} {
if !containsLine(got, want) {
t.Fatalf("expected rewritten link %q in output:\n%s", want, got)
}
}
}
func TestPostprocessLocalizedDocsOnlyTouchesScopedFiles(t *testing.T) {
t.Parallel()