Skip to content

Accept a lowercase region in language codes (pt-br) when expanding shorthand doc paths - #823

Merged
mishig25 merged 1 commit into
mainfrom
fix-lowercase-region-language-codes
Aug 26, 2026
Merged

mishig25 merged 1 commit into
mainfrom
fix-lowercase-region-language-codes

Conversation

@sergiopaniego

Copy link
Copy Markdown
Member

What does this PR do?

Fixes the doc build for repos whose language code has a lowercase region, broken since the kit upgrade to Svelte 5 (#792). Today that is huggingface/smol-course (pt-br), where every PR doc build fails.

getHfDocFullPath ($lib/hfDocPaths.js) expands shorthand doc URLs to the full route, and its language matcher is /^[a-z]{2}(-[A-Z]{2})?$/. pt-br fails that test, so the language segment is never shifted off params and ends up inside the chapter id, while _lang falls back to __DOCS_LANGUAGE__ and still satisfies the equality checks below:

/docs/smol-course/pr_306/pt-br/unit1/1
  -> /docs/smol-course/pr_306/pt-br/pt-br/unit1/1     (404)

That function is the reroute hook, and SvelteKit applies it while prerendering too, so every page of the language 404s and the build aborts on the first one. Before #792 this logic lived in the svelteKitCustomClient fork of SvelteKit's client, which only ran in the browser, so the build never saw it.

zh-CN (agents-course, course, cookbook), ru-RU (agents-course) and pt-BR (audio-transformers-course) already matched. pt-br in smol-course is the only code in the org that does not.

Changes:

  • Accept a lowercase region in the language matcher: /^[a-z]{2}(-[A-Za-z]{2})?$/.

Verified by building smol-course/units/pt-br locally with --html:

before:  exit 1, 14 x [404] GET /docs/smol-course/pr_306/pt-br/..., 0 HTML files
         Error: 404 /docs/smol-course/pr_306/pt-br/README
after:   exit 0, no 404s, 14 HTML files

which reproduces the CI failure of huggingface/smol-course#306 line for line. Building units/ko still passes (exit 0, 8 HTML files), and I checked the reroute mapping for en, zh-CN, ru-RU, pt-BR and pt-br, plus the shorthand (/docs/lib/page) and other-language (returns undefined) paths.

kit/ has no JS test runner, so there is no unit test to add here without pulling in one.

Once merged, re-running the smol-course checks should go green with no smol-course-side change (the reusable PR-doc workflow checks out doc-builder from main).

🤖 Generated with Claude Code

The `reroute` hook expands shorthand doc URLs to the full route, and its
language matcher only accepted `xx` or `xx-XX`. A code like `pt-br` fails
that test, so the language segment is never shifted off the path and ends
up in the chapter id, while `_lang` falls back to the current language and
still satisfies the equality checks:

  /docs/smol-course/pr_306/pt-br/unit1/1
    -> /docs/smol-course/pr_306/pt-br/pt-br/unit1/1   (404)

SvelteKit applies `reroute` during prerendering too, so every page of such
a language 404s and the build aborts on the first one. Before the kit
upgrade to Svelte 5 (#792) this logic lived in a fork of SvelteKit's
client and never ran at build time.

huggingface/smol-course is the only repo in the org with a lowercase
region (`pt-br`); `zh-CN`, `ru-RU` and `pt-BR` already matched.

Verified by building `smol-course/units/pt-br` with `--html`: 14 pages
404 and the build exits 1 before the change, and it exits 0 with all 14
HTML files after it. Building `units/ko` still passes.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@mishig25
mishig25 merged commit 68667a5 into main Aug 26, 2026
5 checks passed
@mishig25
mishig25 deleted the fix-lowercase-region-language-codes branch August 26, 2026 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants