返回 CodeWhale
repository-reference.tsx
根目录 / web / app / [locale] / docs / _components / repository-reference.tsx
1 import Link from "next/link";
2 import { InstallCodeBlock } from "@/components/install-code-block";
3 import { REFERENCE_GUIDE_COPY } from "@/lib/content/reference-guides";
4 import { getFacts } from "@/lib/facts";
5 import { fill, getHome, pickText } from "@/lib/i18n/dictionaries";
6 import { buildPageMetadata } from "@/lib/page-meta";
7 import { getReferenceGuide } from "@/lib/reference-guides";
8
9 export function referenceMetadata(slug: string, locale: string) {
10 const { spec } = getReferenceGuide(slug);
11 return buildPageMetadata({ path: `/docs/${slug}`, locale, title: `${pickText(spec.title, locale)} · Codewhale Docs`, description: pickText(spec.lead, locale) });
12 }
13
14 export async function RepositoryReference({ slug, locale }: { slug: string; locale: string }) {
15 const { spec, source, sources, guide } = getReferenceGuide(slug);
16 const home = getHome(locale);
17 const tag = (await getFacts()).latestPublishedRelease?.tag ?? null;
18 return (
19 <div className="space-y-8">
20 <header id="overview">
21 <h1>{pickText(spec.title, locale)}</h1>
22 <p className="text-ink-soft mt-3 leading-relaxed">{pickText(spec.lead, locale)}</p>
23 {tag && <p className="docs-note mt-4">{fill(pickText(REFERENCE_GUIDE_COPY.scope, locale), { tag })}</p>}
24 <p className="docs-note mt-3">{pickText(REFERENCE_GUIDE_COPY.language, locale)}</p>
25 <Link href={`/${locale}${spec.tutorial}`} className="docs-inline-link underline inline-block mt-4">{pickText(spec.tutorialLabel, locale)}</Link>
26 </header>
27 <div className="install-guide" lang="en">
28 {guide.chunks.map((chunk, index) => chunk.kind === "code" ? (
29 <div key={index} className="my-4">
30 <p className="text-xs font-mono" lang={locale}>{pickText(REFERENCE_GUIDE_COPY.code, locale)}</p>
31 <InstallCodeBlock cmd={chunk.text} copyLabel={home.copy} copiedLabel={home.copied} copyLocale={locale} installIntent={false} />
32 </div>
33 ) : <div key={index} dangerouslySetInnerHTML={{ __html: chunk.text }} />)}
34 </div>
35 {tag && (
36 <p>
37 <a href={`https://github.com/codewhale-hq/CodeWhale/blob/${tag}/${source.path}`} className="docs-inline-link underline">{fill(pickText(REFERENCE_GUIDE_COPY.published, locale), { tag })}</a>
38 </p>
39 )}
40 <a href={`https://github.com/codewhale-hq/CodeWhale/blob/main/${source.path}`} className="docs-inline-link underline">{pickText(REFERENCE_GUIDE_COPY.source, locale)}</a>
41 <details>
42 <summary>{pickText(REFERENCE_GUIDE_COPY.revision, locale)}</summary>
43 {sources.map((entry) => <p key={entry.path} className="text-xs font-mono break-all mt-2">{entry.path} · SHA-256: {entry.sha256}</p>)}
44 </details>
45 </div>
46 );
47 }
48
48 lines Plain Text