返回 CodeWhale
docs-help.tsx
根目录 / web / components / docs-help.tsx
1 "use client";
2
3 import Link from "next/link";
4 import { usePathname } from "next/navigation";
5 import { resolveDocsTopic } from "@/lib/docs-breadcrumbs";
6 import { REPO_DOCS_BASE } from "@/lib/docs-map";
7 import { getDocsShell, splitToken } from "@/lib/i18n/dictionaries";
8 import { DISCORD_URL, REPO_ISSUES_URL } from "@/lib/i18n/links";
9
10 /**
11 * Contextual help band under every docs page. The source-document link is
12 * resolved from the current route through the docs-map registry, so the
13 * band always points at the document this page was drawn from; the rest
14 * are the fixed escalation paths — troubleshooting, FAQ, Discord, and a
15 * pre-labelled docs issue.
16 */
17 export function DocsHelp({ locale }: { locale: string }) {
18 const t = getDocsShell(locale);
19 const pathname = usePathname() ?? `/${locale}/docs`;
20 const topic = resolveDocsTopic(locale, pathname);
21 const sources = topic
22 ? Array.isArray(topic.repoSource)
23 ? topic.repoSource
24 : [topic.repoSource]
25 : [];
26 // "Source: {name}" — the links are typeset between the template's halves
27 // so a locale may place the token anywhere.
28 const sourceParts = splitToken(t.helpSource, "name");
29 const issueUrl = `${REPO_ISSUES_URL}/new?labels=documentation&title=${encodeURIComponent(
30 `docs: ${topic ? topic.label.en : "hub"} (${pathname})`,
31 )}`;
32
33 return (
34 <aside className="docs-help" aria-labelledby="docs-help-title">
35 <div className="docs-help-copy">
36 <h2 id="docs-help-title">{t.helpTitle}</h2>
37 <p>{t.helpLead}</p>
38 {sources.length > 0 && (
39 <p className="docs-help-source">
40 {sourceParts[0]}
41 {sources.map((source, i) => (
42 <span key={source}>
43 {i > 0 && ", "}
44 <a href={`${REPO_DOCS_BASE}/${source}`} target="_blank" rel="noreferrer">
45 {source}
46 </a>
47 </span>
48 ))}
49 {sourceParts[1]}
50 </p>
51 )}
52 </div>
53 <nav className="docs-help-links" aria-label={t.helpTitle}>
54 {topic?.id !== "troubleshooting" && (
55 <Link href={`/${locale}/docs/troubleshooting`}>{t.helpTroubleshooting} →</Link>
56 )}
57 <Link href={`/${locale}/faq`}>{t.helpFaq} →</Link>
58 <a href={DISCORD_URL} target="_blank" rel="noreferrer">
59 {t.helpDiscord}
60 </a>
61 <a href="mailto:help@codewhale.net">help@codewhale.net</a>
62 <a href={issueUrl} target="_blank" rel="noreferrer">
63 {t.helpIssue}
64 </a>
65 </nav>
66 </aside>
67 );
68 }
69
69 lines Plain Text