| 1 | import Link from "next/link"; |
| 2 | import { Icon } from "@/components/icon"; |
| 3 | import { PageHeader, Section } from "@/components/page-header"; |
| 4 | import { Status, type StatusTone } from "@/components/status-badge"; |
| 5 | import { GitHubStar, FaceWall, MergedList, readAsOf, statsAsOf } from "@/components/project-pulse"; |
| 6 | import { getFacts } from "@/lib/facts"; |
| 7 | import { fetchLabelled, type OpenIssue } from "@/lib/github"; |
| 8 | import { getEnv } from "@/lib/kv"; |
| 9 | import { loadProjectPulse } from "@/lib/project-pulse"; |
| 10 | import { fill, getChrome, getContribute, pickText } from "@/lib/i18n/dictionaries"; |
| 11 | import { pluralText } from "@/lib/i18n/plural"; |
| 12 | import { parseExclusions } from "@/lib/repo-activity"; |
| 13 | import { REPO_ISSUES_URL, REPO_URL } from "@/lib/i18n/links"; |
| 14 | import { buildPageMetadata } from "@/lib/page-meta"; |
| 15 | import { getMerchCopy } from "@/lib/content/contributor-merch"; |
| 16 | import { SKILL_CONTRIBUTION } from "@/lib/content/contributing"; |
| 17 | import { CONTRIBUTION_ROUTES, PROJECT_COPY, PROJECT_RELEASES, RELEASE_STATE_LABEL, STANDING_PROJECTS, type ReleaseState } from "@/lib/content/project"; |
| 18 | |
| 19 | export const revalidate = 600; |
| 20 | |
| 21 | const RELEASE_TONES: Record<ReleaseState, StatusTone> = { progress: "accent", planned: "idle", later: "idle" }; |
| 22 | |
| 23 | function milestoneNumber(url: string): string | null { |
| 24 | return url.match(/\/milestone\/(\d+)\/?$/)?.[1] ?? null; |
| 25 | } |
| 26 | |
| 27 | export async function generateMetadata({ params }: { params: Promise<{ locale: string }> }) { |
| 28 | const { locale } = await params; |
| 29 | const t = getContribute(locale); |
| 30 | return buildPageMetadata({ |
| 31 | path: "/contribute", |
| 32 | locale, |
| 33 | title: t.metaTitle, |
| 34 | description: t.metaDescription, |
| 35 | }); |
| 36 | } |
| 37 | |
| 38 | export default async function ContributePage({ params }: { params: Promise<{ locale: string }> }) { |
| 39 | const { locale } = await params; |
| 40 | const t = getContribute(locale); |
| 41 | const merch = getMerchCopy(locale); |
| 42 | const standing = [...STANDING_PROJECTS, SKILL_CONTRIBUTION]; |
| 43 | const facts = await getFacts(); |
| 44 | const pulse = await loadProjectPulse(8, 96); |
| 45 | const chrome = getChrome(locale); |
| 46 | const activity = pulse.activity; |
| 47 | const countForms = parseExclusions().confirmed ? t.mergedPeopleCount : t.mergedAccountsCount; |
| 48 | const mergedCount = activity?.count != null ? pluralText(countForms, activity.count, locale, chrome.dateLocale) : null; |
| 49 | const countAsOf = readAsOf(activity?.readAt, locale); |
| 50 | const progressFor = (href: string) => { |
| 51 | const number = milestoneNumber(href); |
| 52 | return number ? activity?.milestones.find((milestone) => milestoneNumber(milestone.url) === number) : undefined; |
| 53 | }; |
| 54 | let openNow: OpenIssue[] = []; |
| 55 | try { |
| 56 | openNow = await fetchLabelled("help wanted", (await getEnv()).GITHUB_TOKEN, 6); |
| 57 | } catch { |
| 58 | openNow = []; |
| 59 | } |
| 60 | |
| 61 | return ( |
| 62 | <> |
| 63 | <PageHeader |
| 64 | kicker={t.kicker} |
| 65 | title={t.title} |
| 66 | lede={t.lede} |
| 67 | pose="write" |
| 68 | actions={ |
| 69 | <> |
| 70 | <Link href={`${REPO_ISSUES_URL}/new/choose`} className="btn btn-primary btn-lg"> |
| 71 | {t.fileIssue} |
| 72 | <Icon name="external" className="icon" /> |
| 73 | </Link> |
| 74 | <GitHubStar stars={pulse.stats?.stars ?? undefined} locale={locale} asOf={statsAsOf(pulse.stats, locale)} /> |
| 75 | <Link href={`${REPO_URL}/blob/main/CONTRIBUTING.md`} className="btn btn-secondary btn-lg"> |
| 76 | {t.fullGuide} |
| 77 | <Icon name="external" className="icon" /> |
| 78 | </Link> |
| 79 | </> |
| 80 | } |
| 81 | /> |
| 82 | |
| 83 | <div className="page-body"> |
| 84 | <Section |
| 85 | id="contribute-routes" |
| 86 | title={pickText(PROJECT_COPY.routesHeading, locale)} |
| 87 | scope={pickText(PROJECT_COPY.routesScope, locale)} |
| 88 | > |
| 89 | <ul className="dir-list dir-list-card route-list" role="list"> |
| 90 | {CONTRIBUTION_ROUTES.map((route) => ( |
| 91 | <li key={route.have.en}> |
| 92 | <a href={route.href} className="dir-row"> |
| 93 | <span className="dir-text"> |
| 94 | <span className="dir-title">{pickText(route.have, locale)}</span> |
| 95 | </span> |
| 96 | <span className="route-place">{pickText(route.place, locale)}</span> |
| 97 | <span className="dir-action" aria-hidden="true"><Icon name="external" /></span> |
| 98 | </a> |
| 99 | </li> |
| 100 | ))} |
| 101 | </ul> |
| 102 | </Section> |
| 103 | |
| 104 | <Section |
| 105 | id="contribute-features" |
| 106 | layout="split" |
| 107 | label={pickText(PROJECT_COPY.featureLabel, locale)} |
| 108 | title={pickText(PROJECT_COPY.featureHeading, locale)} |
| 109 | scope={pickText(PROJECT_COPY.featureScope, locale)} |
| 110 | > |
| 111 | <ol className="goal-list" role="list"> |
| 112 | {PROJECT_COPY.featureSteps.map((step, index) => ( |
| 113 | <li key={step.title.en} className="goal"> |
| 114 | <span className="goal-number tabular" aria-hidden="true">{String(index + 1).padStart(2, "0")}</span> |
| 115 | <div className="goal-text"> |
| 116 | <h3>{pickText(step.title, locale)}</h3> |
| 117 | <p>{pickText(step.body, locale)}</p> |
| 118 | </div> |
| 119 | </li> |
| 120 | ))} |
| 121 | </ol> |
| 122 | </Section> |
| 123 | |
| 124 | <Section |
| 125 | id="contribute-standing" |
| 126 | title={pickText(PROJECT_COPY.standingHeading, locale)} |
| 127 | scope={pickText(PROJECT_COPY.standingScope, locale)} |
| 128 | > |
| 129 | <div className="grid-3"> |
| 130 | {standing.map((project) => ( |
| 131 | <a key={project.href} href={project.href} className="tile"> |
| 132 | <h3>{pickText(project.title, locale)}</h3> |
| 133 | <p>{pickText(project.body, locale)}</p> |
| 134 | </a> |
| 135 | ))} |
| 136 | </div> |
| 137 | </Section> |
| 138 | |
| 139 | {openNow.length > 0 ? ( |
| 140 | <Section |
| 141 | id="contribute-open" |
| 142 | title={pickText(PROJECT_COPY.openNowHeading, locale)} |
| 143 | scope={pickText(PROJECT_COPY.openNowScope, locale)} |
| 144 | link={<Link href={`${REPO_ISSUES_URL}?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22`} className="section-link">GitHub<Icon name="external" className="icon" /></Link>} |
| 145 | > |
| 146 | <ul className="dir-list dir-list-card" role="list"> |
| 147 | {openNow.map((issue) => ( |
| 148 | <li key={issue.number}> |
| 149 | <a href={issue.url} className="dir-row" data-funnel="help_wanted_exit"> |
| 150 | <span className="dir-mark" aria-hidden="true"><Icon name="sonar" /></span> |
| 151 | <span className="dir-text"> |
| 152 | <span className="dir-title">{issue.title}</span> |
| 153 | <span className="dir-purpose">{issue.labels.slice(0, 3).join(" · ")}</span> |
| 154 | </span> |
| 155 | <span className="dir-action" aria-hidden="true"><Icon name="external" /></span> |
| 156 | </a> |
| 157 | </li> |
| 158 | ))} |
| 159 | </ul> |
| 160 | </Section> |
| 161 | ) : null} |
| 162 | |
| 163 | {pulse.merged.length > 0 || pulse.faces.length > 0 ? ( |
| 164 | <Section |
| 165 | id="contribute-merged" |
| 166 | layout="split" |
| 167 | label={pickText(PROJECT_COPY.liveLabel, locale)} |
| 168 | title={pickText(PROJECT_COPY.mergedPageHeading, locale)} |
| 169 | scope={pickText(PROJECT_COPY.mergedPageScope, locale)} |
| 170 | link={<Link href="#milestones" className="btn btn-secondary">{pickText(PROJECT_COPY.goalsLink, locale)}<Icon name="arrow-right" className="icon icon-flip" /></Link>} |
| 171 | > |
| 172 | {mergedCount ? <p className="page-meta tabular" title={countAsOf}>{mergedCount}{countAsOf ? <span className="sr-only"> {countAsOf}</span> : null}</p> : null} |
| 173 | <MergedList items={pulse.merged} locale={locale} /> |
| 174 | </Section> |
| 175 | ) : null} |
| 176 | |
| 177 | <FaceWall faces={pulse.faces} total={facts.contributorCount} locale={locale} /> |
| 178 | |
| 179 | <Section |
| 180 | id="milestones" |
| 181 | title={pickText(PROJECT_COPY.releasesHeading, locale)} |
| 182 | scope={pickText(PROJECT_COPY.releasesScope, locale)} |
| 183 | > |
| 184 | <dl className="ruled-list release-plan"> |
| 185 | {PROJECT_RELEASES.map((release) => { |
| 186 | const progress = progressFor(release.href); |
| 187 | const total = progress ? progress.open + progress.closed : 0; |
| 188 | return ( |
| 189 | <div key={release.name}> |
| 190 | <dt> |
| 191 | <Link href={release.href} className="tabular">{release.name}</Link> |
| 192 | </dt> |
| 193 | <dd> |
| 194 | <Status tone={RELEASE_TONES[release.state]}>{pickText(RELEASE_STATE_LABEL[release.state], locale)}</Status> |
| 195 | {pickText(release.body, locale)} |
| 196 | {progress && total > 0 ? ( |
| 197 | <span className="tide-progress" title={countAsOf}> |
| 198 | <span className="tide-track" aria-hidden="true"><span style={{ inlineSize: `${Math.round((progress.closed / total) * 100)}%` }} /></span> |
| 199 | <span className="tabular">{fill(pickText(PROJECT_COPY.milestoneProgress, locale), { closed: progress.closed, total })}</span> |
| 200 | {countAsOf ? <span className="sr-only">, {countAsOf}</span> : null} |
| 201 | </span> |
| 202 | ) : null} |
| 203 | </dd> |
| 204 | </div> |
| 205 | ); |
| 206 | })} |
| 207 | </dl> |
| 208 | </Section> |
| 209 | |
| 210 | <Section id="contributor-merch" title={merch.title} scope={merch.lede}> |
| 211 | <Link href={`/${locale}/merch`} className="btn btn-secondary">{merch.cta}</Link> |
| 212 | </Section> |
| 213 | </div> |
| 214 | </> |
| 215 | ); |
| 216 | } |
| 217 |