| 1 | import Link from "next/link"; |
| 2 | import type { RepoFacts } from "@/lib/facts"; |
| 3 | import { fill, getChrome, getDocsShell } from "@/lib/i18n/dictionaries"; |
| 4 | |
| 5 | /** |
| 6 | * Version-aware release truth, as one line of chrome: the latest published |
| 7 | * release from the facts layer, and whether the pages describe that release |
| 8 | * or the newer source candidate. Both values come from |
| 9 | * `lib/facts.generated.ts` (build) or the KV snapshot (deployed); nothing is |
| 10 | * typed by hand. |
| 11 | */ |
| 12 | export function ReleaseTruth({ locale, facts }: { locale: string; facts: RepoFacts }) { |
| 13 | const t = getDocsShell(locale); |
| 14 | const chrome = getChrome(locale); |
| 15 | const published = facts.latestPublishedRelease; |
| 16 | const version = facts.version; |
| 17 | const matches = published !== null && version !== null && published.version === version; |
| 18 | |
| 19 | return ( |
| 20 | <div className="release-truth dotline" data-release-state={matches ? "published" : "candidate"}> |
| 21 | <span className="release-truth-label">{t.releaseLabel}</span> |
| 22 | {published && ( |
| 23 | <a href={published.url} target="_blank" rel="noreferrer"> |
| 24 | {fill(t.releasePublished, { |
| 25 | tag: published.tag, |
| 26 | date: new Date(published.publishedAt).toLocaleDateString(chrome.dateLocale, { |
| 27 | year: "numeric", |
| 28 | month: "short", |
| 29 | day: "numeric", |
| 30 | timeZone: "UTC", |
| 31 | }), |
| 32 | })} |
| 33 | </a> |
| 34 | )} |
| 35 | {version && ( |
| 36 | <span> |
| 37 | {matches |
| 38 | ? fill(t.releaseMatches, { tag: `v${version}` }) |
| 39 | : fill(t.releaseCandidate, { version: `v${version}` })} |
| 40 | </span> |
| 41 | )} |
| 42 | <Link href={`/${locale}/changelog`}>{t.releaseChangelog}</Link> |
| 43 | </div> |
| 44 | ); |
| 45 | } |
| 46 |