fix(landing): keep mixed-case locale casing in emitted URLs (#562)

Astro's getRelativeLocaleUrl lowercases the locale segment by default, so landing links and hreflang for zh-CN, zh-TW, and pt-BR were emitted lowercase and 404 on case-sensitive Cloudflare Pages. Pin the casing at the localizeHref chokepoint with normalizeLocale: false, add an e2e hreflang casing guard, and add a deploy-time check that blocks the build if any lowercased locale path leaks into the output.

Closes #554
This commit is contained in:
SnapOtter
2026-07-18 10:47:53 +08:00
committed by GitHub
parent 54073a7c50
commit 67f54347b2
3 changed files with 56 additions and 1 deletions
+20
View File
@@ -24,6 +24,26 @@ test.describe("landing hreflang, RTL, and banner", () => {
expect(enFromDe).toBe("https://snapotter.com/faq/");
});
// Regression guard for #554. Astro's getRelativeLocaleUrl lowercases the locale
// segment by default (normalizeTheLocale: "zh-CN" -> "zh-cn"), but the built
// directories and the sitemap keep canonical mixed case. The lowercased links
// resolve on case-insensitive local hosting but 404 on Cloudflare Pages. This
// reads the emitted href string, so it catches the mismatch regardless of the
// local filesystem's case sensitivity (which is why the specs above missed it).
test("mixed-case locales keep their exact casing in hreflang links", async ({ page }) => {
await page.goto("/faq");
for (const code of ["zh-CN", "zh-TW", "pt-BR"]) {
const href = await page
.locator(`link[rel="alternate"][hreflang="${code}"]`)
.getAttribute("href");
expect(href, `hreflang ${code} must preserve casing`).toBe(
`https://snapotter.com/${code}/faq/`,
);
// The lowercased path (the bug) must not appear.
expect(href).not.toContain(code.toLowerCase());
}
});
test("Arabic renders dir=rtl on <html>", async ({ page }) => {
await page.goto("/ar/faq");
await expect(page.locator("html")).toHaveAttribute("dir", "rtl");