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
|
@@ -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
|
|
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=
|
|
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"
|
|
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
|
-
|
|
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 ?
|
|
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
|
|
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 ?
|
|
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 ?
|
|
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
|
|
473
|
-
<span><kbd>ESC</kbd>
|
|
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={
|
|
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={
|
|
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
|
|
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={
|
|
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
|
|
418
|
+
<span>{t.tocShort}</span>
|
|
413
419
|
</a>
|
|
414
420
|
<button
|
|
415
421
|
className="toc-mobile-backdrop"
|
|
416
422
|
type="button"
|
|
417
|
-
aria-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={
|
|
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={
|
|
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"
|
|
97
|
-
<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={
|
|
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={
|
|
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=
|
|
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
|
|
152
|
+
<p>{t.previewFailed}</p>
|
|
151
153
|
<div className="gf-state-act">
|
|
152
|
-
<button type="button" className="gf-btn" onClick={() => load()}
|
|
153
|
-
<a className="gf-btn" href={file.url} download={file.name}
|
|
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"
|
|
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">
|
|
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={
|
|
188
|
+
aria-label={t.previewNamed(file.name)}
|
|
187
189
|
>
|
|
188
190
|
<ActionGlyph name="eye" />
|
|
189
|
-
<span className="gf-lb"
|
|
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={
|
|
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={
|
|
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={
|
|
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"
|
|
62
|
+
<span className="gf-lb">{t.download}</span>
|
|
61
63
|
</a>
|
|
62
64
|
)}
|
|
63
65
|
</div>
|