hd-garden 0.7.0 → 0.8.1
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/.env.en.example +67 -0
- package/README.en.md +57 -0
- package/README.md +31 -46
- package/app/a2/[slug]/page.tsx +4 -3
- package/app/a2/page.tsx +4 -3
- package/app/about/page.tsx +8 -9
- package/app/admin/page.tsx +7 -6
- package/app/admin/preview/[...path]/page.tsx +2 -1
- package/app/admin/ui/blocks/page.tsx +2 -1
- package/app/admin/ui/catalog/page.tsx +2 -1
- package/app/admin/ui/evals/page.tsx +2 -1
- package/app/admin/ui/page.tsx +2 -1
- package/app/blog/[...path]/page.tsx +14 -5
- package/app/blog/page.tsx +4 -2
- package/app/columns/[column]/[...path]/page.tsx +17 -18
- package/app/columns/page.tsx +12 -8
- package/app/components/AdminUiShell.tsx +4 -3
- package/app/components/ArticlePager.tsx +32 -0
- package/app/components/ArticleReferences.tsx +4 -1
- package/app/components/ArticleTags.tsx +3 -2
- package/app/components/BlogArchive.tsx +20 -16
- package/app/components/Comments.tsx +17 -10
- package/app/components/ContentEmptyState.tsx +29 -28
- package/app/components/ExternalEmbed.tsx +15 -14
- package/app/components/FeedMore.tsx +70 -0
- package/app/components/GardenContentGuide.tsx +10 -2
- package/app/components/GardenDocsNav.tsx +29 -22
- package/app/components/GiscusComments.tsx +2 -1
- package/app/components/GithubLiveOverview.tsx +10 -8
- package/app/components/GithubProfile.tsx +31 -21
- package/app/components/HandbookLangRedirect.tsx +30 -0
- package/app/components/HandbookLangSwitch.tsx +53 -0
- package/app/components/HandbookView.tsx +270 -0
- package/app/components/MarkdownArticle.tsx +39 -9
- package/app/components/MarkdownImage.tsx +6 -4
- package/app/components/SiteChrome.tsx +11 -2
- package/app/components/SiteFooter.tsx +6 -4
- package/app/components/SiteHeader.tsx +38 -25
- package/app/components/TableOfContents.tsx +15 -9
- package/app/components/ThoughtCard.tsx +16 -14
- package/app/components/ThoughtFeed.tsx +41 -0
- package/app/components/UiBlock.tsx +3 -2
- package/app/components/UiLang.tsx +18 -0
- package/app/components/Webmentions.tsx +13 -12
- package/app/components/WidgetChart.tsx +8 -6
- package/app/components/garden/FilePreview.tsx +14 -12
- package/app/components/garden/GardenBlock.tsx +10 -1
- package/app/components/garden/GardenFile.tsx +10 -8
- package/app/components/garden/RefDemo.tsx +62 -0
- package/app/components/garden/blocks.tsx +90 -32
- package/app/components/garden/chrome.tsx +20 -13
- package/app/components/garden/patterns.tsx +497 -0
- package/app/garden/[...slug]/page.tsx +11 -130
- package/app/garden/en/[...slug]/page.tsx +28 -0
- package/app/garden/en/page.tsx +16 -0
- package/app/garden/page.tsx +8 -74
- package/app/garden-modules.d.ts +3 -0
- package/app/globals.css +10 -0
- package/app/layout.tsx +2 -4
- package/app/lib/a2-meta.ts +26 -3
- package/app/lib/content.ts +13 -3
- package/app/lib/garden-docs-meta.ts +84 -5
- package/app/lib/github-id.mjs +8 -0
- package/app/lib/handbook-path.ts +11 -0
- package/app/lib/handbook-switch.mjs +12 -0
- package/app/lib/i18n.ts +621 -0
- package/app/lib/page-alternates.ts +2 -2
- package/app/lib/rehype-field-tables.mjs +47 -0
- package/app/lib/remark-a2.mjs +18 -8
- package/app/lib/remark-link-card.mjs +22 -0
- package/app/lib/remark-ref-demos.mjs +42 -0
- package/app/lib/tag-filter.ts +9 -2
- package/app/not-found.tsx +34 -4
- package/app/page.tsx +17 -14
- package/app/rss.xml/route.ts +2 -1
- package/app/site.config.ts +1 -1
- package/app/styles/a2.css +439 -32
- package/app/styles/shell.css +21 -2
- package/app/tags/page.tsx +7 -5
- package/app/thoughts/[slug]/page.tsx +2 -1
- package/app/thoughts/page/[n]/page.tsx +44 -0
- package/app/thoughts/page.tsx +4 -7
- package/app/ui-parity/page.tsx +38 -22
- package/bin/garden.mjs +133 -19
- package/docs/handbook/ai-writing.md +99 -0
- package/docs/handbook/assets/reading-layout-en.svg +26 -0
- package/docs/handbook/components/card.md +43 -20
- package/docs/handbook/components/chart.md +10 -24
- package/docs/handbook/components/choice.md +42 -0
- package/docs/handbook/components/compare.md +34 -21
- package/docs/handbook/components/figure.md +33 -44
- package/docs/handbook/components/file.md +10 -13
- package/docs/handbook/components/html.md +10 -28
- package/docs/handbook/components/interactive.md +9 -33
- package/docs/handbook/components/list.md +65 -0
- package/docs/handbook/components/relations.md +95 -0
- package/docs/handbook/components/stat.md +10 -26
- package/docs/handbook/components/timeline.md +13 -26
- package/docs/handbook/components.md +210 -19
- package/docs/handbook/config.md +7 -5
- package/docs/handbook/deploy.md +2 -2
- package/docs/handbook/design.md +23 -15
- package/docs/handbook/en/ai-writing.md +99 -0
- package/docs/handbook/en/components/card.md +67 -0
- package/docs/handbook/en/components/chart.md +38 -0
- package/docs/handbook/en/components/choice.md +42 -0
- package/docs/handbook/en/components/compare.md +53 -0
- package/docs/handbook/en/components/figure.md +59 -0
- package/docs/handbook/en/components/file/checklist.md +17 -0
- package/docs/handbook/en/components/file.md +29 -0
- package/docs/handbook/en/components/html.md +49 -0
- package/docs/handbook/en/components/interactive.md +41 -0
- package/docs/handbook/en/components/list.md +65 -0
- package/docs/handbook/en/components/relations.md +95 -0
- package/docs/handbook/en/components/stat.md +39 -0
- package/docs/handbook/en/components/timeline.md +37 -0
- package/docs/handbook/en/components.md +222 -0
- package/docs/handbook/en/config.md +127 -0
- package/docs/handbook/en/deploy.md +273 -0
- package/docs/handbook/en/design.md +88 -0
- package/docs/handbook/en/index.md +192 -0
- package/docs/handbook/en/reference/card.md +85 -0
- package/docs/handbook/en/reference/chart.md +68 -0
- package/docs/handbook/en/reference/choice.md +69 -0
- package/docs/handbook/en/reference/compare.md +59 -0
- package/docs/handbook/en/reference/figure.md +84 -0
- package/docs/handbook/en/reference/file/checklist.md +17 -0
- package/docs/handbook/en/reference/file.md +50 -0
- package/docs/handbook/en/reference/html.md +62 -0
- package/docs/handbook/en/reference/interactive.md +71 -0
- package/docs/handbook/en/reference/list.md +72 -0
- package/docs/handbook/en/reference/relations.md +113 -0
- package/docs/handbook/en/reference/stat.md +60 -0
- package/docs/handbook/en/reference/timeline.md +56 -0
- package/docs/handbook/en/reference.md +26 -0
- package/docs/handbook/en/start.md +92 -0
- package/docs/handbook/en/workflow.md +82 -0
- package/docs/handbook/en/writing.md +157 -0
- package/docs/handbook/index.md +99 -4
- package/docs/handbook/reference/card.md +85 -0
- package/docs/handbook/reference/chart.md +68 -0
- package/docs/handbook/reference/choice.md +69 -0
- package/docs/handbook/reference/compare.md +59 -0
- package/docs/handbook/reference/figure.md +84 -0
- package/docs/handbook/reference/file/checklist.md +17 -0
- package/docs/handbook/reference/file.md +50 -0
- package/docs/handbook/reference/html.md +62 -0
- package/docs/handbook/reference/interactive.md +71 -0
- package/docs/handbook/reference/list.md +72 -0
- package/docs/handbook/reference/relations.md +113 -0
- package/docs/handbook/reference/stat.md +60 -0
- package/docs/handbook/reference/timeline.md +56 -0
- package/docs/handbook/reference.md +26 -0
- package/docs/handbook/start.md +1 -1
- package/docs/handbook/workflow.md +6 -5
- package/docs/handbook/writing.md +21 -12
- package/next.config.ts +6 -0
- package/package.json +2 -1
- package/public/images/garden/ref-card-book.svg +1 -0
- package/public/images/garden/ref-card-lamp.svg +1 -0
- package/scripts/build-content.mjs +57 -16
- package/scripts/favicon-ico.mjs +9 -6
- package/scripts/file-preview.mjs +10 -7
- package/scripts/handbook-allowlist.mjs +18 -0
- package/scripts/handbook-facts.mjs +339 -11
- package/scripts/html-lang.mjs +36 -0
- package/scripts/link-assets.mjs +7 -0
- package/scripts/new-post.mjs +18 -9
- package/scripts/prepare-pages-output.mjs +30 -18
- package/scripts/redirects.mjs +17 -6
- package/scripts/static-404.mjs +25 -0
- package/scripts/ui-cli.mjs +14 -8
- package/templates/garden-blocks.md +67 -0
- package/templates/garden-snippets.plist +61 -0
- package/templates/site/Makefile.en +45 -0
- package/templates/site/README.en.md +15 -0
- package/templates/site/site.config.en.yaml +55 -0
- package/templates/site/site.config.yaml +2 -0
- package/templates/skills-en/garden-interactive-chart/SKILL.md +84 -0
- package/templates/skills-en/garden-interactive-chart/references/shell.html +49 -0
- package/templates/skills-en/garden-interactive-chart/references/style.md +61 -0
- package/templates/skills-en/garden-post-review/SKILL.md +63 -0
- package/templates/skills-en/garden-ui/SKILL.md +118 -0
- package/templates/workflows/pages.en.yml +195 -0
- package/templates/workflows/pages.yml +195 -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 +205 -4
- package/ui/garden/check.mjs +12 -0
- package/ui/garden/file-block.mjs +8 -7
- package/ui/garden/html-lang.mjs +88 -0
- package/ui/garden/markdown-links.mjs +7 -4
- package/ui/garden/paging.mjs +30 -0
- package/ui/garden/parse.mjs +45 -0
- package/ui/garden/relations.mjs +252 -0
- package/ui/garden/search-index.mjs +6 -4
- package/ui/garden/source-icon.mjs +54 -0
- package/ui/parity-fixtures.mjs +77 -0
- package/ui/preview/dist/garden-ui.css +9 -9
- package/ui/preview/dist/garden-ui.esm.js +206 -169
- package/ui/preview/dist/garden-ui.iife.js +206 -169
- package/ui/prompt/rules.md +28 -1
- package/ui/react/components/chart.tsx +8 -5
- package/ui/react/components/display.tsx +7 -4
- 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 +89 -0
- package/ui/react/parity.tsx +8 -6
- package/ui/react/runtime.tsx +3 -1
- package/ui/react/ui.css +9 -9
- package/worker/index.ts +14 -1
|
@@ -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, handbookOverviewMetadata } from "../../components/HandbookView";
|
|
3
|
+
import { pageAlternates } from "../../lib/page-alternates";
|
|
4
|
+
import { gardenIndexDocEn } from "../../lib/content";
|
|
5
|
+
|
|
6
|
+
void pageAlternates;
|
|
7
|
+
void handbookLanguages;
|
|
8
|
+
|
|
9
|
+
export async function generateMetadata() {
|
|
10
|
+
return handbookOverviewMetadata("en", gardenIndexDocEn);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export default function GardenEnPage() {
|
|
14
|
+
if (!gardenIndexDocEn) notFound();
|
|
15
|
+
return <HandbookOverview lang="en" />;
|
|
16
|
+
}
|
package/app/garden/page.tsx
CHANGED
|
@@ -1,81 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { ArrowRight } from "@phosphor-icons/react/ssr";
|
|
3
|
-
import { ArticleMeasure } from "../components/ArticleMeasure";
|
|
4
|
-
import { ArticleReferences } from "../components/ArticleReferences";
|
|
5
|
-
import { ArticleTitle } from "../components/ArticleTitle";
|
|
6
|
-
import { GardenDocsNav } from "../components/GardenDocsNav";
|
|
7
|
-
import { GardenMediaGuide } from "../components/GardenMediaGuide";
|
|
8
|
-
import { MarkdownArticle } from "../components/MarkdownArticle";
|
|
9
|
-
import { TableOfContents } from "../components/TableOfContents";
|
|
10
|
-
import {
|
|
11
|
-
extractHeadings,
|
|
12
|
-
gardenDocHref,
|
|
13
|
-
gardenDocs,
|
|
14
|
-
gardenIndexDoc,
|
|
15
|
-
} from "../lib/content";
|
|
16
|
-
import {
|
|
17
|
-
orderedHandbookDocs,
|
|
18
|
-
toHandbookNavItems,
|
|
19
|
-
} from "../lib/garden-docs-meta";
|
|
1
|
+
import { HandbookOverview, handbookLanguages } from "../components/HandbookView";
|
|
20
2
|
import { pageAlternates } from "../lib/page-alternates";
|
|
21
|
-
import {
|
|
3
|
+
import { HANDBOOK_UI } from "../lib/garden-docs-meta";
|
|
4
|
+
import { gardenIndexDoc } from "../lib/content";
|
|
5
|
+
import { siteLang } from "../lib/i18n";
|
|
22
6
|
|
|
23
7
|
export const metadata = {
|
|
24
|
-
title:
|
|
25
|
-
description:
|
|
26
|
-
|
|
27
|
-
alternates: pageAlternates("/garden"),
|
|
8
|
+
title: HANDBOOK_UI[siteLang].name,
|
|
9
|
+
description: gardenIndexDoc?.description ?? "",
|
|
10
|
+
alternates: pageAlternates("/garden", handbookLanguages("zh", "index")),
|
|
28
11
|
};
|
|
29
12
|
|
|
30
13
|
export default function GardenPage() {
|
|
31
|
-
|
|
32
|
-
const ordered = orderedHandbookDocs(gardenDocs);
|
|
33
|
-
const firstDoc = ordered[0] ?? null;
|
|
34
|
-
const content = gardenIndexDoc?.content ?? "";
|
|
35
|
-
const headings = extractHeadings(content);
|
|
36
|
-
const configuredTitle = siteConfig.pages.garden.title?.trim() || gardenIndexDoc?.title || "Garden 使用说明";
|
|
37
|
-
const configuredSubtitle = siteConfig.pages.garden.subtitle?.trim() || gardenIndexDoc?.description || "";
|
|
38
|
-
void GardenMediaGuide;
|
|
39
|
-
|
|
40
|
-
return (
|
|
41
|
-
<main className="column-reading-page garden-doc-page">
|
|
42
|
-
<GardenDocsNav docs={navItems} currentPath="" />
|
|
43
|
-
|
|
44
|
-
<article className="article-column garden-doc-article h-entry">
|
|
45
|
-
<header className="gdoc-article-head">
|
|
46
|
-
<div className="gdoc-eyebrow">
|
|
47
|
-
<span>Garden 使用说明</span>
|
|
48
|
-
<span aria-hidden="true">/</span>
|
|
49
|
-
<span>总览</span>
|
|
50
|
-
</div>
|
|
51
|
-
<ArticleTitle title={configuredTitle} />
|
|
52
|
-
{configuredSubtitle ? (
|
|
53
|
-
<p className="gdoc-article-deck p-summary">{configuredSubtitle}</p>
|
|
54
|
-
) : null}
|
|
55
|
-
</header>
|
|
56
|
-
|
|
57
|
-
<ArticleMeasure />
|
|
58
|
-
|
|
59
|
-
<div className="e-content">
|
|
60
|
-
<MarkdownArticle content={content} />
|
|
61
|
-
</div>
|
|
62
|
-
|
|
63
|
-
<ArticleReferences references={gardenIndexDoc?.references} />
|
|
64
|
-
|
|
65
|
-
{firstDoc ? (
|
|
66
|
-
<nav className="gdoc-pager" aria-label="说明书上下篇导航">
|
|
67
|
-
<Link href={gardenDocHref(firstDoc)} className="gdoc-pager-card is-next">
|
|
68
|
-
<span className="gdoc-pager-dir">
|
|
69
|
-
下一篇
|
|
70
|
-
<ArrowRight size={14} aria-hidden="true" />
|
|
71
|
-
</span>
|
|
72
|
-
<strong>{firstDoc.title}</strong>
|
|
73
|
-
</Link>
|
|
74
|
-
</nav>
|
|
75
|
-
) : null}
|
|
76
|
-
</article>
|
|
77
|
-
|
|
78
|
-
<TableOfContents headings={headings} label="本页目录" />
|
|
79
|
-
</main>
|
|
80
|
-
);
|
|
14
|
+
return <HandbookOverview lang={siteLang} />;
|
|
81
15
|
}
|
package/app/garden-modules.d.ts
CHANGED
|
@@ -60,9 +60,12 @@ declare module "@garden/generated-content" {
|
|
|
60
60
|
references?: { title: string; url?: string; domain?: string }[];
|
|
61
61
|
sourcePath: string;
|
|
62
62
|
content: string;
|
|
63
|
+
lang?: "zh" | "en";
|
|
63
64
|
};
|
|
64
65
|
export const gardenDocs: GardenDocEntry[];
|
|
65
66
|
export const gardenIndexDoc: GardenDocEntry | null;
|
|
67
|
+
export const gardenDocsEn: GardenDocEntry[];
|
|
68
|
+
export const gardenIndexDocEn: GardenDocEntry | null;
|
|
66
69
|
export const a2WordCounts: Record<string, number>;
|
|
67
70
|
export type LinkCardMeta = {
|
|
68
71
|
title: string;
|
package/app/globals.css
CHANGED
|
@@ -3923,6 +3923,16 @@ html[data-theme="dark"] .search-footer {
|
|
|
3923
3923
|
transition: opacity 160ms ease, transform 160ms ease, visibility 0s;
|
|
3924
3924
|
}
|
|
3925
3925
|
|
|
3926
|
+
/* The floating contents button sits over the bottom 76px of the screen:
|
|
3927
|
+
keep that much room after the last line, and keep anchors clear of it. */
|
|
3928
|
+
html:has(.toc-mobile-trigger) {
|
|
3929
|
+
scroll-padding-bottom: calc(76px + env(safe-area-inset-bottom));
|
|
3930
|
+
}
|
|
3931
|
+
|
|
3932
|
+
body:has(.toc-mobile-trigger) main {
|
|
3933
|
+
padding-bottom: calc(76px + env(safe-area-inset-bottom));
|
|
3934
|
+
}
|
|
3935
|
+
|
|
3926
3936
|
:root[data-theme="dark"] .toc-mobile-trigger,
|
|
3927
3937
|
html[data-theme="dark"] .toc-mobile-trigger,
|
|
3928
3938
|
:root[data-theme="dark"] .toc-nojs-trigger,
|
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>
|
package/app/lib/a2-meta.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
const shanghaiOffsetMs = 8 * 60 * 60 * 1000;
|
|
2
|
+
const EN_MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] as const;
|
|
3
|
+
|
|
4
|
+
export type DateLang = "zh" | "en";
|
|
2
5
|
|
|
3
6
|
function shanghaiDate(value: string) {
|
|
4
7
|
const date = new Date(value);
|
|
@@ -6,23 +9,43 @@ function shanghaiDate(value: string) {
|
|
|
6
9
|
return new Date(date.getTime() + shanghaiOffsetMs);
|
|
7
10
|
}
|
|
8
11
|
|
|
9
|
-
/** Calendar date in Asia/Shanghai,
|
|
10
|
-
export function demoDateLabel(value: string) {
|
|
12
|
+
/** Calendar date in Asia/Shanghai, formatted for the active site language. */
|
|
13
|
+
export function demoDateLabel(value: string, lang: DateLang = "zh") {
|
|
11
14
|
const date = shanghaiDate(value);
|
|
12
15
|
if (!date) return value;
|
|
16
|
+
if (lang === "en") {
|
|
17
|
+
return `${EN_MONTHS[date.getUTCMonth()]} ${date.getUTCDate()}, ${date.getUTCFullYear()}`;
|
|
18
|
+
}
|
|
13
19
|
return `${date.getUTCFullYear()} 年 ${date.getUTCMonth() + 1} 月 ${date.getUTCDate()} 日`;
|
|
14
20
|
}
|
|
15
21
|
|
|
16
22
|
/** Home list label. The current Shanghai year drops the year so the column stays narrow. */
|
|
17
|
-
export function homeListDate(value: string, now = new Date()) {
|
|
23
|
+
export function homeListDate(value: string, now = new Date(), lang: "zh" | "en" = "zh") {
|
|
18
24
|
const date = shanghaiDate(value);
|
|
19
25
|
if (!date) return value;
|
|
20
26
|
const today = shanghaiDate(now.toISOString());
|
|
27
|
+
const sameYear = Boolean(today && date.getUTCFullYear() === today.getUTCFullYear());
|
|
28
|
+
if (lang === "en") {
|
|
29
|
+
return new Intl.DateTimeFormat("en-US", {
|
|
30
|
+
timeZone: "UTC",
|
|
31
|
+
month: "short",
|
|
32
|
+
day: "numeric",
|
|
33
|
+
...(sameYear ? {} : { year: "numeric" }),
|
|
34
|
+
}).format(date);
|
|
35
|
+
}
|
|
21
36
|
const monthDay = `${date.getUTCMonth() + 1} 月 ${date.getUTCDate()} 日`;
|
|
22
37
|
if (today && date.getUTCFullYear() === today.getUTCFullYear()) return monthDay;
|
|
23
38
|
return `${date.getUTCFullYear()} 年 ${monthDay}`;
|
|
24
39
|
}
|
|
25
40
|
|
|
41
|
+
/** Full list date: 「2025 年 7 月 21 日」 or "Jul 21, 2025". */
|
|
42
|
+
export function fullListDate(value: string, lang: "zh" | "en" = "zh") {
|
|
43
|
+
if (lang !== "en") return demoDateLabel(value);
|
|
44
|
+
const date = shanghaiDate(value);
|
|
45
|
+
if (!date) return value;
|
|
46
|
+
return new Intl.DateTimeFormat("en-US", { timeZone: "UTC", year: "numeric", month: "short", day: "numeric" }).format(date);
|
|
47
|
+
}
|
|
48
|
+
|
|
26
49
|
export function demoDateTime(value: string) {
|
|
27
50
|
const date = shanghaiDate(value);
|
|
28
51
|
if (!date) return value.slice(0, 10);
|
package/app/lib/content.ts
CHANGED
|
@@ -3,6 +3,8 @@ import {
|
|
|
3
3
|
columns,
|
|
4
4
|
gardenDocs,
|
|
5
5
|
gardenIndexDoc,
|
|
6
|
+
gardenDocsEn,
|
|
7
|
+
gardenIndexDocEn,
|
|
6
8
|
posts,
|
|
7
9
|
thoughts,
|
|
8
10
|
type ContentEntry,
|
|
@@ -19,8 +21,9 @@ import { unified } from "unified";
|
|
|
19
21
|
import { visit } from "unist-util-visit";
|
|
20
22
|
import { articleUsesHeadingNumbers, autoNumbersHeadings, splitHeadingNumber } from "./heading-number";
|
|
21
23
|
import { siteHref } from "./site-href";
|
|
24
|
+
import { siteLang, ui } from "./i18n";
|
|
22
25
|
|
|
23
|
-
export { columns, gardenDocs, gardenIndexDoc, posts, thoughts };
|
|
26
|
+
export { columns, gardenDocs, gardenDocsEn, gardenIndexDoc, gardenIndexDocEn, posts, thoughts };
|
|
24
27
|
export type { ContentEntry, GardenDocEntry, MediaItem };
|
|
25
28
|
|
|
26
29
|
export const postHref = (post: Pick<ContentEntry, "path">) => siteHref(`/blog/${post.path}`);
|
|
@@ -41,11 +44,11 @@ export const columnIndexHref = (slug: string) => siteHref(`/columns/#${slug}`);
|
|
|
41
44
|
export const thoughtHref = (slug: string) => siteHref(`/thoughts/${slug}`);
|
|
42
45
|
|
|
43
46
|
export const formatDate = (value: string, withTime = false) => {
|
|
44
|
-
if (!withTime) return demoDateLabel(value);
|
|
47
|
+
if (!withTime) return demoDateLabel(value, siteLang);
|
|
45
48
|
const canonical = canonicalSiteDate(value) ?? value;
|
|
46
49
|
const date = new Date(canonical);
|
|
47
50
|
if (Number.isNaN(date.getTime())) return value;
|
|
48
|
-
return new Intl.DateTimeFormat(
|
|
51
|
+
return new Intl.DateTimeFormat(ui().dateLocale, {
|
|
49
52
|
timeZone: "Asia/Shanghai",
|
|
50
53
|
year: "numeric",
|
|
51
54
|
month: "2-digit",
|
|
@@ -135,6 +138,13 @@ export const findThought = (slug: string): ContentEntry | undefined =>
|
|
|
135
138
|
export const findGardenDoc = (path: string): GardenDocEntry | undefined =>
|
|
136
139
|
gardenDocs.find((doc) => doc.path === path);
|
|
137
140
|
|
|
141
|
+
/** Handbook pages and the overview of one language. */
|
|
142
|
+
export const handbookDocs = (lang: "zh" | "en") => (lang === "en" ? gardenDocsEn : gardenDocs);
|
|
143
|
+
export const handbookIndexDoc = (lang: "zh" | "en") => (lang === "en" ? gardenIndexDocEn : gardenIndexDoc);
|
|
144
|
+
/** Whether a handbook page (or "index") exists in a language. */
|
|
145
|
+
export const hasHandbookPage = (lang: "zh" | "en", path: string) =>
|
|
146
|
+
path === "index" || path === "" ? Boolean(handbookIndexDoc(lang)) : handbookDocs(lang).some((doc) => doc.path === path);
|
|
147
|
+
|
|
138
148
|
export const findColumnEntry = (
|
|
139
149
|
column: string,
|
|
140
150
|
path: string,
|
|
@@ -4,21 +4,79 @@ export type GardenDocNavItem = {
|
|
|
4
4
|
description?: string;
|
|
5
5
|
section?: string;
|
|
6
6
|
order?: number;
|
|
7
|
+
navTitle?: string;
|
|
7
8
|
};
|
|
8
9
|
|
|
10
|
+
export type HandbookLang = "zh" | "en";
|
|
11
|
+
|
|
9
12
|
export type HandbookSectionMeta = {
|
|
10
13
|
id: string;
|
|
11
14
|
title: string;
|
|
12
|
-
|
|
15
|
+
/** English sidebar group heading; falls back to the Chinese one until translated. */
|
|
16
|
+
titleEn?: string;
|
|
13
17
|
};
|
|
14
18
|
|
|
19
|
+
/** Where each language of the handbook lives. English mirrors the Chinese paths. */
|
|
20
|
+
export const handbookBase = (lang: HandbookLang) => (lang === "en" ? "/garden/en" : "/garden");
|
|
21
|
+
export const handbookPath = (lang: HandbookLang, docPath = "") =>
|
|
22
|
+
docPath && docPath !== "index" ? `${handbookBase(lang)}/${docPath}` : handbookBase(lang);
|
|
23
|
+
export const sectionTitle = (section: HandbookSectionMeta | undefined, lang: HandbookLang) =>
|
|
24
|
+
section ? (lang === "en" ? section.titleEn ?? section.title : section.title) : undefined;
|
|
25
|
+
/** The handbook remembers the reader's choice under this localStorage key. */
|
|
26
|
+
export const HANDBOOK_LANG_KEY = "garden-handbook-lang";
|
|
27
|
+
|
|
28
|
+
/** Handbook chrome labels. Page text lives in docs/handbook and docs/handbook/en. */
|
|
29
|
+
export const HANDBOOK_UI = {
|
|
30
|
+
zh: {
|
|
31
|
+
name: "Garden 使用说明",
|
|
32
|
+
overview: "总览",
|
|
33
|
+
overviewHint: "总览与快速入口",
|
|
34
|
+
guide: "指南",
|
|
35
|
+
pager: "说明书上下篇导航",
|
|
36
|
+
prev: "上一篇",
|
|
37
|
+
next: "下一篇",
|
|
38
|
+
backToOverview: "返回总览",
|
|
39
|
+
overviewDocTitle: "Garden 使用说明首页",
|
|
40
|
+
toc: "本页目录",
|
|
41
|
+
sidebar: "Garden 使用说明目录",
|
|
42
|
+
chapters: "章节导航",
|
|
43
|
+
closeSidebar: "关闭说明目录",
|
|
44
|
+
openSidebar: "打开说明目录",
|
|
45
|
+
sidebarShort: "说明目录",
|
|
46
|
+
mobileBar: "说明书目录栏",
|
|
47
|
+
},
|
|
48
|
+
en: {
|
|
49
|
+
name: "Garden Handbook",
|
|
50
|
+
overview: "Overview",
|
|
51
|
+
overviewHint: "Overview and quick links",
|
|
52
|
+
guide: "Guide",
|
|
53
|
+
pager: "Handbook pages",
|
|
54
|
+
prev: "Previous",
|
|
55
|
+
next: "Next",
|
|
56
|
+
backToOverview: "Back to overview",
|
|
57
|
+
overviewDocTitle: "Garden Handbook home",
|
|
58
|
+
toc: "On this page",
|
|
59
|
+
sidebar: "Garden Handbook contents",
|
|
60
|
+
chapters: "Chapters",
|
|
61
|
+
closeSidebar: "Close contents",
|
|
62
|
+
openSidebar: "Open contents",
|
|
63
|
+
sidebarShort: "Contents",
|
|
64
|
+
mobileBar: "Handbook contents bar",
|
|
65
|
+
},
|
|
66
|
+
} as const;
|
|
67
|
+
|
|
15
68
|
export const HANDBOOK_SECTIONS: HandbookSectionMeta[] = [
|
|
16
|
-
{ id: "getting-started", title: "快速上手",
|
|
17
|
-
{ id: "writing-and-reading", title: "写作与排版",
|
|
18
|
-
{ id: "components", title: "内置组件",
|
|
19
|
-
{ id: "workflow", title: "检查与补全",
|
|
69
|
+
{ id: "getting-started", title: "快速上手", titleEn: "Getting Started" },
|
|
70
|
+
{ id: "writing-and-reading", title: "写作与排版", titleEn: "Writing & Layout" },
|
|
71
|
+
{ id: "components", title: "内置组件", titleEn: "Built-in Components" },
|
|
72
|
+
{ id: "workflow", title: "检查与补全", titleEn: "Checks & Shortcuts" },
|
|
73
|
+
{ id: "reference", title: "组件参考", titleEn: "Component reference" },
|
|
20
74
|
];
|
|
21
75
|
|
|
76
|
+
/** Component reference pages: one per component, all fields and error codes. */
|
|
77
|
+
export const REFERENCE_SECTION = "reference";
|
|
78
|
+
export const isReferencePath = (docPath: string) => docPath === REFERENCE_SECTION || docPath.startsWith(`${REFERENCE_SECTION}/`);
|
|
79
|
+
|
|
22
80
|
export const COMPONENT_BADGE: Record<string, string> = {
|
|
23
81
|
"components/card": "card",
|
|
24
82
|
"components/stat": "stat",
|
|
@@ -29,10 +87,26 @@ export const COMPONENT_BADGE: Record<string, string> = {
|
|
|
29
87
|
"components/html": "html",
|
|
30
88
|
"components/interactive": "interactive",
|
|
31
89
|
"components/file": "file",
|
|
90
|
+
"components/relations": "relations",
|
|
91
|
+
"components/list": "list",
|
|
92
|
+
"components/choice": "choice",
|
|
93
|
+
"reference/card": "card",
|
|
94
|
+
"reference/stat": "stat",
|
|
95
|
+
"reference/compare": "compare",
|
|
96
|
+
"reference/timeline": "timeline",
|
|
97
|
+
"reference/chart": "chart",
|
|
98
|
+
"reference/figure": "figure",
|
|
99
|
+
"reference/html": "html",
|
|
100
|
+
"reference/interactive": "interactive",
|
|
101
|
+
"reference/file": "file",
|
|
102
|
+
"reference/relations": "relations",
|
|
103
|
+
"reference/list": "list",
|
|
104
|
+
"reference/choice": "choice",
|
|
32
105
|
};
|
|
33
106
|
|
|
34
107
|
export const NAV_SHORT_TITLE: Record<string, string> = {
|
|
35
108
|
start: "快速开始",
|
|
109
|
+
"ai-writing": "用 AI 写作",
|
|
36
110
|
config: "站点与专栏配置",
|
|
37
111
|
deploy: "发布到 GitHub Pages",
|
|
38
112
|
writing: "写文章与随想",
|
|
@@ -47,7 +121,11 @@ export const NAV_SHORT_TITLE: Record<string, string> = {
|
|
|
47
121
|
"components/html": "嵌入网页片段",
|
|
48
122
|
"components/interactive": "可调公式与参数",
|
|
49
123
|
"components/file": "文件下载与预览",
|
|
124
|
+
"components/relations": "关系图",
|
|
125
|
+
"components/list": "图标列表",
|
|
126
|
+
"components/choice": "选择卡",
|
|
50
127
|
workflow: "语法检查与快捷输入",
|
|
128
|
+
reference: "总览",
|
|
51
129
|
};
|
|
52
130
|
|
|
53
131
|
export function groupHandbookDocs<T extends GardenDocNavItem>(docs: T[]) {
|
|
@@ -79,5 +157,6 @@ export function toHandbookNavItems(docs: GardenDocNavItem[]): GardenDocNavItem[]
|
|
|
79
157
|
description: doc.description,
|
|
80
158
|
section: doc.section,
|
|
81
159
|
order: doc.order,
|
|
160
|
+
...(doc.navTitle ? { navTitle: doc.navTitle } : {}),
|
|
82
161
|
}));
|
|
83
162
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** The template placeholder written by `garden init`; not a real GitHub account. */
|
|
2
|
+
export const GITHUB_ID_PLACEHOLDER = "your-github-id";
|
|
3
|
+
|
|
4
|
+
/** True when the configured GitHub id is a real account worth calling the GitHub API for. */
|
|
5
|
+
export function hasRealGithubId(id) {
|
|
6
|
+
const value = String(id ?? "").trim();
|
|
7
|
+
return value !== "" && value.toLowerCase() !== GITHUB_ID_PLACEHOLDER;
|
|
8
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The same handbook page in the other language, worked out from the address
|
|
3
|
+
* in the browser so a basePath (/repo/garden/...) stays in front.
|
|
4
|
+
* /garden/x/ ⇄ /garden/en/x/. Returns null outside the handbook.
|
|
5
|
+
*/
|
|
6
|
+
export function swapHandbookLang(pathname: string, target: "zh" | "en"): string | null {
|
|
7
|
+
const match = /^(.*?\/garden)(\/en)?(\/.*)?$/u.exec(pathname);
|
|
8
|
+
if (!match) return null;
|
|
9
|
+
const rest = match[3] ?? "/";
|
|
10
|
+
return target === "en" ? `${match[1]}/en${rest}` : `${match[1]}${rest}`;
|
|
11
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Handbook page language from its path: /garden/en/... is English, the rest of /garden/ is Chinese. */
|
|
2
|
+
export const handbookPageLang = (pathname) => (/\/garden\/en(\/|$)/u.test(String(pathname ?? "")) ? "en" : "zh");
|
|
3
|
+
|
|
4
|
+
/** The 中 / EN switch always offers the other language: Chinese pages offer English, English pages offer Chinese. */
|
|
5
|
+
export const handbookSwitchTarget = (pageLang) => (pageLang === "en" ? "zh" : "en");
|
|
6
|
+
|
|
7
|
+
/** aria-label of the live link. */
|
|
8
|
+
export const handbookSwitchLabel = (pageLang) => (handbookSwitchTarget(pageLang) === "en" ? "Read in English" : "Switch to Chinese");
|
|
9
|
+
|
|
10
|
+
/** Tooltip while there is no counterpart link (built HTML, before hydration). */
|
|
11
|
+
export const handbookSwitchTitle = (pageLang, siteLang) =>
|
|
12
|
+
pageLang === "en" ? "No Chinese version of this page yet" : siteLang === "en" ? "No English version of this page yet" : "这一页还没有英文版";
|