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.
Files changed (123) hide show
  1. package/.agents/skills/garden-ui/SKILL.md +26 -19
  2. package/README.en.md +57 -0
  3. package/README.md +31 -46
  4. package/app/admin/preview/[...path]/page.tsx +1 -1
  5. package/app/blog/[...path]/page.tsx +11 -3
  6. package/app/columns/[column]/[...path]/page.tsx +12 -14
  7. package/app/components/ArticleMeasure.tsx +39 -4
  8. package/app/components/ArticlePager.tsx +32 -0
  9. package/app/components/Comments.tsx +2 -1
  10. package/app/components/FeedMore.tsx +70 -0
  11. package/app/components/GardenDocsNav.tsx +189 -0
  12. package/app/components/HandbookLangRedirect.tsx +30 -0
  13. package/app/components/HandbookLangSwitch.tsx +49 -0
  14. package/app/components/HandbookView.tsx +187 -0
  15. package/app/components/MarkdownArticle.tsx +15 -8
  16. package/app/components/MarkdownImage.tsx +6 -4
  17. package/app/components/SiteChrome.tsx +11 -2
  18. package/app/components/SiteFooter.tsx +12 -3
  19. package/app/components/SiteHeader.tsx +27 -23
  20. package/app/components/TableOfContents.tsx +15 -9
  21. package/app/components/ThoughtFeed.tsx +41 -0
  22. package/app/components/UiLang.tsx +18 -0
  23. package/app/components/Webmentions.tsx +3 -2
  24. package/app/components/garden/FilePreview.tsx +13 -11
  25. package/app/components/garden/GardenBlock.tsx +3 -1
  26. package/app/components/garden/GardenFile.tsx +9 -7
  27. package/app/components/garden/blocks.tsx +34 -24
  28. package/app/components/garden/chrome.tsx +20 -13
  29. package/app/garden/[...slug]/page.tsx +28 -0
  30. package/app/garden/en/[...slug]/page.tsx +28 -0
  31. package/app/garden/en/page.tsx +16 -0
  32. package/app/garden/page.tsx +7 -141
  33. package/app/garden-modules.d.ts +18 -0
  34. package/app/globals.css +10 -10
  35. package/app/layout.tsx +2 -4
  36. package/app/lib/content.ts +27 -11
  37. package/app/lib/garden-docs-meta.ts +138 -0
  38. package/app/lib/handbook-path.ts +11 -0
  39. package/app/lib/heading-number.ts +13 -0
  40. package/app/lib/i18n.ts +222 -0
  41. package/app/lib/page-alternates.ts +2 -2
  42. package/app/not-found.tsx +5 -3
  43. package/app/site.config.ts +1 -1
  44. package/app/styles/a2.css +613 -13
  45. package/app/styles/shell.css +6 -0
  46. package/app/thoughts/page/[n]/page.tsx +44 -0
  47. package/app/thoughts/page.tsx +2 -6
  48. package/bin/garden.mjs +4 -0
  49. package/docs/handbook/ai-writing.md +99 -0
  50. package/docs/handbook/assets/reading-layout.svg +26 -0
  51. package/docs/handbook/components/card.md +46 -0
  52. package/docs/handbook/components/chart.md +54 -0
  53. package/docs/handbook/components/compare.md +38 -0
  54. package/docs/handbook/components/figure.md +72 -0
  55. package/docs/handbook/components/file/checklist.md +17 -0
  56. package/docs/handbook/components/file.md +34 -0
  57. package/docs/handbook/components/html.md +69 -0
  58. package/docs/handbook/components/interactive.md +67 -0
  59. package/docs/handbook/components/stat.md +57 -0
  60. package/docs/handbook/components/timeline.md +52 -0
  61. package/docs/handbook/components.md +30 -0
  62. package/docs/handbook/config.md +125 -0
  63. package/docs/handbook/deploy.md +273 -0
  64. package/docs/handbook/design.md +81 -0
  65. package/docs/handbook/en/ai-writing.md +99 -0
  66. package/docs/handbook/en/components/card.md +46 -0
  67. package/docs/handbook/en/components/chart.md +54 -0
  68. package/docs/handbook/en/components/compare.md +38 -0
  69. package/docs/handbook/en/components/figure.md +72 -0
  70. package/docs/handbook/en/components/file/checklist.md +17 -0
  71. package/docs/handbook/en/components/file.md +34 -0
  72. package/docs/handbook/en/components/html.md +69 -0
  73. package/docs/handbook/en/components/interactive.md +67 -0
  74. package/docs/handbook/en/components/stat.md +57 -0
  75. package/docs/handbook/en/components/timeline.md +52 -0
  76. package/docs/handbook/en/components.md +30 -0
  77. package/docs/handbook/en/config.md +125 -0
  78. package/docs/handbook/en/deploy.md +273 -0
  79. package/docs/handbook/en/design.md +81 -0
  80. package/docs/handbook/en/index.md +192 -0
  81. package/docs/handbook/en/start.md +92 -0
  82. package/docs/handbook/en/workflow.md +81 -0
  83. package/docs/handbook/en/writing.md +156 -0
  84. package/docs/handbook/index.md +187 -0
  85. package/docs/handbook/start.md +92 -0
  86. package/docs/handbook/workflow.md +81 -0
  87. package/docs/handbook/writing.md +156 -0
  88. package/package.json +2 -1
  89. package/scripts/build-content.mjs +144 -15
  90. package/scripts/handbook-allowlist.mjs +68 -0
  91. package/scripts/handbook-facts.mjs +1138 -0
  92. package/scripts/html-lang.mjs +36 -0
  93. package/scripts/static-404.mjs +25 -0
  94. package/scripts/ui-cli.mjs +14 -8
  95. package/site.config.yaml +2 -2
  96. package/templates/garden-blocks.md +1 -1
  97. package/templates/site/package.json +1 -3
  98. package/templates/site/site.config.yaml +2 -0
  99. package/ui/core/apply.mjs +22 -4
  100. package/ui/core/cli-locale.mjs +67 -0
  101. package/ui/core/fence.mjs +18 -3
  102. package/ui/core/fix-prompt.mjs +18 -15
  103. package/ui/core/garden-fence.mjs +64 -0
  104. package/ui/core/scan.mjs +19 -3
  105. package/ui/garden/adjacent.mjs +21 -0
  106. package/ui/garden/catalog.mjs +1 -1
  107. package/ui/garden/check.mjs +6 -0
  108. package/ui/garden/html-lang.mjs +16 -0
  109. package/ui/garden/paging.mjs +30 -0
  110. package/ui/preview/dist/garden-ui.css +9 -9
  111. package/ui/preview/dist/garden-ui.esm.js +169 -169
  112. package/ui/preview/dist/garden-ui.iife.js +169 -169
  113. package/ui/react/components/chart.tsx +7 -4
  114. package/ui/react/components/display.tsx +6 -3
  115. package/ui/react/components/inputs.tsx +6 -3
  116. package/ui/react/components/layout.tsx +6 -4
  117. package/ui/react/components/media.tsx +7 -4
  118. package/ui/react/components/sandbox.tsx +3 -1
  119. package/ui/react/index.tsx +11 -7
  120. package/ui/react/lang.tsx +85 -0
  121. package/ui/react/runtime.tsx +3 -1
  122. package/ui/react/ui.css +9 -9
  123. 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 { stringify } from "yaml";
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 title = String(props.title ?? "图表");
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>查看数据表</summary>
207
+ <summary>{t.dataTable}</summary>
205
208
  <table>
206
- <thead><tr><th>{String(props.xLabel ?? (typeof props.x === "string" ? props.x : "项目"))}</th><th>{String(props.yLabel ?? "数值")}</th></tr></thead>
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>): Part[] {
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 ?? `部分 ${index + 1}`);
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 parts = partsOf(props);
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="结构图">{body}</FullscreenFrame> : body;
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")} 字节` : String(Math.round(result * 1e4) / 1e4)}`;
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">HTML 在 {props.src}。发布时由同名目录读入。</p>;
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 header = {
503
- id: block.id || block.props.id || "interactive",
504
- caption: block.props.caption ?? "",
505
- intent: block.props.intent ?? "",
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
- <FullscreenFrame label={String(header.caption || "交互")}>
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">想法 · 发布前编译</p>
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
- return <p className="g-embed-note">未知 Garden 块:{name}</p>;
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 = "复制代码" }: { getText: () => string; label?: string }) {
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 ? "已复制" : label}
60
- title={done ? "已复制" : label}
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 ? "已复制" : COPY_ICON}
74
+ {done ? t.copied : COPY_ICON}
71
75
  </button>
72
- <span className="ux-live" aria-live="polite">{done ? "已复制到剪贴板" : ""}</span>
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" ? "(新增)" : kind === "del" ? "(删除)" : "";
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 tabs = ["代码", "对比上一版"];
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 = "演示" }: { children: ReactNode; label?: string }) {
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
+ }
@@ -1,148 +1,14 @@
1
- import { ArrowRight, ArrowUpRight, GithubLogo } from "@phosphor-icons/react/ssr";
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: "Garden",
11
- description: "用 Markdown 写文章。推送之后,页面、搜索和 RSS 一起更新。",
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>&lt;owner&gt;.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
  }
@@ -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: #1d1d1f;
4832
- --garden-muted: #6e6e73;
4833
- --garden-stage: #f5f5f7;
4834
- --garden-link: #0071e3;
4835
- --garden-button: #1d1d1f;
4836
- --garden-button-text: #fff;
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: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", sans-serif;
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: #8ab4f8;
4848
- --garden-button: #f5f5f7;
4849
- --garden-button-text: #1d1d1f;
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="zh-CN" suppressHydrationWarning>
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>