hd-garden 0.6.1 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/skills/garden-ui/SKILL.md +26 -19
- package/README.en.md +57 -0
- package/README.md +31 -46
- package/app/admin/preview/[...path]/page.tsx +1 -1
- package/app/blog/[...path]/page.tsx +11 -3
- package/app/columns/[column]/[...path]/page.tsx +12 -14
- package/app/components/ArticleMeasure.tsx +39 -4
- package/app/components/ArticlePager.tsx +32 -0
- package/app/components/Comments.tsx +2 -1
- package/app/components/FeedMore.tsx +70 -0
- package/app/components/GardenDocsNav.tsx +189 -0
- package/app/components/HandbookLangRedirect.tsx +30 -0
- package/app/components/HandbookLangSwitch.tsx +49 -0
- package/app/components/HandbookView.tsx +187 -0
- package/app/components/MarkdownArticle.tsx +15 -8
- package/app/components/MarkdownImage.tsx +6 -4
- package/app/components/SiteChrome.tsx +11 -2
- package/app/components/SiteFooter.tsx +12 -3
- package/app/components/SiteHeader.tsx +27 -23
- package/app/components/TableOfContents.tsx +15 -9
- package/app/components/ThoughtFeed.tsx +41 -0
- package/app/components/UiLang.tsx +18 -0
- package/app/components/Webmentions.tsx +3 -2
- package/app/components/garden/FilePreview.tsx +13 -11
- package/app/components/garden/GardenBlock.tsx +3 -1
- package/app/components/garden/GardenFile.tsx +9 -7
- package/app/components/garden/blocks.tsx +34 -24
- package/app/components/garden/chrome.tsx +20 -13
- package/app/garden/[...slug]/page.tsx +28 -0
- package/app/garden/en/[...slug]/page.tsx +28 -0
- package/app/garden/en/page.tsx +16 -0
- package/app/garden/page.tsx +7 -141
- package/app/garden-modules.d.ts +18 -0
- package/app/globals.css +10 -10
- package/app/layout.tsx +2 -4
- package/app/lib/content.ts +27 -11
- package/app/lib/garden-docs-meta.ts +138 -0
- package/app/lib/handbook-path.ts +11 -0
- package/app/lib/heading-number.ts +13 -0
- package/app/lib/i18n.ts +222 -0
- package/app/lib/page-alternates.ts +2 -2
- package/app/not-found.tsx +5 -3
- package/app/site.config.ts +1 -1
- package/app/styles/a2.css +613 -13
- package/app/styles/shell.css +6 -0
- package/app/thoughts/page/[n]/page.tsx +44 -0
- package/app/thoughts/page.tsx +2 -6
- package/bin/garden.mjs +4 -0
- package/docs/handbook/ai-writing.md +99 -0
- package/docs/handbook/assets/reading-layout.svg +26 -0
- package/docs/handbook/components/card.md +46 -0
- package/docs/handbook/components/chart.md +54 -0
- package/docs/handbook/components/compare.md +38 -0
- package/docs/handbook/components/figure.md +72 -0
- package/docs/handbook/components/file/checklist.md +17 -0
- package/docs/handbook/components/file.md +34 -0
- package/docs/handbook/components/html.md +69 -0
- package/docs/handbook/components/interactive.md +67 -0
- package/docs/handbook/components/stat.md +57 -0
- package/docs/handbook/components/timeline.md +52 -0
- package/docs/handbook/components.md +30 -0
- package/docs/handbook/config.md +125 -0
- package/docs/handbook/deploy.md +273 -0
- package/docs/handbook/design.md +81 -0
- package/docs/handbook/en/ai-writing.md +99 -0
- package/docs/handbook/en/components/card.md +46 -0
- package/docs/handbook/en/components/chart.md +54 -0
- package/docs/handbook/en/components/compare.md +38 -0
- package/docs/handbook/en/components/figure.md +72 -0
- package/docs/handbook/en/components/file/checklist.md +17 -0
- package/docs/handbook/en/components/file.md +34 -0
- package/docs/handbook/en/components/html.md +69 -0
- package/docs/handbook/en/components/interactive.md +67 -0
- package/docs/handbook/en/components/stat.md +57 -0
- package/docs/handbook/en/components/timeline.md +52 -0
- package/docs/handbook/en/components.md +30 -0
- package/docs/handbook/en/config.md +125 -0
- package/docs/handbook/en/deploy.md +273 -0
- package/docs/handbook/en/design.md +81 -0
- package/docs/handbook/en/index.md +192 -0
- package/docs/handbook/en/start.md +92 -0
- package/docs/handbook/en/workflow.md +81 -0
- package/docs/handbook/en/writing.md +156 -0
- package/docs/handbook/index.md +187 -0
- package/docs/handbook/start.md +92 -0
- package/docs/handbook/workflow.md +81 -0
- package/docs/handbook/writing.md +156 -0
- package/package.json +2 -1
- package/scripts/build-content.mjs +144 -15
- package/scripts/handbook-allowlist.mjs +68 -0
- package/scripts/handbook-facts.mjs +1138 -0
- package/scripts/html-lang.mjs +36 -0
- package/scripts/static-404.mjs +25 -0
- package/scripts/ui-cli.mjs +14 -8
- package/site.config.yaml +2 -2
- package/templates/garden-blocks.md +1 -1
- package/templates/site/package.json +1 -3
- package/templates/site/site.config.yaml +2 -0
- package/ui/core/apply.mjs +22 -4
- package/ui/core/cli-locale.mjs +67 -0
- package/ui/core/fence.mjs +18 -3
- package/ui/core/fix-prompt.mjs +18 -15
- package/ui/core/garden-fence.mjs +64 -0
- package/ui/core/scan.mjs +19 -3
- package/ui/garden/adjacent.mjs +21 -0
- package/ui/garden/catalog.mjs +1 -1
- package/ui/garden/check.mjs +6 -0
- package/ui/garden/html-lang.mjs +16 -0
- package/ui/garden/paging.mjs +30 -0
- package/ui/preview/dist/garden-ui.css +9 -9
- package/ui/preview/dist/garden-ui.esm.js +169 -169
- package/ui/preview/dist/garden-ui.iife.js +169 -169
- package/ui/react/components/chart.tsx +7 -4
- package/ui/react/components/display.tsx +6 -3
- package/ui/react/components/inputs.tsx +6 -3
- package/ui/react/components/layout.tsx +6 -4
- package/ui/react/components/media.tsx +7 -4
- package/ui/react/components/sandbox.tsx +3 -1
- package/ui/react/index.tsx +11 -7
- package/ui/react/lang.tsx +85 -0
- package/ui/react/runtime.tsx +3 -1
- package/ui/react/ui.css +9 -9
- package/worker/index.ts +8 -1
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
import { useEffect, useId, useRef, useState, type ReactNode } from "react";
|
|
4
4
|
import ReactMarkdown from "react-markdown";
|
|
5
|
-
import {
|
|
5
|
+
import { useUi, useUiLang } from "../UiLang";
|
|
6
|
+
import { langOf, ui } from "../../lib/i18n";
|
|
7
|
+
import { interactiveUiSource } from "../../../ui/core/garden-fence.mjs";
|
|
6
8
|
import { markdownPlugins } from "../../lib/markdown-plugins";
|
|
7
9
|
import { compileUiBlock } from "../../../ui/core/compile.mjs";
|
|
8
10
|
import { splitCompareLine } from "../../../ui/garden/compare-line.mjs";
|
|
9
|
-
import { UiErrorCard, UiFigure, type Diagnostic, type UiPayload } from "../../../ui/react";
|
|
11
|
+
import { RuntimeLangProvider, UiErrorCard, UiFigure, type Diagnostic, type UiPayload } from "../../../ui/react";
|
|
10
12
|
import { FullscreenFrame, SandboxFrame } from "./chrome";
|
|
11
13
|
|
|
12
14
|
function Rich({ text }: { text: string }) {
|
|
@@ -187,7 +189,8 @@ function chartRows(props: Record<string, unknown>) {
|
|
|
187
189
|
export function GardenChart({ props }: { props: Record<string, unknown> }) {
|
|
188
190
|
const rows = chartRows(props);
|
|
189
191
|
const max = Math.max(...rows.map((row) => row.y), 1);
|
|
190
|
-
const
|
|
192
|
+
const t = useUi();
|
|
193
|
+
const title = String(props.title ?? t.chart);
|
|
191
194
|
return (
|
|
192
195
|
<figure className="g-chart" role="group" aria-label={title}>
|
|
193
196
|
{props.title ? <p className="g-chart-t">{title}</p> : null}
|
|
@@ -201,9 +204,9 @@ export function GardenChart({ props }: { props: Record<string, unknown> }) {
|
|
|
201
204
|
))}
|
|
202
205
|
</div>
|
|
203
206
|
<details className="g-chart-data">
|
|
204
|
-
<summary
|
|
207
|
+
<summary>{t.dataTable}</summary>
|
|
205
208
|
<table>
|
|
206
|
-
<thead><tr><th>{String(props.xLabel ?? (typeof props.x === "string" ? props.x :
|
|
209
|
+
<thead><tr><th>{String(props.xLabel ?? (typeof props.x === "string" ? props.x : t.item))}</th><th>{String(props.yLabel ?? t.value)}</th></tr></thead>
|
|
207
210
|
<tbody>
|
|
208
211
|
{rows.map((row) => <tr key={row.x}><td>{row.x}</td><td>{row.label}</td></tr>)}
|
|
209
212
|
</tbody>
|
|
@@ -216,11 +219,11 @@ export function GardenChart({ props }: { props: Record<string, unknown> }) {
|
|
|
216
219
|
|
|
217
220
|
type Part = { id: string; label: string; text: string };
|
|
218
221
|
|
|
219
|
-
function partsOf(props: Record<string, unknown
|
|
222
|
+
function partsOf(props: Record<string, unknown>, partLabel: (n: number) => string): Part[] {
|
|
220
223
|
if (!Array.isArray(props.parts)) return [];
|
|
221
224
|
return props.parts.map((part, index) => {
|
|
222
225
|
const item = part as Record<string, unknown>;
|
|
223
|
-
const label = String(item.label ?? item.name ??
|
|
226
|
+
const label = String(item.label ?? item.name ?? partLabel(index + 1));
|
|
224
227
|
return { id: String(item.id ?? item.name ?? label), label, text: String(item.text ?? "") };
|
|
225
228
|
});
|
|
226
229
|
}
|
|
@@ -240,7 +243,8 @@ function partOn(selected: string, token: string) {
|
|
|
240
243
|
}
|
|
241
244
|
|
|
242
245
|
export function GardenFigure({ props, children }: { props: Record<string, unknown>; children?: string }) {
|
|
243
|
-
const
|
|
246
|
+
const t = useUi();
|
|
247
|
+
const parts = partsOf(props, t.part);
|
|
244
248
|
const [selected, setSelected] = useState(parts[0]?.id ?? "all");
|
|
245
249
|
const svgRef = useRef<HTMLDivElement>(null);
|
|
246
250
|
const base = useId();
|
|
@@ -286,7 +290,7 @@ export function GardenFigure({ props, children }: { props: Record<string, unknow
|
|
|
286
290
|
const body = (
|
|
287
291
|
<figure className="g-explore" data-g="explore" data-sel={selected} ref={svgRef}>
|
|
288
292
|
{parts.length ? (
|
|
289
|
-
<div role="tablist" aria-label=
|
|
293
|
+
<div role="tablist" aria-label={t.pickPart}>
|
|
290
294
|
{parts.map((part, index) => (
|
|
291
295
|
<button
|
|
292
296
|
key={part.id}
|
|
@@ -324,7 +328,7 @@ export function GardenFigure({ props, children }: { props: Record<string, unknow
|
|
|
324
328
|
{typeof props.caption === "string" ? <figcaption><Rich text={props.caption} /></figcaption> : null}
|
|
325
329
|
</figure>
|
|
326
330
|
);
|
|
327
|
-
return parts.length || svg ? <FullscreenFrame label=
|
|
331
|
+
return parts.length || svg ? <FullscreenFrame label={t.diagram}>{body}</FullscreenFrame> : body;
|
|
328
332
|
}
|
|
329
333
|
|
|
330
334
|
function htmlHasScript(source: string) {
|
|
@@ -336,6 +340,8 @@ function isLightWidget(source: string) {
|
|
|
336
340
|
}
|
|
337
341
|
|
|
338
342
|
function bindGardenWidgets(root: HTMLElement) {
|
|
343
|
+
const attr = root.closest("[lang]")?.getAttribute("lang");
|
|
344
|
+
const t = ui(attr ? langOf(attr) : undefined);
|
|
339
345
|
root.querySelectorAll<HTMLElement>("[data-g=tabs]").forEach((widget) => {
|
|
340
346
|
const list = widget.querySelector<HTMLElement>(":scope > [role=tablist]");
|
|
341
347
|
const tabs = [...(list?.querySelectorAll<HTMLElement>(":scope > [role=tab]") ?? [])];
|
|
@@ -373,12 +379,12 @@ function bindGardenWidgets(root: HTMLElement) {
|
|
|
373
379
|
const chosen = form.querySelector<HTMLInputElement>("input:checked");
|
|
374
380
|
if (!chosen) {
|
|
375
381
|
out.className = "g-quiz-out";
|
|
376
|
-
out.textContent =
|
|
382
|
+
out.textContent = t.pickAnswer;
|
|
377
383
|
return;
|
|
378
384
|
}
|
|
379
385
|
const correct = chosen.value === form.dataset.answer;
|
|
380
386
|
out.className = `g-quiz-out ${correct ? "ok" : "no"}`;
|
|
381
|
-
out.textContent = correct ?
|
|
387
|
+
out.textContent = correct ? t.correct : t.wrong;
|
|
382
388
|
if (explain) explain.hidden = !correct;
|
|
383
389
|
});
|
|
384
390
|
});
|
|
@@ -446,7 +452,7 @@ function bindGardenWidgets(root: HTMLElement) {
|
|
|
446
452
|
const equation = calc.querySelector("[data-calc]");
|
|
447
453
|
if (equation && spec.show) {
|
|
448
454
|
const shown = spec.show.replace(/\{(\w+)\}/g, (_, key: string) => String(values[key]));
|
|
449
|
-
equation.textContent = `${shown} = ${spec.format === "GB" ? `${Math.round(result).toLocaleString("en-US")}
|
|
455
|
+
equation.textContent = `${shown} = ${spec.format === "GB" ? `${Math.round(result).toLocaleString("en-US")} ${t.bytes}` : String(Math.round(result * 1e4) / 1e4)}`;
|
|
450
456
|
}
|
|
451
457
|
};
|
|
452
458
|
calc.addEventListener("input", run);
|
|
@@ -484,9 +490,10 @@ function LightGardenHtml({ code }: { code: string }) {
|
|
|
484
490
|
|
|
485
491
|
export function GardenHtml({ props, children }: { props: Record<string, unknown>; children?: string }) {
|
|
486
492
|
const code = typeof props.code === "string" ? props.code : children || "";
|
|
493
|
+
const t = useUi();
|
|
487
494
|
const title = String(props.title ?? "HTML");
|
|
488
495
|
if (!code && typeof props.src === "string") {
|
|
489
|
-
return <p className="g-embed-note">
|
|
496
|
+
return <p className="g-embed-note">{t.htmlAt(String(props.src))}</p>;
|
|
490
497
|
}
|
|
491
498
|
if (htmlHasScript(code)) {
|
|
492
499
|
return <SandboxFrame html={code} title={title} />;
|
|
@@ -499,36 +506,38 @@ export function GardenHtml({ props, children }: { props: Record<string, unknown>
|
|
|
499
506
|
}
|
|
500
507
|
|
|
501
508
|
export function GardenInteractive({ block }: { block: { id?: string | null; props: Record<string, unknown>; children?: string } }) {
|
|
502
|
-
const
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
...(block.props.expect ? { expect: block.props.expect } : {}),
|
|
507
|
-
};
|
|
508
|
-
const source = `---\n${stringify(header)}---\n${block.children ?? ""}`;
|
|
509
|
+
const t = useUi();
|
|
510
|
+
const lang = useUiLang();
|
|
511
|
+
// Same source `garden ui check` validates (ui/core/garden-fence.mjs).
|
|
512
|
+
const { source, header } = interactiveUiSource({ id: block.id ?? null, props: block.props, children: block.children ?? "" });
|
|
509
513
|
const { payload, check } = compileUiBlock(source);
|
|
510
514
|
if (!payload) {
|
|
511
515
|
return (
|
|
516
|
+
<RuntimeLangProvider lang={lang}>
|
|
512
517
|
<UiErrorCard
|
|
513
518
|
id={String(header.id)}
|
|
514
519
|
caption={String(header.caption)}
|
|
515
520
|
diagnostics={(check.diagnostics ?? []) as Diagnostic[]}
|
|
516
521
|
/>
|
|
522
|
+
</RuntimeLangProvider>
|
|
517
523
|
);
|
|
518
524
|
}
|
|
519
525
|
return (
|
|
520
|
-
<
|
|
526
|
+
<RuntimeLangProvider lang={lang}>
|
|
527
|
+
<FullscreenFrame label={String(header.caption || t.interactive)}>
|
|
521
528
|
<div className="g-play">
|
|
522
529
|
<UiFigure payload={payload as UiPayload} />
|
|
523
530
|
</div>
|
|
524
531
|
</FullscreenFrame>
|
|
532
|
+
</RuntimeLangProvider>
|
|
525
533
|
);
|
|
526
534
|
}
|
|
527
535
|
|
|
528
536
|
export function GardenIdea({ text }: { text: string }) {
|
|
537
|
+
const t = useUi();
|
|
529
538
|
return (
|
|
530
539
|
<aside className="g-idea">
|
|
531
|
-
<p className="g-example-label"
|
|
540
|
+
<p className="g-example-label">{t.ideaLabel}</p>
|
|
532
541
|
<p>{text}</p>
|
|
533
542
|
</aside>
|
|
534
543
|
);
|
|
@@ -539,7 +548,8 @@ export function GardenLegacy({ suggestion }: { suggestion: string }) {
|
|
|
539
548
|
}
|
|
540
549
|
|
|
541
550
|
export function GardenUnknown({ name }: { name: string }) {
|
|
542
|
-
|
|
551
|
+
const t = useUi();
|
|
552
|
+
return <p className="g-embed-note">{t.unknownBlock(name)}</p>;
|
|
543
553
|
}
|
|
544
554
|
|
|
545
555
|
export function GardenMessage({ children }: { children: ReactNode }) {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
+
import { useUi } from "../UiLang";
|
|
4
|
+
|
|
3
5
|
import {
|
|
4
6
|
useEffect,
|
|
5
7
|
useId,
|
|
@@ -47,7 +49,9 @@ function writeClipboard(text: string) {
|
|
|
47
49
|
});
|
|
48
50
|
}
|
|
49
51
|
|
|
50
|
-
export function CopyButton({ getText, label
|
|
52
|
+
export function CopyButton({ getText, label }: { getText: () => string; label?: string }) {
|
|
53
|
+
const t = useUi();
|
|
54
|
+
label = label ?? t.copyCode;
|
|
51
55
|
const [done, setDone] = useState(false);
|
|
52
56
|
const timer = useRef<number>(0);
|
|
53
57
|
|
|
@@ -56,8 +60,8 @@ export function CopyButton({ getText, label = "复制代码" }: { getText: () =>
|
|
|
56
60
|
<button
|
|
57
61
|
type="button"
|
|
58
62
|
className={`ux-btn ux-copy${done ? " ux-done" : ""}`}
|
|
59
|
-
aria-label={done ?
|
|
60
|
-
title={done ?
|
|
63
|
+
aria-label={done ? t.copied : label}
|
|
64
|
+
title={done ? t.copied : label}
|
|
61
65
|
onClick={() => {
|
|
62
66
|
const text = getText();
|
|
63
67
|
writeClipboard(text).then(() => {
|
|
@@ -67,9 +71,9 @@ export function CopyButton({ getText, label = "复制代码" }: { getText: () =>
|
|
|
67
71
|
}).catch(() => setDone(false));
|
|
68
72
|
}}
|
|
69
73
|
>
|
|
70
|
-
{done ?
|
|
74
|
+
{done ? t.copied : COPY_ICON}
|
|
71
75
|
</button>
|
|
72
|
-
<span className="ux-live" aria-live="polite">{done ?
|
|
76
|
+
<span className="ux-live" aria-live="polite">{done ? t.copiedLive : ""}</span>
|
|
73
77
|
</>
|
|
74
78
|
);
|
|
75
79
|
}
|
|
@@ -88,12 +92,12 @@ export function CodeCopy({ children }: { children: ReactNode }) {
|
|
|
88
92
|
);
|
|
89
93
|
}
|
|
90
94
|
|
|
91
|
-
function diffLines(source: string) {
|
|
95
|
+
function diffLines(source: string, t: ReturnType<typeof useUi>) {
|
|
92
96
|
return source.replace(/\n$/u, "").split("\n").map((line) => {
|
|
93
97
|
const kind = line.startsWith("+") ? "add" : line.startsWith("-") ? "del" : "ctx";
|
|
94
98
|
const body = kind === "ctx" ? line.replace(/^ /u, "") : line.slice(1);
|
|
95
99
|
const mark = kind === "add" ? "+" : kind === "del" ? "−" : " ";
|
|
96
|
-
const spoken = kind === "add" ?
|
|
100
|
+
const spoken = kind === "add" ? t.diffAdded : kind === "del" ? t.diffRemoved : "";
|
|
97
101
|
return { kind, body, mark, spoken };
|
|
98
102
|
});
|
|
99
103
|
}
|
|
@@ -109,11 +113,12 @@ export function CodeDiff({
|
|
|
109
113
|
}) {
|
|
110
114
|
const [tab, setTab] = useState(0);
|
|
111
115
|
const base = useId();
|
|
112
|
-
const
|
|
116
|
+
const t = useUi();
|
|
117
|
+
const tabs = t.codeTabs;
|
|
113
118
|
|
|
114
119
|
return (
|
|
115
120
|
<div className="g-tabs g-code-group g-codediff" data-g="tabs">
|
|
116
|
-
<div role="tablist" aria-label=
|
|
121
|
+
<div role="tablist" aria-label={t.codeTabsLabel}>
|
|
117
122
|
{tabs.map((label, index) => (
|
|
118
123
|
<button
|
|
119
124
|
key={label}
|
|
@@ -146,7 +151,7 @@ export function CodeDiff({
|
|
|
146
151
|
<div role="tabpanel" id={`${base}-p1`} aria-labelledby={`${base}-t1`} hidden={tab !== 1}>
|
|
147
152
|
<pre className="code g-diff">
|
|
148
153
|
<code>
|
|
149
|
-
{diffLines(diff).map((line, index) => (
|
|
154
|
+
{diffLines(diff, t).map((line, index) => (
|
|
150
155
|
<span className={`d-${line.kind}`} key={index}>
|
|
151
156
|
<span className="d-m" aria-hidden="true">{line.mark}</span>
|
|
152
157
|
{line.body}
|
|
@@ -164,7 +169,9 @@ function fullscreenElement() {
|
|
|
164
169
|
return document.fullscreenElement || (document as Document & { webkitFullscreenElement?: Element }).webkitFullscreenElement || null;
|
|
165
170
|
}
|
|
166
171
|
|
|
167
|
-
export function FullscreenFrame({ children, label
|
|
172
|
+
export function FullscreenFrame({ children, label }: { children: ReactNode; label?: string }) {
|
|
173
|
+
const t = useUi();
|
|
174
|
+
label = label ?? t.demo;
|
|
168
175
|
const ref = useRef<HTMLDivElement>(null);
|
|
169
176
|
const buttonRef = useRef<HTMLButtonElement>(null);
|
|
170
177
|
const restoreRef = useRef<HTMLElement | null>(null);
|
|
@@ -255,8 +262,8 @@ export function FullscreenFrame({ children, label = "演示" }: { children: Reac
|
|
|
255
262
|
ref={buttonRef}
|
|
256
263
|
type="button"
|
|
257
264
|
className="ux-btn ux-fsb"
|
|
258
|
-
aria-label={active ?
|
|
259
|
-
title={active ?
|
|
265
|
+
aria-label={active ? t.exitFullscreen : t.fullscreen}
|
|
266
|
+
title={active ? t.exitFullscreen : t.fullscreen}
|
|
260
267
|
onClick={() => (active ? close() : open())}
|
|
261
268
|
>
|
|
262
269
|
{active ? EXIT_ICON : ENTER_ICON}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { notFound } from "next/navigation";
|
|
2
|
+
import { HandbookDoc, handbookDocMetadata } from "../../components/HandbookView";
|
|
3
|
+
import { gardenDocs } from "../../lib/content";
|
|
4
|
+
import { isStaticPlaceholder, STATIC_PLACEHOLDER, staticParams } from "../../../ui/garden/static-params.mjs";
|
|
5
|
+
|
|
6
|
+
const find = (slug: string[]) => gardenDocs.find((doc) => doc.path === slug.join("/"));
|
|
7
|
+
|
|
8
|
+
export function generateStaticParams() {
|
|
9
|
+
return staticParams(
|
|
10
|
+
gardenDocs.map((doc) => ({ slug: doc.path.split("/") })),
|
|
11
|
+
{ slug: [STATIC_PLACEHOLDER] },
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function generateMetadata({ params }: { params: Promise<{ slug: string[] }> }) {
|
|
16
|
+
const { slug } = await params;
|
|
17
|
+
return handbookDocMetadata("zh", find(slug));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default async function GardenDocPage({ params }: { params: Promise<{ slug: string[] }> }) {
|
|
21
|
+
const { slug } = await params;
|
|
22
|
+
const doc = find(slug);
|
|
23
|
+
if (!doc) {
|
|
24
|
+
if (isStaticPlaceholder(slug)) return null;
|
|
25
|
+
notFound();
|
|
26
|
+
}
|
|
27
|
+
return <HandbookDoc lang="zh" doc={doc} />;
|
|
28
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { notFound } from "next/navigation";
|
|
2
|
+
import { HandbookDoc, handbookDocMetadata } from "../../../components/HandbookView";
|
|
3
|
+
import { gardenDocsEn } from "../../../lib/content";
|
|
4
|
+
import { isStaticPlaceholder, STATIC_PLACEHOLDER, staticParams } from "../../../../ui/garden/static-params.mjs";
|
|
5
|
+
|
|
6
|
+
const find = (slug: string[]) => gardenDocsEn.find((doc) => doc.path === slug.join("/"));
|
|
7
|
+
|
|
8
|
+
export function generateStaticParams() {
|
|
9
|
+
return staticParams(
|
|
10
|
+
gardenDocsEn.map((doc) => ({ slug: doc.path.split("/") })),
|
|
11
|
+
{ slug: [STATIC_PLACEHOLDER] },
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function generateMetadata({ params }: { params: Promise<{ slug: string[] }> }) {
|
|
16
|
+
const { slug } = await params;
|
|
17
|
+
return handbookDocMetadata("en", find(slug));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default async function GardenEnDocPage({ params }: { params: Promise<{ slug: string[] }> }) {
|
|
21
|
+
const { slug } = await params;
|
|
22
|
+
const doc = find(slug);
|
|
23
|
+
if (!doc) {
|
|
24
|
+
if (isStaticPlaceholder(slug)) return null;
|
|
25
|
+
notFound();
|
|
26
|
+
}
|
|
27
|
+
return <HandbookDoc lang="en" doc={doc} />;
|
|
28
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { notFound } from "next/navigation";
|
|
2
|
+
import { HandbookOverview, handbookLanguages } from "../../components/HandbookView";
|
|
3
|
+
import { pageAlternates } from "../../lib/page-alternates";
|
|
4
|
+
import { HANDBOOK_UI } from "../../lib/garden-docs-meta";
|
|
5
|
+
import { gardenIndexDocEn } from "../../lib/content";
|
|
6
|
+
|
|
7
|
+
export const metadata = {
|
|
8
|
+
title: HANDBOOK_UI.en.name,
|
|
9
|
+
description: gardenIndexDocEn?.description ?? "",
|
|
10
|
+
alternates: pageAlternates("/garden/en", handbookLanguages("en", "index")),
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export default function GardenEnPage() {
|
|
14
|
+
if (!gardenIndexDocEn) notFound();
|
|
15
|
+
return <HandbookOverview lang="en" />;
|
|
16
|
+
}
|
package/app/garden/page.tsx
CHANGED
|
@@ -1,148 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { GardenAdminGuide } from "../components/GardenAdminGuide";
|
|
3
|
-
import { GardenContentGuide } from "../components/GardenContentGuide";
|
|
4
|
-
import { GardenMediaGuide } from "../components/GardenMediaGuide";
|
|
5
|
-
import { PageIntro } from "../components/PageIntro";
|
|
6
|
-
import { siteConfig } from "../site.config";
|
|
1
|
+
import { HandbookOverview, handbookLanguages } from "../components/HandbookView";
|
|
7
2
|
import { pageAlternates } from "../lib/page-alternates";
|
|
3
|
+
import { HANDBOOK_UI } from "../lib/garden-docs-meta";
|
|
4
|
+
import { gardenIndexDoc } from "../lib/content";
|
|
8
5
|
|
|
9
6
|
export const metadata = {
|
|
10
|
-
title:
|
|
11
|
-
description:
|
|
12
|
-
alternates: pageAlternates("/garden"),
|
|
7
|
+
title: HANDBOOK_UI.zh.name,
|
|
8
|
+
description: gardenIndexDoc?.description ?? "",
|
|
9
|
+
alternates: pageAlternates("/garden", handbookLanguages("zh", "index")),
|
|
13
10
|
};
|
|
14
11
|
|
|
15
|
-
const jumps = [
|
|
16
|
-
["#write-post", "写文章"],
|
|
17
|
-
["#write-thought", "随想"],
|
|
18
|
-
["#make-column", "专栏"],
|
|
19
|
-
["#setup", "跑起来"],
|
|
20
|
-
["#media", "视频和链接"],
|
|
21
|
-
["#admin", "后台"],
|
|
22
|
-
];
|
|
23
|
-
|
|
24
|
-
const setupSteps = [
|
|
25
|
-
{
|
|
26
|
-
title: "创建站点",
|
|
27
|
-
body: (
|
|
28
|
-
<>
|
|
29
|
-
运行 <code>npx hd-garden init my-blog</code>。目录里留下 <code>content/</code> 和 <code>site.config.yaml</code>。仓库名叫 <code><owner>.github.io</code> 时,地址最直接。
|
|
30
|
-
</>
|
|
31
|
-
),
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
title: "在本地看",
|
|
35
|
-
command: "make dev",
|
|
36
|
-
body: "第一次会安装依赖。然后打开终端里的地址。",
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
title: "换成你的内容",
|
|
40
|
-
files: [
|
|
41
|
-
["site.config.yaml", "站名、作者、各页标题"],
|
|
42
|
-
["content/posts/", "长文和附件"],
|
|
43
|
-
["content/thoughts/", "随想"],
|
|
44
|
-
["content/columns.yaml", "专栏和阅读顺序"],
|
|
45
|
-
],
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
title: "发布",
|
|
49
|
-
command: "make update",
|
|
50
|
-
body: "先检查,再提交并推送。main 更新后,网站、搜索和 RSS 会一起更新。",
|
|
51
|
-
},
|
|
52
|
-
];
|
|
53
|
-
|
|
54
12
|
export default function GardenPage() {
|
|
55
|
-
return
|
|
56
|
-
<main className="page-shell garden-page">
|
|
57
|
-
<PageIntro title={siteConfig.pages.garden.title} subtitle={siteConfig.pages.garden.subtitle}>
|
|
58
|
-
<p className="garden-lede">
|
|
59
|
-
文章放在你自己的仓库里。你改文件,网站跟着更新。
|
|
60
|
-
</p>
|
|
61
|
-
<div className="garden-actions">
|
|
62
|
-
<a
|
|
63
|
-
className="garden-primary-link"
|
|
64
|
-
href="https://github.com/hedon954/garden"
|
|
65
|
-
target="_blank"
|
|
66
|
-
rel="noreferrer"
|
|
67
|
-
>
|
|
68
|
-
<GithubLogo size={18} weight="fill" />
|
|
69
|
-
查看源码
|
|
70
|
-
<ArrowUpRight size={16} />
|
|
71
|
-
</a>
|
|
72
|
-
<a className="inline-cta" href="#setup">
|
|
73
|
-
在本地跑起来
|
|
74
|
-
<ArrowRight size={16} />
|
|
75
|
-
</a>
|
|
76
|
-
</div>
|
|
77
|
-
</PageIntro>
|
|
78
|
-
|
|
79
|
-
<nav className="garden-jumps" aria-label="本页">
|
|
80
|
-
{jumps.map(([href, label]) => (
|
|
81
|
-
<a key={href} href={href}>{label}</a>
|
|
82
|
-
))}
|
|
83
|
-
</nav>
|
|
84
|
-
|
|
85
|
-
<GardenContentGuide />
|
|
86
|
-
|
|
87
|
-
<section className="garden-setup" id="setup" aria-labelledby="garden-setup-title">
|
|
88
|
-
<header className="garden-section-heading">
|
|
89
|
-
<h2 id="garden-setup-title">跑起来</h2>
|
|
90
|
-
<p>不需要数据库。换上你的名字和第一篇文章,推送即可。</p>
|
|
91
|
-
</header>
|
|
92
|
-
|
|
93
|
-
<ol className="garden-steps">
|
|
94
|
-
{setupSteps.map((step, index) => (
|
|
95
|
-
<li key={step.title}>
|
|
96
|
-
<span>{index + 1}</span>
|
|
97
|
-
<div>
|
|
98
|
-
<h3>{step.title}</h3>
|
|
99
|
-
{"command" in step && step.command ? <pre><code>{step.command}</code></pre> : null}
|
|
100
|
-
{"files" in step && step.files ? (
|
|
101
|
-
<dl>
|
|
102
|
-
{step.files.map(([name, note]) => (
|
|
103
|
-
<div key={name}>
|
|
104
|
-
<dt>{name}</dt>
|
|
105
|
-
<dd>{note}</dd>
|
|
106
|
-
</div>
|
|
107
|
-
))}
|
|
108
|
-
</dl>
|
|
109
|
-
) : null}
|
|
110
|
-
{"body" in step && step.body ? <p>{step.body}</p> : null}
|
|
111
|
-
</div>
|
|
112
|
-
</li>
|
|
113
|
-
))}
|
|
114
|
-
</ol>
|
|
115
|
-
|
|
116
|
-
<div className="garden-setup-notes">
|
|
117
|
-
<p>
|
|
118
|
-
<strong>仓库可以是私有的。</strong>
|
|
119
|
-
公开仓库一种就够。想把草稿留在私有仓库时,用 <code>PAGES_REPOSITORY</code> 指向公开的页面仓库。两种都是 <code>make update</code>。
|
|
120
|
-
</p>
|
|
121
|
-
<p>
|
|
122
|
-
<strong>先看草稿。</strong>
|
|
123
|
-
<code>CONTENT_INCLUDE_DRAFTS=1 make dev</code> 会把草稿和还没到时间的文章也显示出来。
|
|
124
|
-
</p>
|
|
125
|
-
<p>
|
|
126
|
-
<strong>密钥不进仓库。</strong>
|
|
127
|
-
评论、统计和后台的密钥放在部署平台。
|
|
128
|
-
</p>
|
|
129
|
-
</div>
|
|
130
|
-
</section>
|
|
131
|
-
|
|
132
|
-
<GardenMediaGuide />
|
|
133
|
-
|
|
134
|
-
<section className="garden-after" aria-labelledby="garden-after-title">
|
|
135
|
-
<header className="garden-section-heading">
|
|
136
|
-
<h2 id="garden-after-title">推送之后</h2>
|
|
137
|
-
</header>
|
|
138
|
-
<p className="garden-after-lead">推送之后,网站公开更新。</p>
|
|
139
|
-
<div className="garden-after-copy">
|
|
140
|
-
<p>文章在你自己的仓库里。读者打开的是已经发布的页面。</p>
|
|
141
|
-
<p>一次更新会带上正文、目录、前后篇、搜索、RSS 和 sitemap。后台和评论都可以以后再加。</p>
|
|
142
|
-
</div>
|
|
143
|
-
</section>
|
|
144
|
-
|
|
145
|
-
<GardenAdminGuide />
|
|
146
|
-
</main>
|
|
147
|
-
);
|
|
13
|
+
return <HandbookOverview lang="zh" />;
|
|
148
14
|
}
|
package/app/garden-modules.d.ts
CHANGED
|
@@ -48,6 +48,24 @@ declare module "@garden/generated-content" {
|
|
|
48
48
|
export const posts: ContentEntry[];
|
|
49
49
|
export const columns: ContentEntry[];
|
|
50
50
|
export const thoughts: ContentEntry[];
|
|
51
|
+
export type GardenDocEntry = {
|
|
52
|
+
title: string;
|
|
53
|
+
slug: string;
|
|
54
|
+
path: string;
|
|
55
|
+
description?: string;
|
|
56
|
+
section?: string;
|
|
57
|
+
sectionTitle?: string;
|
|
58
|
+
order?: number;
|
|
59
|
+
readingTime?: string;
|
|
60
|
+
references?: { title: string; url?: string; domain?: string }[];
|
|
61
|
+
sourcePath: string;
|
|
62
|
+
content: string;
|
|
63
|
+
lang?: "zh" | "en";
|
|
64
|
+
};
|
|
65
|
+
export const gardenDocs: GardenDocEntry[];
|
|
66
|
+
export const gardenIndexDoc: GardenDocEntry | null;
|
|
67
|
+
export const gardenDocsEn: GardenDocEntry[];
|
|
68
|
+
export const gardenIndexDocEn: GardenDocEntry | null;
|
|
51
69
|
export const a2WordCounts: Record<string, number>;
|
|
52
70
|
export type LinkCardMeta = {
|
|
53
71
|
title: string;
|
package/app/globals.css
CHANGED
|
@@ -4828,14 +4828,14 @@ html[data-theme="dark"] .search-footer {
|
|
|
4828
4828
|
.garden-page,
|
|
4829
4829
|
.admin-shell,
|
|
4830
4830
|
.admin-access-page {
|
|
4831
|
-
--garden-ink:
|
|
4832
|
-
--garden-muted:
|
|
4833
|
-
--garden-stage:
|
|
4834
|
-
--garden-link:
|
|
4835
|
-
--garden-button:
|
|
4836
|
-
--garden-button-text:
|
|
4831
|
+
--garden-ink: var(--ink);
|
|
4832
|
+
--garden-muted: var(--muted);
|
|
4833
|
+
--garden-stage: var(--paper-deep);
|
|
4834
|
+
--garden-link: var(--ink);
|
|
4835
|
+
--garden-button: var(--ink);
|
|
4836
|
+
--garden-button-text: var(--paper);
|
|
4837
4837
|
color: var(--garden-ink);
|
|
4838
|
-
font-family:
|
|
4838
|
+
font-family: var(--sans);
|
|
4839
4839
|
}
|
|
4840
4840
|
|
|
4841
4841
|
:root[data-theme="dark"] .garden-page,
|
|
@@ -4844,9 +4844,9 @@ html[data-theme="dark"] .search-footer {
|
|
|
4844
4844
|
--garden-ink: var(--ink);
|
|
4845
4845
|
--garden-muted: var(--muted);
|
|
4846
4846
|
--garden-stage: var(--paper-deep);
|
|
4847
|
-
--garden-link:
|
|
4848
|
-
--garden-button:
|
|
4849
|
-
--garden-button-text:
|
|
4847
|
+
--garden-link: var(--ink);
|
|
4848
|
+
--garden-button: var(--ink);
|
|
4849
|
+
--garden-button-text: var(--paper);
|
|
4850
4850
|
}
|
|
4851
4851
|
|
|
4852
4852
|
.garden-page pre,
|
package/app/layout.tsx
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
import { githubUrl, siteConfig } from "./site.config";
|
|
14
14
|
import { brand } from "@garden/site-config";
|
|
15
15
|
import { FEED_ALTERNATES } from "./lib/page-alternates";
|
|
16
|
+
import { htmlLang, siteLang } from "./lib/i18n";
|
|
16
17
|
|
|
17
18
|
export async function generateMetadata(): Promise<Metadata> {
|
|
18
19
|
const siteUrl = await getSiteUrl();
|
|
@@ -75,7 +76,7 @@ export default function RootLayout({
|
|
|
75
76
|
"https://plausible.io/js/script.js";
|
|
76
77
|
|
|
77
78
|
return (
|
|
78
|
-
<html lang=
|
|
79
|
+
<html lang={htmlLang(siteLang)} suppressHydrationWarning>
|
|
79
80
|
<head>
|
|
80
81
|
<script
|
|
81
82
|
dangerouslySetInnerHTML={{
|
|
@@ -93,9 +94,6 @@ export default function RootLayout({
|
|
|
93
94
|
)}
|
|
94
95
|
</head>
|
|
95
96
|
<body>
|
|
96
|
-
<a className="skip-link" href="#main-content">
|
|
97
|
-
跳到正文
|
|
98
|
-
</a>
|
|
99
97
|
<SiteChrome>{children}</SiteChrome>
|
|
100
98
|
</body>
|
|
101
99
|
</html>
|