返回 CodeWhale
page.tsx
根目录 / web / app / [locale] / install / page.tsx
1 import Link from "next/link";
2 import type { ReactNode } from "react";
3 import { EnglishRegion } from "@/components/fallback-region";
4 import { HeroInstall } from "@/components/hero-install";
5 import { Icon } from "@/components/icon";
6 import { InstallCodeBlock } from "@/components/install-code-block";
7 import { OnboardingCheck } from "@/components/onboarding-check";
8 import { WhalePose } from "@/components/whale-pose";
9 import { claimAvailability, runtimeCapabilityContext } from "@/lib/capabilities";
10 import { INSTALL_COMMANDS, INSTALL_COPY, INSTALL_PAGE_COMMANDS as C } from "@/lib/content/install";
11 import { splitCode } from "@/lib/content/models";
12 import type { LocalizedText } from "@/lib/content/vocabulary";
13 import { getFacts } from "@/lib/facts";
14 import { fill, getHome, pickText, pickTextLocale } from "@/lib/i18n/dictionaries";
15 import { buildPageMetadata, SITE_URL } from "@/lib/page-meta";
16
17 export const revalidate = 300;
18
19 const REPO_BLOB = "https://github.com/codewhale-hq/CodeWhale/blob";
20
21 export async function generateMetadata({ params }: { params: Promise<{ locale: string }> }) {
22 const { locale } = await params;
23 const meta = buildPageMetadata({
24 path: "/install",
25 locale,
26 title: pickText(INSTALL_COPY.metaTitle, locale),
27 description: pickText(INSTALL_COPY.metaDescription, locale),
28 });
29 return {
30 ...meta,
31 alternates: {
32 ...meta.alternates,
33 languages: {
34 ...meta.alternates?.languages,
35 en: `${SITE_URL}/en/install`,
36 zh: `${SITE_URL}/zh/install`,
37 "x-default": `${SITE_URL}/en/install`,
38 },
39 },
40 };
41 }
42
43 function Rich({ text }: { text: string }) {
44 return <>{splitCode(text).map((part, i) => (part.code ? <code key={i}>{part.text}</code> : part.text))}</>;
45 }
46
47 function Block({ id, title, children }: { id: string; title: string; children: ReactNode }) {
48 return (
49 <section id={id} className="install-guide" aria-labelledby={`${id}-title`}>
50 <h2 className="section-title" id={`${id}-title`}>{title}</h2>
51 {children}
52 </section>
53 );
54 }
55
56 function Channel({ id, title, children }: { id: string; title: string; children: ReactNode }) {
57 return (
58 <div id={id} className="install-channel">
59 <h3>{title}</h3>
60 {children}
61 </div>
62 );
63 }
64
65 export default async function InstallPage({ params }: { params: Promise<{ locale: string }> }) {
66 const { locale } = await params;
67 const home = getHome(locale);
68 const copyLocale = pickTextLocale(locale);
69 const facts = await getFacts();
70 const release = facts.latestPublishedRelease;
71 const version = release?.version ?? null;
72 const tag = release?.tag ?? null;
73 const uninstallReleased = claimAvailability({ feature: "unix-uninstall" }, runtimeCapabilityContext(facts)) === "released";
74 const t = (copy: LocalizedText) => fill(pickText(copy, locale), { version: version ?? "" });
75 const p = (copy: LocalizedText) => <p><Rich text={t(copy)} /></p>;
76 const code = (cmd: string) => (
77 <InstallCodeBlock cmd={cmd} copyLabel={home.copy} copiedLabel={home.copied} copyLocale={locale} />
78 );
79 const guideFile = locale === "zh" ? "docs/zh_hans/INSTALL.md" : "docs/INSTALL.md";
80 const guideRef = tag ?? "main";
81 const mirrorGuide = `${REPO_BLOB}/${guideRef}/${locale === "zh" ? "docs/zh_hans/CNB_MIRROR.md" : "docs/CNB_MIRROR.md"}`;
82 const mirrors = (
83 <Block id="mirrors" title={t(INSTALL_COPY.mirrorsTitle)}>
84 {p(INSTALL_COPY.mirrorsNpm)}
85 {p(INSTALL_COPY.mirrorsCnb)}
86 {code(C.cnbVerify)}
87 <p><a href={mirrorGuide} className="link">{t(INSTALL_COPY.mirrorsGuide)}</a></p>
88 </Block>
89 );
90
91 return (
92 <>
93 <div id="install-overview" className="install-head">
94 <div className="install-head-inner">
95 <WhalePose pose="run" className="install-head-pose" priority />
96 <div className="install-head-text">
97 <h1 className="page-title">{home.sectionStartHeading}</h1>
98 <p className="page-lede"><Rich text={home.sectionStartBody} /></p>
99 <HeroInstall locale={locale} ariaLabel={home.heroInstallAria} copyLabel={home.copy} copiedLabel={home.copied} />
100 <p className="install-head-source" lang={copyLocale}>
101 <Icon name="check" className="icon" />
102 <a href="/install.sh" className="link">{t(INSTALL_COPY.scriptLink)}</a>
103 </p>
104 {version ? <p className="install-head-note" lang={copyLocale}>{t(INSTALL_COPY.releaseLine)}</p> : null}
105 </div>
106 </div>
107 </div>
108 <EnglishRegion when={copyLocale === "en" && locale !== "en"}>
109 <div lang={copyLocale}>
110 {locale === "zh" ? mirrors : null}
111
112 <Block id="install-new-to-terminal" title={t(INSTALL_COPY.newTitle)}>
113 {p(INSTALL_COPY.newLead)}
114 <Channel id="install-new-macos" title={t(INSTALL_COPY.newMacTitle)}>
115 <ol>
116 <li><Rich text={t(INSTALL_COPY.newMac1)} /></li>
117 <li><Rich text={t(INSTALL_COPY.newMac2)} />{code(INSTALL_COMMANDS.shell)}</li>
118 <li><Rich text={t(INSTALL_COPY.newMac3)} /></li>
119 </ol>
120 </Channel>
121 <Channel id="install-new-linux" title={t(INSTALL_COPY.newLinuxTitle)}>
122 <ol>
123 <li><Rich text={t(INSTALL_COPY.newLinux1)} /></li>
124 <li><Rich text={t(INSTALL_COPY.newLinux2)} />{code(INSTALL_COMMANDS.shell)}</li>
125 <li><Rich text={t(INSTALL_COPY.newLinux3)} /></li>
126 </ol>
127 </Channel>
128 <Channel id="install-new-windows" title={t(INSTALL_COPY.newWinTitle)}>
129 <ol>
130 <li><Rich text={t(INSTALL_COPY.newWin1)} /></li>
131 <li><Rich text={t(INSTALL_COPY.newWin2)} />{code(INSTALL_COMMANDS.windows)}</li>
132 <li><Rich text={t(INSTALL_COPY.newWin3)} /></li>
133 </ol>
134 </Channel>
135 <p>
136 <Link href={`/${locale}/docs/first-time`} className="section-link">
137 {t(INSTALL_COPY.newNext)}
138 <Icon name="arrow-right" className="icon icon-flip" />
139 </Link>
140 </p>
141 </Block>
142
143 <Block id="install-path" title={t(INSTALL_COPY.pathTitle)}>
144 {p(INSTALL_COPY.pathPlaces)}
145 <ul>
146 {[INSTALL_COPY.pathZsh, INSTALL_COPY.pathBashLinux, INSTALL_COPY.pathBashMac, INSTALL_COPY.pathOther, INSTALL_COPY.pathFish].map((row) => (
147 <li key={row.en}><Rich text={t(row)} /></li>
148 ))}
149 </ul>
150 {p(INSTALL_COPY.pathBlockIntro)}
151 {code(C.pathBlock)}
152 {p(INSTALL_COPY.pathBlockAfter)}
153 {code(C.pathNow)}
154 {p(INSTALL_COPY.pathOptOut)}
155 {code(C.noModifyPath)}
156 {p(INSTALL_COPY.pathManualIntro)}
157 {p(INSTALL_COPY.pathManualBash)}
158 {code(C.pathManualBash)}
159 {p(INSTALL_COPY.pathManualZsh)}
160 {code(C.pathManualZsh)}
161 </Block>
162
163 <Block id="install-verify" title={t(INSTALL_COPY.verifyTitle)}>
164 {p(version ? INSTALL_COPY.verifyBody : INSTALL_COPY.verifyBodyUnknown)}
165 {code(C.version)}
166 <OnboardingCheck kind="install" locale={locale} />
167 </Block>
168
169 <Block id="install-first-task" title={t(INSTALL_COPY.firstTitle)}>
170 <ol>
171 {[INSTALL_COPY.firstStep1, INSTALL_COPY.firstStep2, INSTALL_COPY.firstStep3].map((row) => (
172 <li key={row.en}><Rich text={t(row)} /></li>
173 ))}
174 </ol>
175 <p>
176 <Link href={`/${locale}/docs/guide`} className="section-link">
177 {t(INSTALL_COPY.quickstart)}
178 <Icon name="arrow-right" className="icon icon-flip" />
179 </Link>
180 </p>
181 </Block>
182
183 <Block id="install-usage" title={t(INSTALL_COPY.usageTitle)}>
184 {p(INSTALL_COPY.usageBody)}
185 {code(C.telemetryOff)}
186 {p(INSTALL_COPY.usageInstaller)}
187 <p>
188 <Link href={`/${locale}/legal/privacy#usage-counting`} className="section-link">
189 {t(INSTALL_COPY.usageLink)}
190 <Icon name="arrow-right" className="icon icon-flip" />
191 </Link>
192 </p>
193 </Block>
194
195 <Block id="install-update" title={t(INSTALL_COPY.updateTitle)}>
196 {p(INSTALL_COPY.updateBody)}
197 {code(C.update)}
198 </Block>
199
200 <Block id="install-remove" title={t(INSTALL_COPY.removeTitle)}>
201 {uninstallReleased ? (
202 <>
203 {p(INSTALL_COPY.removeNow)}
204 {code(C.uninstall)}
205 {p(INSTALL_COPY.removeFilesNow)}
206 </>
207 ) : (
208 p(version ? INSTALL_COPY.removeFilesOnly : INSTALL_COPY.removeFilesOnlyUnknown)
209 )}
210 {code(C.removeFiles)}
211 {p(INSTALL_COPY.removePath)}
212 {p(INSTALL_COPY.removeData)}
213 {code(C.removeData)}
214 {version ? <p><Rich text={t(INSTALL_COPY.removeGuide)} /></p> : null}
215 </Block>
216
217 <Block id="install-troubleshooting" title={t(INSTALL_COPY.troubleTitle)}>
218 <ul>
219 {[INSTALL_COPY.troubleNotFound, INSTALL_COPY.troubleQueued, INSTALL_COPY.troubleLegacy].map((row) => (
220 <li key={row.en}><Rich text={t(row)} /></li>
221 ))}
222 </ul>
223 <p>
224 <Link href={`/${locale}/docs/troubleshooting`} className="section-link">
225 {t(INSTALL_COPY.troubleMore)}
226 <Icon name="arrow-right" className="icon icon-flip" />
227 </Link>
228 </p>
229 </Block>
230
231 <Block id="install-channels" title={t(INSTALL_COPY.channelsTitle)}>
232 {p(version ? INSTALL_COPY.channelsLead : INSTALL_COPY.channelsLeadUnknown)}
233 <Channel id="install-windows" title={t(INSTALL_COPY.windowsTitle)}>
234 {code(INSTALL_COMMANDS.windows)}
235 {p(INSTALL_COPY.windowsVerify)}
236 {p(INSTALL_COPY.windowsPackage)}
237 {p(INSTALL_COPY.windowsSandbox)}
238 {p(INSTALL_COPY.windowsUpdate)}
239 </Channel>
240 <Channel id="install-npm" title={t(INSTALL_COPY.npmTitle)}>
241 {code(INSTALL_COMMANDS.npm)}
242 {p(INSTALL_COPY.npmBody)}
243 {p(INSTALL_COPY.npmEacces)}
244 {code(C.npmPrefix)}
245 {p(INSTALL_COPY.npmScripts)}
246 {p(INSTALL_COPY.npmUpdate)}
247 </Channel>
248 <Channel id="install-cargo" title={t(INSTALL_COPY.cargoTitle)}>
249 {code(INSTALL_COMMANDS.cargo)}
250 {p(INSTALL_COPY.cargoBody)}
251 {p(INSTALL_COPY.cargoUpdate)}
252 {code(C.cargoUpdate)}
253 </Channel>
254 <Channel id="install-homebrew" title={t(INSTALL_COPY.brewTitle)}>
255 {code(C.brewInstall)}
256 {p(INSTALL_COPY.brewBody)}
257 {p(INSTALL_COPY.brewUpdate)}
258 {code(C.brewRemove)}
259 </Channel>
260 </Block>
261
262 {locale === "zh" ? null : mirrors}
263
264 <section id="install-full-guide" className="install-guide" aria-label={t(INSTALL_COPY.fullGuide)}>
265 <p>
266 <a href={`${REPO_BLOB}/${guideRef}/${guideFile}`} className="section-link">
267 {t(INSTALL_COPY.fullGuide)}
268 <Icon name="external" className="icon" />
269 </a>
270 </p>
271 </section>
272 </div>
273 </EnglishRegion>
274 </>
275 );
276 }
277
277 lines Plain Text