| 1 | import Link from "next/link"; |
| 2 | import { notFound, permanentRedirect } from "next/navigation"; |
| 3 | import { Icon } from "@/components/icon"; |
| 4 | import { PageHeader } from "@/components/page-header"; |
| 5 | import { RELEASE_NOTES } from "@/lib/release-notes.generated"; |
| 6 | import { changelogAnchor } from "@/scripts/changelog-lib.mjs"; |
| 7 | import { fill, getChangelog } from "@/lib/i18n/dictionaries"; |
| 8 | import { REPO_URL } from "@/lib/i18n/links"; |
| 9 | import { buildPageMetadata } from "@/lib/page-meta"; |
| 10 | import { bodyDateLocale } from "@/lib/i18n/fallback"; |
| 11 | import { FallbackRegion } from "@/components/fallback-region"; |
| 12 | |
| 13 | type PageParams = Promise<{ locale: string; version: string }>; |
| 14 | |
| 15 | export function generateStaticParams() { |
| 16 | return []; |
| 17 | } |
| 18 | |
| 19 | function findRelease(version: string) { |
| 20 | return RELEASE_NOTES.find((release) => release.version === version); |
| 21 | } |
| 22 | |
| 23 | export async function generateMetadata({ params }: { params: PageParams }) { |
| 24 | const { locale, version } = await params; |
| 25 | const release = findRelease(version); |
| 26 | if (!release) notFound(); |
| 27 | const t = getChangelog(locale); |
| 28 | return buildPageMetadata({ |
| 29 | path: `/changelog/${release.version}`, |
| 30 | locale, |
| 31 | title: fill(t.versionMetaTitle, { version: release.version }), |
| 32 | description: fill(t.versionMetaDescription, { version: release.version }), |
| 33 | }); |
| 34 | } |
| 35 | |
| 36 | export default async function ReleaseNotesPage({ params }: { params: PageParams }) { |
| 37 | const { locale, version } = await params; |
| 38 | const release = findRelease(version); |
| 39 | if (!release) { |
| 40 | const bare = version.replace(/^v/i, ""); |
| 41 | if (bare !== version && findRelease(bare)) permanentRedirect(`/${locale}/changelog/${bare}`); |
| 42 | notFound(); |
| 43 | } |
| 44 | const t = getChangelog(locale); |
| 45 | const date = release.date |
| 46 | ? new Date(release.date).toLocaleDateString(bodyDateLocale("/changelog", locale), { |
| 47 | year: "numeric", |
| 48 | month: "long", |
| 49 | day: "numeric", |
| 50 | timeZone: "UTC", |
| 51 | }) |
| 52 | : null; |
| 53 | const notesUrl = `${REPO_URL}/blob/main/CHANGELOG.md#${changelogAnchor(release)}`; |
| 54 | |
| 55 | return ( |
| 56 | <FallbackRegion path="/changelog" locale={locale}> |
| 57 | <PageHeader |
| 58 | kicker={t.versionKicker} |
| 59 | title={`Codewhale ${release.version}`} |
| 60 | lede={date ? fill(t.versionLead, { date }) : t.versionLeadUndated} |
| 61 | pose="write" |
| 62 | actions={ |
| 63 | <> |
| 64 | <Link href={`/${locale}/changelog`} className="btn btn-secondary"> |
| 65 | {t.allReleasesLink} |
| 66 | </Link> |
| 67 | <a href={notesUrl} target="_blank" rel="noreferrer" className="section-link"> |
| 68 | {t.fullNotes.replace(/\s*↗\s*$/u, "")} |
| 69 | <Icon name="external" className="icon" /> |
| 70 | </a> |
| 71 | </> |
| 72 | } |
| 73 | /> |
| 74 | |
| 75 | <div className="page-body"> |
| 76 | <div className="page-body-narrow changelog-list"> |
| 77 | <article id={`v${release.version}`} className="changelog-release"> |
| 78 | <div className="changelog-sections"> |
| 79 | {release.sections.map((section, i) => ( |
| 80 | <section key={`${section.heading}-${i}`}> |
| 81 | <h3> |
| 82 | {section.heading} |
| 83 | <span className="tabular">{section.itemCount}</span> |
| 84 | </h3> |
| 85 | <ul> |
| 86 | {section.items.map((item, j) => ( |
| 87 | <li key={j}>{item}</li> |
| 88 | ))} |
| 89 | </ul> |
| 90 | </section> |
| 91 | ))} |
| 92 | </div> |
| 93 | </article> |
| 94 | </div> |
| 95 | </div> |
| 96 | </FallbackRegion> |
| 97 | ); |
| 98 | } |
| 99 |