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
@@ -14,9 +14,11 @@ import type Fuse from "fuse.js";
14
14
  import { MagnifyingGlass, X } from "@phosphor-icons/react";
15
15
  import { brand, searchFull, searchIndexUrl } from "@garden/site-config";
16
16
  import { createSearch } from "../../ui/garden/search-match.mjs";
17
- import { cropMatchedText, highlightParts, noResultsText } from "../../ui/garden/search-preview.mjs";
17
+ import { cropMatchedText, highlightParts } from "../../ui/garden/search-preview.mjs";
18
18
  import { resolveDark, themeSwitchProps } from "../../ui/garden/theme.mjs";
19
19
  import { SITE_NAV, isCurrentNav } from "../../ui/garden/site-nav.mjs";
20
+ import { routeLang, ui } from "../lib/i18n";
21
+ import { HandbookLangSwitch } from "./HandbookLangSwitch";
20
22
  import { createIdbStore, loadFullIndex, saveDataOn, whenIdleAfterLoad } from "../../ui/garden/search-full.mjs";
21
23
  import { siteConfig } from "../site.config";
22
24
  import { siteHref } from "../lib/site-href";
@@ -87,7 +89,7 @@ function loadSearchEngine() {
87
89
  return engineLoad;
88
90
  }
89
91
 
90
- const nav = SITE_NAV.map((item) => ({ ...item, href: siteHref(item.href) }));
92
+ const nav = SITE_NAV.map((item) => ({ ...item, key: item.href, href: siteHref(item.href) }));
91
93
 
92
94
  function rangesFor(
93
95
  matches: readonly SearchMatch[] | undefined,
@@ -140,6 +142,7 @@ function searchPreview(
140
142
 
141
143
  export function SiteHeader() {
142
144
  const pathname = usePathname() || "/";
145
+ const t = ui(routeLang(pathname));
143
146
  const [menuOpen, setMenuOpen] = useState(false);
144
147
  const [searchOpen, setSearchOpen] = useState(false);
145
148
  const [query, setQuery] = useState("");
@@ -313,29 +316,30 @@ export function SiteHeader() {
313
316
  {brand.logo ? <span className="sh-mark" aria-hidden="true" dangerouslySetInnerHTML={{ __html: brand.logo }} /> : null}
314
317
  {siteConfig.name}
315
318
  </Link>
316
- <nav className="sh-nav" aria-label="站点导航">
319
+ <nav className="sh-nav" aria-label={t.siteNav}>
317
320
  {nav.map((item) => (
318
321
  <Link key={item.href} href={item.href} aria-current={current(item.href) ? "page" : undefined}>
319
- {item.label}
322
+ {t.navLabels[item.key] ?? item.label}
320
323
  </Link>
321
324
  ))}
322
325
  </nav>
323
326
  <div className="sh-tools">
324
- <button ref={searchTriggerRef} className="sh-search" type="button" onClick={openSearch} onPointerEnter={prefetchSearch} onFocus={prefetchSearch} aria-label="搜索文章" aria-expanded={searchOpen} aria-controls="site-search-dialog">
327
+ <button ref={searchTriggerRef} className="sh-search" type="button" onClick={openSearch} onPointerEnter={prefetchSearch} onFocus={prefetchSearch} aria-label={t.searchArticles} aria-expanded={searchOpen} aria-controls="site-search-dialog">
325
328
  <svg viewBox="0 0 20 20" aria-hidden="true">
326
329
  <circle cx="9" cy="9" r="5.8" />
327
330
  <path d="M13.3 13.3 17 17" />
328
331
  </svg>
329
- <span className="lbl">搜索</span>
332
+ <span className="lbl">{t.search}</span>
330
333
  <kbd><span className="kbd-mod kbd-mac">⌘</span><span className="kbd-mod kbd-other">Ctrl</span>{" "}K</kbd>
331
334
  </button>
332
- <button className="sh-icon sh-search-m" type="button" onClick={openSearch} onPointerDown={prefetchSearch} aria-label="搜索文章">
335
+ <button className="sh-icon sh-search-m" type="button" onClick={openSearch} onPointerDown={prefetchSearch} aria-label={t.searchArticles}>
333
336
  <svg viewBox="0 0 20 20" aria-hidden="true">
334
337
  <circle cx="9" cy="9" r="5.8" />
335
338
  <path d="M13.3 13.3 17 17" />
336
339
  </svg>
337
340
  </button>
338
- <button className="sh-icon sh-theme" type="button" onClick={toggleTheme} aria-label={dark ? "切换到浅色模式" : "切换到深色模式"}>
341
+ {pathname?.startsWith("/garden") ? <HandbookLangSwitch /> : null}
342
+ <button className="sh-icon sh-theme" type="button" onClick={toggleTheme} aria-label={dark ? t.toLight : t.toDark}>
339
343
  <svg className="i-moon" viewBox="0 0 20 20" aria-hidden="true">
340
344
  <path d="M16.5 12.2A6.8 6.8 0 0 1 7.8 3.5a6.8 6.8 0 1 0 8.7 8.7Z" />
341
345
  </svg>
@@ -344,27 +348,27 @@ export function SiteHeader() {
344
348
  <path d="M10 1.8v2M10 16.2v2M1.8 10h2M16.2 10h2M4.2 4.2l1.4 1.4M14.4 14.4l1.4 1.4M4.2 15.8l1.4-1.4M14.4 5.6l1.4-1.4" />
345
349
  </svg>
346
350
  </button>
347
- <button className="sh-icon sh-menu-btn" type="button" aria-expanded={menuOpen} aria-controls="sh-menu" aria-label={menuOpen ? "关闭菜单" : "打开菜单"} onClick={() => setMenuOpen((open) => !open)}>
351
+ <button className="sh-icon sh-menu-btn" type="button" aria-expanded={menuOpen} aria-controls="sh-menu" aria-label={menuOpen ? t.closeMenu : t.openMenu} onClick={() => setMenuOpen((open) => !open)}>
348
352
  {menuOpen ? <X size={18} /> : <span aria-hidden="true">☰</span>}
349
353
  </button>
350
354
  {/* Without JavaScript the button above cannot open anything: these two links take its place
351
355
  and open or close the menu through :target on the fixed anchors above (shell.css). */}
352
- <a className="sh-icon sh-menu-nojs" id="sh-menu-open" href="#sh-menu-on" aria-label="打开菜单">
356
+ <a className="sh-icon sh-menu-nojs" id="sh-menu-open" href="#sh-menu-on" aria-label={t.openMenu}>
353
357
  <span aria-hidden="true">☰</span>
354
358
  </a>
355
- <a className="sh-icon sh-menu-nojs-close" href="#sh-menu-off" aria-label="关闭菜单">
359
+ <a className="sh-icon sh-menu-nojs-close" href="#sh-menu-off" aria-label={t.closeMenu}>
356
360
  <X size={18} />
357
361
  </a>
358
362
  </div>
359
363
  </div>
360
- <nav className={`sh-menu${menuOpen ? " is-open" : ""}`} id="sh-menu" aria-label="站点导航(移动端)">
364
+ <nav className={`sh-menu${menuOpen ? " is-open" : ""}`} id="sh-menu" aria-label={t.siteNavMobile}>
361
365
  {nav.map((item) => (
362
366
  <Link key={item.href} href={item.href} aria-current={current(item.href) ? "page" : undefined} onClick={() => setMenuOpen(false)}>
363
- {item.label}
367
+ {t.navLabels[item.key] ?? item.label}
364
368
  </Link>
365
369
  ))}
366
370
  <button className="sh-menu-theme" {...themeSwitchProps(dark, toggleTheme)}>
367
- <span>深色模式</span>
371
+ <span>{t.darkMode}</span>
368
372
  <span className="sh-switch" aria-hidden="true" />
369
373
  </button>
370
374
  </nav>
@@ -388,7 +392,7 @@ export function SiteHeader() {
388
392
  onKeyDown={handleSearchKeyDown}
389
393
  >
390
394
  <h2 className="sr-only" id="site-search-title">
391
- 搜索站内内容
395
+ {t.searchTitle}
392
396
  </h2>
393
397
  <div className="search-input-wrap">
394
398
  <MagnifyingGlass size={20} aria-hidden="true" />
@@ -400,8 +404,8 @@ export function SiteHeader() {
400
404
  setActiveResult(-1);
401
405
  resultRefs.current = [];
402
406
  }}
403
- placeholder="搜索标题、主题或正文…"
404
- aria-label="模糊搜索"
407
+ placeholder={t.searchPlaceholder}
408
+ aria-label={t.searchInput}
405
409
  role="combobox"
406
410
  aria-expanded="true"
407
411
  aria-autocomplete="list"
@@ -410,7 +414,7 @@ export function SiteHeader() {
410
414
  activeResult >= 0 ? `site-search-result-${activeResult}` : undefined
411
415
  }
412
416
  />
413
- <button onClick={closeSearch} aria-label="关闭搜索">
417
+ <button onClick={closeSearch} aria-label={t.closeSearch}>
414
418
  <X size={19} />
415
419
  </button>
416
420
  </div>
@@ -418,11 +422,11 @@ export function SiteHeader() {
418
422
  className="search-results"
419
423
  id="site-search-results"
420
424
  role="listbox"
421
- aria-label="搜索结果"
425
+ aria-label={t.searchResults}
422
426
  >
423
427
  {query && engine && resultTotal === 0 ? null : (
424
428
  <p className="search-label">
425
- {query ? `${resultTotal} 篇相关文章` : "最近内容"}
429
+ {query ? t.resultCount(resultTotal) : t.recent}
426
430
  </p>
427
431
  )}
428
432
  {results.map((result, index) => {
@@ -464,13 +468,13 @@ export function SiteHeader() {
464
468
  {results.length === 0 && (
465
469
  <p className="empty-state">
466
470
  {/* The query is a React text child, so it is escaped. */}
467
- {engine ? noResultsText(query) : engineFailed ? "搜索暂时打不开,请稍后再试。" : "正在载入…"}
471
+ {engine ? t.noResults(query.trim()) : engineFailed ? t.searchFailed : t.loading}
468
472
  </p>
469
473
  )}
470
474
  </div>
471
475
  <footer className="search-footer">
472
- <span>支持模糊匹配</span>
473
- <span><kbd>ESC</kbd> 关闭</span>
476
+ <span>{t.fuzzy}</span>
477
+ <span><kbd>ESC</kbd> {t.escToClose}</span>
474
478
  </footer>
475
479
  </section>
476
480
  </div>
@@ -10,6 +10,7 @@ import {
10
10
  type ReactNode,
11
11
  } from "react";
12
12
  import { List, X } from "@phosphor-icons/react";
13
+ import { ui, type UiLang } from "../lib/i18n";
13
14
 
14
15
  type Heading = { depth: number; text: string; id: string; no?: string };
15
16
 
@@ -115,11 +116,16 @@ const scrollToHeading = (id: string) => {
115
116
 
116
117
  export function TableOfContents({
117
118
  headings,
118
- label = "本篇目录",
119
+ label,
120
+ lang,
119
121
  }: {
120
122
  headings: Heading[];
121
123
  label?: string;
124
+ /** Defaults to the site language; the bilingual handbook passes its own. */
125
+ lang?: UiLang;
122
126
  }) {
127
+ const t = ui(lang);
128
+ label ??= t.toc;
123
129
  const [activeId, setActiveId] = useState(headings[0]?.id);
124
130
  const [collapsedSections, setCollapsedSections] = useState<Set<string>>(
125
131
  () => new Set(),
@@ -368,7 +374,7 @@ export function TableOfContents({
368
374
  type="button"
369
375
  aria-controls={childListId}
370
376
  aria-expanded={!collapsed}
371
- aria-label={`${collapsed ? "展开" : "收起"}「${node.text}」的子目录`}
377
+ aria-label={t.tocToggle(collapsed, node.text)}
372
378
  onClick={() => toggleSection(node.id)}
373
379
  >
374
380
  <span aria-hidden="true">{collapsed ? "+" : "−"}</span>
@@ -396,25 +402,25 @@ export function TableOfContents({
396
402
  type="button"
397
403
  aria-controls={panelId}
398
404
  aria-expanded={mobileOpen}
399
- aria-label={`打开${label}${activeHeading ? `,当前章节:${activeHeading.text}` : ""}`}
405
+ aria-label={`${t.open}${label}${activeHeading ? `${t.currentSection}${activeHeading.text}` : ""}`}
400
406
  tabIndex={mobileOpen ? -1 : 0}
401
407
  data-mobile-open={mobileOpen}
402
408
  onClick={() => setMobileOpen(true)}
403
409
  >
404
410
  <List size={17} weight="bold" aria-hidden="true" />
405
- <span>目录</span>
411
+ <span>{t.tocShort}</span>
406
412
  </button>
407
413
  {/* Without JavaScript the button above does nothing. This link opens the
408
414
  drawer through :target instead; CSS shows it only when scripting is
409
415
  off, so with JavaScript nothing here is visible. */}
410
- <a className="toc-nojs-trigger" id={`${panelId}-open`} href={`#${panelId}`} aria-label={`打开${label}`}>
416
+ <a className="toc-nojs-trigger" id={`${panelId}-open`} href={`#${panelId}`} aria-label={`${t.open}${label}`}>
411
417
  <List size={17} weight="bold" aria-hidden="true" />
412
- <span>目录</span>
418
+ <span>{t.tocShort}</span>
413
419
  </a>
414
420
  <button
415
421
  className="toc-mobile-backdrop"
416
422
  type="button"
417
- aria-label={`关闭${label}`}
423
+ aria-label={`${t.close}${label}`}
418
424
  tabIndex={mobileOpen ? 0 : -1}
419
425
  data-mobile-open={mobileOpen}
420
426
  onClick={() => closeMobileToc(true)}
@@ -431,12 +437,12 @@ export function TableOfContents({
431
437
  ref={mobileCloseRef}
432
438
  className="toc-mobile-close"
433
439
  type="button"
434
- aria-label={`关闭${label}`}
440
+ aria-label={`${t.close}${label}`}
435
441
  onClick={() => closeMobileToc(true)}
436
442
  >
437
443
  <X size={18} aria-hidden="true" />
438
444
  </button>
439
- <a className="toc-nojs-close" href={`#${panelId}-open`} aria-label={`关闭${label}`}>
445
+ <a className="toc-nojs-close" href={`#${panelId}-open`} aria-label={`${t.close}${label}`}>
440
446
  <X size={18} aria-hidden="true" />
441
447
  </a>
442
448
  </div>
@@ -0,0 +1,41 @@
1
+ import Link from "next/link";
2
+ import { ThoughtCard } from "./ThoughtCard";
3
+ import { FeedMore } from "./FeedMore";
4
+ import { getPublishedThoughts } from "../lib/public-thoughts";
5
+ import { ui } from "../lib/i18n";
6
+ import { siteHref } from "../lib/site-href";
7
+ import { siteConfig } from "../site.config";
8
+ import { pageCount, pageItems, pagePath, pageSizeOf } from "../../ui/garden/paging.mjs";
9
+
10
+ export const thoughtsPageSize = () => pageSizeOf(siteConfig.pages.thoughts.pageSize);
11
+ export const thoughtsPageCount = () => pageCount(getPublishedThoughts().length, thoughtsPageSize());
12
+ export const thoughtsPageHref = (page: number) => siteHref(pagePath("/thoughts", page));
13
+
14
+ /** One page of 随想 and the link (or automatic loading) to the next. */
15
+ export function ThoughtFeed({ page }: { page: number }) {
16
+ const t = ui();
17
+ const all = getPublishedThoughts();
18
+ const total = thoughtsPageCount();
19
+ const items = pageItems(all, page, thoughtsPageSize());
20
+ const next = page < total ? thoughtsPageHref(page + 1) : null;
21
+ return (
22
+ <>
23
+ <div className="thought-stream" data-feed-page={page}>
24
+ {items.map((thought) => (
25
+ <ThoughtCard key={thought.slug} thought={thought} />
26
+ ))}
27
+ </div>
28
+ {page > 1 ? (
29
+ <p className="feed-prev">
30
+ <Link href={thoughtsPageHref(page - 1)} rel="prev">{t.prevPage}</Link>
31
+ <span>{t.pageOf(page, total)}</span>
32
+ </p>
33
+ ) : null}
34
+ <FeedMore
35
+ next={next}
36
+ streamSelector=".thought-stream"
37
+ labels={{ nextPage: t.nextPage, loadingMore: t.loadingMore, loadFailed: t.loadFailed, feedEnd: t.feedEnd }}
38
+ />
39
+ </>
40
+ );
41
+ }
@@ -0,0 +1,18 @@
1
+ "use client";
2
+
3
+ import { createContext, useContext, type ReactNode } from "react";
4
+ import { siteLang, ui, type UiLang } from "../lib/i18n";
5
+
6
+ /**
7
+ * The language of the framework chrome inside a page body (copy buttons, code
8
+ * tabs, file cards...). It is the site language everywhere except the /garden/
9
+ * handbook, whose pages set it from their own route (/garden/en/ is English).
10
+ */
11
+ const UiLangContext = createContext<UiLang>(siteLang);
12
+
13
+ export function UiLangProvider({ lang, children }: { lang?: UiLang; children: ReactNode }) {
14
+ return <UiLangContext.Provider value={lang ?? siteLang}>{children}</UiLangContext.Provider>;
15
+ }
16
+
17
+ export const useUiLang = () => useContext(UiLangContext);
18
+ export const useUi = () => ui(useContext(UiLangContext));
@@ -8,6 +8,7 @@ import {
8
8
  Quotes,
9
9
  Repeat,
10
10
  } from "@phosphor-icons/react";
11
+ import { ui } from "../lib/i18n";
11
12
 
12
13
  type WebmentionEntry = {
13
14
  author?: {
@@ -93,8 +94,8 @@ export function Webmentions({
93
94
  <div className="webmention-title">
94
95
  <LinkSimple size={21} />
95
96
  <div>
96
- <h2 id="webmentions-heading">来自开放网络的回应</h2>
97
- <p>引用、喜欢、转发和站外回复会通过 Webmention 回到这里。</p>
97
+ <h2 id="webmentions-heading">{ui().webmentions}</h2>
98
+ <p>{ui().webmentionsLead}</p>
98
99
  </div>
99
100
  </div>
100
101
 
@@ -2,6 +2,7 @@
2
2
 
3
3
  import { useCallback, useEffect, useId, useRef, useState, type FocusEvent, type MouseEvent } from "react";
4
4
  import { createPortal } from "react-dom";
5
+ import { ui, type UiLang } from "../../lib/i18n";
5
6
  import { previewBody, previewFrameProps } from "../../../ui/garden/file-block.mjs";
6
7
  import { ActionGlyph, FileGlyph } from "./file-icons";
7
8
 
@@ -25,7 +26,8 @@ type Loaded = { state: "idle" | "loading" | "error" } | { state: "ready"; html:
25
26
  * The control is a link: without JavaScript it opens the same preview (or the
26
27
  * file) in a new tab, next to the card's download link.
27
28
  */
28
- export function FilePreview({ file, compact }: { file: PreviewFile; compact: boolean }) {
29
+ export function FilePreview({ file, compact, lang }: { file: PreviewFile; compact: boolean; lang?: UiLang }) {
30
+ const t = ui(lang);
29
31
  const [open, setOpen] = useState(false);
30
32
  const [loaded, setLoaded] = useState<Loaded>({ state: "idle" });
31
33
  const trigger = useRef<HTMLAnchorElement>(null);
@@ -130,13 +132,13 @@ export function FilePreview({ file, compact }: { file: PreviewFile; compact: boo
130
132
  {file.meta ? <div className="gf-meta">{file.meta}</div> : null}
131
133
  </div>
132
134
  <div className="gf-act">
133
- <a className="gf-btn icon" href={file.url} download={file.name} aria-label={`下载 ${file.name}`} title="下载">
135
+ <a className="gf-btn icon" href={file.url} download={file.name} aria-label={t.downloadNamed(file.name)} title={t.download}>
134
136
  <ActionGlyph name="download" />
135
137
  </a>
136
- <a className="gf-btn icon" href={file.url} target="_blank" rel="noopener noreferrer" aria-label={`在新标签页打开 ${file.name}`} title="在新标签页打开">
138
+ <a className="gf-btn icon" href={file.url} target="_blank" rel="noopener noreferrer" aria-label={t.openNamedInTab(file.name)} title={t.openInTab}>
137
139
  <ActionGlyph name="external" />
138
140
  </a>
139
- <button ref={closeButton} type="button" className="gf-btn icon" onClick={close} aria-label="关闭预览" title="关闭">
141
+ <button ref={closeButton} type="button" className="gf-btn icon" onClick={close} aria-label={t.closePreview} title={ui(lang).close.trim()}>
140
142
  <ActionGlyph name="close" />
141
143
  </button>
142
144
  </div>
@@ -147,14 +149,14 @@ export function FilePreview({ file, compact }: { file: PreviewFile; compact: boo
147
149
  <div className="markdown-body prose gf-doc" dangerouslySetInnerHTML={{ __html: loaded.html }} />
148
150
  ) : loaded.state === "error" ? (
149
151
  <div className="gf-state" role="alert">
150
- <p>预览没能载入。</p>
152
+ <p>{t.previewFailed}</p>
151
153
  <div className="gf-state-act">
152
- <button type="button" className="gf-btn" onClick={() => load()}>重试</button>
153
- <a className="gf-btn" href={file.url} download={file.name}>下载文件</a>
154
+ <button type="button" className="gf-btn" onClick={() => load()}>{t.retry}</button>
155
+ <a className="gf-btn" href={file.url} download={file.name}>{t.downloadFile}</a>
154
156
  </div>
155
157
  </div>
156
158
  ) : (
157
- <div className="gf-state" role="status">正在载入预览…</div>
159
+ <div className="gf-state" role="status">{t.previewLoading}</div>
158
160
  )}
159
161
  </div>
160
162
  ) : (
@@ -165,7 +167,7 @@ export function FilePreview({ file, compact }: { file: PreviewFile; compact: boo
165
167
  <span tabIndex={0} className="gf-sentinel" data-gf-sentinel="after" onFocus={fromAfter} />
166
168
  </div>
167
169
  )}
168
- <p className="gf-hint">Esc 关闭</p>
170
+ <p className="gf-hint">{t.escClose}</p>
169
171
  </aside>
170
172
  </div>,
171
173
  document.body,
@@ -183,10 +185,10 @@ export function FilePreview({ file, compact }: { file: PreviewFile; compact: boo
183
185
  data-compact={compact ? "true" : undefined}
184
186
  onClick={openDrawer}
185
187
  aria-haspopup="dialog"
186
- aria-label={`预览 ${file.name}`}
188
+ aria-label={t.previewNamed(file.name)}
187
189
  >
188
190
  <ActionGlyph name="eye" />
189
- <span className="gf-lb">预览</span>
191
+ <span className="gf-lb">{t.preview}</span>
190
192
  </a>
191
193
  {drawer}
192
194
  </>
@@ -1,5 +1,6 @@
1
1
  "use client";
2
2
 
3
+ import { useUiLang } from "../UiLang";
3
4
  import { readGardenPayload } from "../../lib/remark-garden.mjs";
4
5
  import {
5
6
  GardenCard,
@@ -17,6 +18,7 @@ import {
17
18
  import { GardenFile } from "./GardenFile";
18
19
 
19
20
  export function GardenBlock({ dataPayload }: { dataPayload?: string }) {
21
+ const lang = useUiLang();
20
22
  const block = readGardenPayload(dataPayload);
21
23
  if (!block) return null;
22
24
  if (block.legacy && block.suggestion) return <GardenLegacy suggestion={String(block.suggestion)} />;
@@ -42,7 +44,7 @@ export function GardenBlock({ dataPayload }: { dataPayload?: string }) {
42
44
  return <GardenInteractive block={{ id: block.id, props, children: block.children }} />;
43
45
  case "file":
44
46
  // Post bodies render file cards on the server (MarkdownArticle); this path has no Markdown preview.
45
- return <GardenFile props={props} />;
47
+ return <GardenFile props={props} lang={lang} />;
46
48
  default:
47
49
  return <GardenUnknown name={String(block.name)} />;
48
50
  }
@@ -1,4 +1,5 @@
1
1
  // Server component: the card for `garden file`. Only the 预览 control is a client island.
2
+ import { ui, type UiLang } from "../../lib/i18n";
2
3
  import { blockFiles, fileMeta } from "../../../ui/garden/file-block.mjs";
3
4
  import { ActionGlyph, FileGlyph, safeFileHref } from "./file-icons";
4
5
  import { FilePreview, type PreviewFile } from "./FilePreview";
@@ -19,7 +20,8 @@ type FileEntry = {
19
20
 
20
21
  const PREVIEWS = new Set(["md", "html", "pdf"]);
21
22
 
22
- export function GardenFile({ props }: { props: Record<string, unknown> }) {
23
+ export function GardenFile({ props, lang }: { props: Record<string, unknown>; lang?: UiLang }) {
24
+ const t = ui(lang);
23
25
  const block = blockFiles(props) as { layout?: string; title?: string; files: FileEntry[] };
24
26
  const files = block.files.filter((file) => safeFileHref(file.url));
25
27
  if (!files.length) return null;
@@ -29,7 +31,7 @@ export function GardenFile({ props }: { props: Record<string, unknown> }) {
29
31
  {group && block.title ? <div className="gf-title">{block.title}</div> : null}
30
32
  {files.map((file, index) => {
31
33
  const href = safeFileHref(file.url);
32
- const name = file.name || file.title || "文件";
34
+ const name = file.name || file.title || t.file;
33
35
  const title = file.title || name;
34
36
  const meta = fileMeta(file);
35
37
  const previewSrc = file.preview === "md" ? safeFileHref(file.previewSrc) : "";
@@ -44,20 +46,20 @@ export function GardenFile({ props }: { props: Record<string, unknown> }) {
44
46
  {meta ? <div className="gf-meta">{meta}</div> : null}
45
47
  </div>
46
48
  <div className="gf-act">
47
- {previewFile ? <FilePreview file={previewFile} compact={group} /> : null}
49
+ {previewFile ? <FilePreview file={previewFile} compact={group} lang={lang} /> : null}
48
50
  {file.remote ? (
49
- <a className="gf-btn icon" href={href} target="_blank" rel="noopener noreferrer" aria-label={`在新标签页打开 ${name}`} title="在新标签页打开">
51
+ <a className="gf-btn icon" href={href} target="_blank" rel="noopener noreferrer" aria-label={t.openNamedInTab(name)} title={t.openInTab}>
50
52
  <ActionGlyph name="external" />
51
53
  </a>
52
54
  ) : null}
53
55
  {group ? (
54
- <a className="gf-btn icon" href={href} download={file.remote ? undefined : name} aria-label={`下载 ${name}`} title="下载">
56
+ <a className="gf-btn icon" href={href} download={file.remote ? undefined : name} aria-label={t.downloadNamed(name)} title={t.download}>
55
57
  <ActionGlyph name="download" />
56
58
  </a>
57
59
  ) : (
58
- <a className="gf-btn pri" href={href} download={file.remote ? undefined : name} aria-label={`下载 ${name}`}>
60
+ <a className="gf-btn pri" href={href} download={file.remote ? undefined : name} aria-label={t.downloadNamed(name)}>
59
61
  <ActionGlyph name="download" />
60
- <span className="gf-lb">下载</span>
62
+ <span className="gf-lb">{t.download}</span>
61
63
  </a>
62
64
  )}
63
65
  </div>