Fix blog dates ignoring the page locale - #35
Merged
Conversation
fmtDate(s, format, lang) now formats its default/unrecognised branch with the page's own BCP-47 locale via Intl.DateTimeFormat, instead of an unconditional en-US literal. Every caller (ArchiveView, BlogIndexView, PostArticle, and the /search/label archive routes) now passes the page's own meta.lang (the Lingo variant actually being rendered), not the site default. No locale known keeps the historic en-US output byte-identical. `cjk` is accepted as an alias of `cjk-full`. Any other unrecognised blog-date-format value still renders (the locale default, never a blank date) but emits one build-time warning naming the allowed values, instead of silently doing nothing. Fixes #34
…locales An invalid BCP-47 lang tag (e.g. ja_JP, en US) made Intl.DateTimeFormat throw and crash the whole build; fmtDate's locale-default renderer now falls back to the historic en-US output on any tag Intl rejects, matching main. An explicit CJK blog-date-format (cjk/cjk-full/cjk-badge/cjk-md) was applied to every page locale, including English. Per the 2026-09-11 ruling, these formats now apply only to CJK page locales (ja/ko/zh-*); other locales get their own Intl default. ymd-slash stays script-neutral and unaffected. Also fixes a timezone-dependent test suite, pins an ICU literal so a small-ICU runner fails loudly instead of passing silently, replaces a source-text regex broken by the new guard with a behavioural check, and adds call-site and KNOWN_DATE_FORMATS coverage.
Member
Author
|
Round 1 fixed: fmtDate no longer crashes on an invalid BCP-47 lang tag (falls back to main's byte-identical en-US output), and an explicit CJK blog-date-format now applies only to CJK page locales (ja/ko/zh-*) rather than every locale — ymd-slash stays unaffected; details and the cheap P3s applied are in the updated PR description. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #34.
fmtDate(s, format, lang)gains a thirdlangargument: the page's own BCP-47 locale (the Lingo variant actually being rendered). Its default/unrecognised branch now formats withIntl.DateTimeFormat(toBcp47(lang), { year: 'numeric', month: 'long', day: 'numeric' })instead of an unconditionalen-USliteral. When no locale is known, output stays byte-identical to the historicen-USstring.fmtDatecaller (ArchiveView.astro,BlogIndexView.astro,PostArticle.astro, and the/search/label/[tag]archive routes) now passes the page's ownmeta.lang, not the site default.cjkis accepted as an alias ofcjk-full.blog-date-formatvalue still renders (the locale default, never a blank date), and now emits one build-time warning naming the allowed values — once per build per bad value, not once per post.langwith noblog-date-formatset will see its dates change (e.g.lang: zh-Hantmoves fromJuly 13, 2024to2024年7月13日) — this is the point of the fix, but is a real, visible output change for any such site's existing pages.Round 1 review fixes
langcrashed the whole build. Alang:value that is not a well-formed BCP-47 tag (ja_JP,zh_TW,en US, non-ASCII text) madeIntl.DateTimeFormatthrowRangeError, taking the whole build down on the first date it rendered — a regression versusmain, which always rendered (in English) regardless oflang.fmtDate's locale-default renderer now tries the page's tag and falls back to the historicen-USoutput, byte-identical tomain, on any tag Intl rejects; never throws.blog-date-formatis the site owner's choice for the locales it fits.cjk/cjk-full/cjk-badge/cjk-mdare a script, not a punctuation style, so they now apply only when the page's own locale is Japanese, Korean, or Chinese (ja/ko/zh-*) — a non-CJK page locale renders that locale's own Intl default instead (so anen-USpage staysJuly 13, 2024even when the site setsblog-date-format: cjk).ymd-slashhas no script and is unaffected — it always applies, on every locale, as before. When no page locale is known at all (langabsent), a named CJK format still always renders, matching the pre-existing behaviour beforelangwas threaded through. This rule is documented at theCJK_DATE_FORMATS/isCJKLangdefinitions and thefmtDatedoc comment inpackages/sitetile/astro/src/lib/blog.mjs.Cheap round 1 P3s also applied
blog-date-format.test.mjspinsTZ=UTCfor its own process) — the underlying UTC-midnight-vs-local-date gap is pre-existing elsewhere and out of scope here.ja-JP→2024年7月13日) so a small-ICU/system-ICU runner missing Japanese locale data fails loudly instead of silently passing on an Intl-vs-Intl comparison.chrome-copy.test.mjsthat pinnedfmtDate's exact default-branch source text with a behavioural check (it would have broken on the P1 fix'stry/catchfor no reason related to what it was guarding).fmtDate(call site to pass alangargument, mirroring the existingdateBadgePartsguard.KNOWN_DATE_FORMATSentry renders without an "unrecognised format" warning.Test plan
node packages/sitetile/blog-date-format.test.mjs— 9 tests: no-format under ja-JP/zh-TW/en-US against Intl's own output plus a pinned ICU literal, no-format-no-locale byte-identical,cjkalias, the new CJK-locale-gating rule (ja-JP/zh-TW/ko-KR stay CJK, en-US falls back,ymd-slashalways applies), unrecognised value warns once and still renders the locale default, everyKNOWN_DATE_FORMATSvalue warns never, every existing explicit format unchanged, unparseable date passthrough, and the new invalid-BCP-47-tag guard (garbage tags, empty tag, non-CJK bad tag under a CJK format) never throws and matchesmain's byte-identicalen-USoutput.TZ=America/Los_Angeles— all 9 pass.node packages/sitetile/chrome-copy.test.mjs— 15 tests, including the new behavioural (not structural) CJK-neutrality check and the newfmtDatecall-site guard.node packages/sitetile/blog-locale-archives.test.mjs,blog-unlisted.test.mjs,blog-defaults.test.mjs,blog-tenancy.test.mjs,blog-url-gating.test.mjs— unaffected, all green (28/18/2/14/15).Not verified
packages/sitetile/astro/node_modulesis not installed in this environment), so the actual rendered HTML on a live multi-locale build was not visually re-checked this round — only the underlyingfmtDate/call-site changes were unit-tested.