Skip to content

Commit 40c7d83

Browse files
✨ feat(playground): rebuild playground as docs-kit introduction site
1 parent 8b8dc03 commit 40c7d83

46 files changed

Lines changed: 1838 additions & 65 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎AGENTS.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ The skill text was written for consumers; when it disagrees with `src/config.ts`
3838

3939
The user-facing docs are the playground site (`pnpm dev`):
4040

41-
- **Guides**: `playground/docs/<group>/<page>.mdx` with `title` + `description` (+ `order`), listed in `publicDocs` in `playground/docs.config.ts`. Groups are `getting-started`, `writing`, `configuration`, `advanced`, each a `themeConfig.sidebarGroups` entry.
41+
- **Guides**: `playground/docs/<group>/<page>.mdx` with `title` + `description` (+ `order`), listed in `publicDocs` in `playground/docs.config.ts`. Groups are `getting-started`, `file-conventions`, `guide`, `advanced` (structure modeled on nextra.site/docs), each a `themeConfig.sidebarGroups` entry.
4242
- **Sample components**: `playground/src/<Name>/` (`index.ts`, `type.ts` with JSDoc, `index.mdx`, `demos/`). They are fixtures too: `Button` and `compatibility.json` back `buttonPilot`, `inventory`, `readLegacyMap`, `demoPlugin` and `liveTransform` tests, and `site/compiler/inventory.test.ts` lists every playground document, so update it when you add or remove a page.
4343
- **Home**: `playground/docs/home/home.tsx` (follow `building-landing-home`).
4444
- **Facts**: verify every documented field, command and route against the source before writing it. Only `Demo` and `Api` are MDX globals; no `:::` callouts (the playground imports `src/Callout`).
@@ -47,7 +47,7 @@ The user-facing docs are the playground site (`pnpm dev`):
4747

4848
## Adding Things
4949

50-
- **Config field**: add it to `DocsConfig` / `DocsThemeConfig` in `src/config.ts`; if the browser needs it, it reaches the app through `virtual:lobedocs/site-config` (`ClientSiteConfig`). Values must survive JSON (the config is serialized out of a subprocess); pass functions as a module path, like `stylex`. Add a test, document it in `playground/docs/configuration/docs-config.mdx`, and update the `using-docs-kit` reference.
50+
- **Config field**: add it to `DocsConfig` / `DocsThemeConfig` in `src/config.ts`; if the browser needs it, it reaches the app through `virtual:lobedocs/site-config` (`ClientSiteConfig`). Values must survive JSON (the config is serialized out of a subprocess); pass functions as a module path, like `stylex`. Add a test, document it in `playground/docs/file-conventions/docs-config.mdx`, and update the `using-docs-kit` reference.
5151
- **CLI command**: add a handler to `commands` in `src/cli/commands.ts` (usage text is derived from its keys), cover it in `src/cli/commands.test.ts`, and document it in `playground/docs/getting-started/cli.mdx` and the README table.
5252
- **Docs UI component**: `site/components/<Name>/<Name>.tsx` with a StyleX `style.ts` (named exports only; StyleX longhands such as `backgroundColor`, enforced by ESLint) and a colocated `<Name>.test.tsx`. To expose it in MDX, register it in `site/app/mdx-components.tsx` and update the "only `Demo` and `Api` are global" statements in docs and skills.
5353
- **Theme or appearance**: providers and the theme bootstrap live in `site/app/providers/`; global styles in `site/styles/`. Colors come from `@lobehub/ui` tokens, not hard-coded values.

‎playground/CHANGELOG.md‎

Lines changed: 0 additions & 21 deletions
This file was deleted.

‎playground/docs.config.ts‎

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,61 @@
11
import legacyRedirects from './compatibility.json';
22

3+
const github = 'https://github.com/lobehub/docs-kit';
4+
35
export default {
46
atomDirs: [{ dir: 'src' }],
5-
description: 'A sandbox consumer that exercises every docs-kit feature end to end.',
7+
description:
8+
'Static documentation sites for React component libraries, driven by MDX and one config file.',
9+
homePage: './docs/home/home.tsx',
610
legacyRedirects,
7-
publicDocs: ['docs/guide.mdx'],
11+
publicDocs: [
12+
'docs/getting-started/introduction.mdx',
13+
'docs/getting-started/installation.mdx',
14+
'docs/getting-started/cli.mdx',
15+
'docs/file-conventions/project-structure.mdx',
16+
'docs/file-conventions/docs-config.mdx',
17+
'docs/file-conventions/component-pages.mdx',
18+
'docs/guide/markdown.mdx',
19+
'docs/guide/demos.mdx',
20+
'docs/guide/api-tables.mdx',
21+
'docs/guide/guide-pages.mdx',
22+
'docs/guide/home-page.mdx',
23+
'docs/guide/theming.mdx',
24+
'docs/guide/search.mdx',
25+
'docs/guide/ai-docs.mdx',
26+
'docs/guide/integrations.mdx',
27+
'docs/guide/build-and-deploy.mdx',
28+
'docs/advanced/validations.mdx',
29+
'docs/advanced/react-router.mdx',
30+
'docs/advanced/migrating-from-dumi.mdx',
31+
],
832
siteUrl: 'https://docs-kit.lobehub.com',
933
themeConfig: {
1034
apiHeader: {
1135
docUrl: '{github}/edit/main/playground/{atomId}',
12-
github: 'https://github.com/lobehub/docs-kit',
36+
github,
37+
match: ['/components/'],
1338
sourceUrl: '{github}/tree/main/playground/{atomId}',
1439
},
15-
navItems: [{ href: '/guide', icon: 'book-open', label: 'Guide' }],
40+
navItems: [
41+
{
42+
external: true,
43+
href: 'https://ui.lobehub.com',
44+
icon: 'external-link',
45+
label: 'Live Example: Lobe UI',
46+
},
47+
],
1648
prefersColor: 'auto',
17-
socialLinks: [{ href: 'https://github.com/lobehub/docs-kit', icon: 'github', label: 'GitHub' }],
49+
sidebarGroups: [
50+
{ dir: 'docs/getting-started', icon: 'rocket', order: -4, title: 'Getting Started' },
51+
{ dir: 'docs/file-conventions', icon: 'folder-tree', order: -3, title: 'File Conventions' },
52+
{ dir: 'docs/guide', icon: 'book-open', order: -2, title: 'Guide' },
53+
{ dir: 'docs/advanced', icon: 'wrench', order: -1, title: 'Advanced' },
54+
],
55+
socialLinks: [
56+
{ href: github, icon: 'github', label: 'GitHub' },
57+
{ href: 'https://www.npmjs.com/package/@lobehub/docs-kit', icon: 'npm', label: 'NPM' },
58+
],
1859
},
19-
title: 'Docs Kit Playground',
60+
title: 'Lobe Docs Kit',
2061
};
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
title: Migrating from dumi
3+
description: Move a dumi and dumi-theme-lobehub site to docs-kit, and keep old demo URLs working with legacyRedirects.
4+
order: 3
5+
---
6+
7+
import Callout from '../../src/Callout';
8+
9+
Docs Kit was built to replace `dumi` and `dumi-theme-lobehub` on the LobeHub sites. Most of a migration is mechanical: rename files, swap dumi's tags for `Demo` and `Api` blocks, and clean up frontmatter. Sites with existing readers can keep their old demo URLs alive.
10+
11+
## Content
12+
13+
Docs Kit replaces `dumi` and `dumi-theme-lobehub`. For each component page:
14+
15+
- Rename `index.md` to `index.mdx`; only `index.mdx` is discovered.
16+
- Replace dumi's code tags with an import and a block: a `?demo` import and a `Demo` block whose `of` prop is that import (see [Demos](/guide/demos)). Map `center` to `layout="center"`, `noPadding` to `layout="bare"` and `iframe` to `isolated`.
17+
- Move demos under `src/**/demos/**`.
18+
- Replace hand-written API tables with an `Api` block (see [API Tables](/guide/api-tables)) and move the descriptions into JSDoc.
19+
- Remove the `group`, `nav`, `hero` and `apiHeader` frontmatter fields, and add `description` and `category`.
20+
- Move guide pages to `docs/**/*.mdx` and list them in `publicDocs`.
21+
- Delete `.dumirc.ts` and add `docs.config.ts`.
22+
23+
## Keeping old URLs
24+
25+
A site that already has readers on dumi URLs can pass a frozen inventory of the old site as `legacyRedirects`, usually stored as `compatibility.json`:
26+
27+
```ts
28+
import legacyRedirects from './compatibility.json';
29+
30+
export default {
31+
// …
32+
legacyRedirects,
33+
};
34+
```
35+
36+
The inventory lists each old document and demo with its source file and dumi ids. With it, the build:
37+
38+
- Keeps every old standalone demo id working as `/~demos/<legacy-id>`, next to the new canonical id.
39+
- Follows a document that moved from `.md` to `.mdx` without losing its aliases.
40+
- Fails the audit if a recorded page or demo is no longer produced.
41+
42+
This playground keeps a small `compatibility.json` for its Button page, which the kit's tests use to check that behaviour.
43+
44+
<Callout title="New sites">
45+
A site that never ran on dumi has nothing to preserve. Leave `legacyRedirects` out.
46+
</Callout>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
title: React Router Overrides
3+
description: Change the React Router config the CLI supplies, for example to serve the site under a basename.
4+
order: 2
5+
---
6+
7+
The CLI supplies a React Router config so your repository doesn't need one. When you need to change it, for example to serve the site under a sub-path, you can add your own and the CLI steps aside.
8+
9+
## Defaults
10+
11+
The CLI supplies this React Router config for every command:
12+
13+
| Option | Value |
14+
| ---------------- | ----------------------------------------- |
15+
| `appDirectory` | The kit's own `site/` folder |
16+
| `buildDirectory` | `.react-router/build` |
17+
| `ssr` | `false` |
18+
| `prerender` | Every page, overview, demo and agent file |
19+
| `routeDiscovery` | `{ mode: 'initial' }` |
20+
21+
## Overriding
22+
23+
Add a `react-router.config.ts` to the repository root and build it from the exported defaults:
24+
25+
```ts
26+
import { defineLobeDocsReactRouterConfig } from '@lobehub/docs-kit/react-router-config';
27+
28+
export default defineLobeDocsReactRouterConfig({
29+
basename: '/docs',
30+
});
31+
```
32+
33+
`defineLobeDocsReactRouterConfig` merges your options over the defaults. The module also exports `lobeDocsReactRouterConfig`, the defaults object, as both a named and the default export.
34+
35+
A config you write yourself always wins: the CLI only generates its temporary `react-router.config.mjs` when no `react-router.config.*` exists, and never modifies yours. Keep `appDirectory`, `buildDirectory` and `prerender` from the defaults unless you know why you are changing them; the finalize step reads `.react-router/build/client`.
36+
37+
## Stable entry points
38+
39+
`@lobehub/docs-kit/react-router-config` and the `lobedocs` CLI are the supported entry points. Other deep imports into the package are not stable yet.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
title: Build Validations
3+
description: The content errors and artifact checks that stop lobedocs build, and how to fix each one.
4+
order: 1
5+
---
6+
7+
import Callout from '../../src/Callout';
8+
9+
`lobedocs build` fails fast on content errors, then audits the finished site before it replaces `dist/`. `lobedocs dev` reports the content errors too, so most problems show up while you write.
10+
11+
## Frontmatter
12+
13+
Reported as `Invalid MDX documents:` with the file and every bad field.
14+
15+
| Rule | Fix |
16+
| --- | --- |
17+
| No YAML frontmatter, or invalid YAML | Add a `---` block at the very top (`CHANGELOG.md` is exempt) |
18+
| `title` or `description` missing or empty | Add both, as plain strings |
19+
| `category` missing on a component page | Add `category`, reusing an existing name |
20+
| `order` is not a finite number | Write `order: 2`, not `order: "2"` |
21+
| `status` is not `stable`, `beta`, `experimental` or `deprecated` | Use one of those or remove it |
22+
| `route` is invalid or leaves `/components/` on a component page | Remove `route` and let the folder decide the URL |
23+
| Two documents resolve to the same URL | Rename a folder or set a distinct `route` |
24+
25+
## Sidebar groups
26+
27+
`themeConfig.sidebarGroups` entries need a non-empty `dir` and `title`; `icon` must be a non-empty string and `order` a finite number when set. Duplicate `dir` or `title` values are rejected.
28+
29+
## Demos
30+
31+
- A `Demo` block whose `of` value is not a `?demo` import, or the imported file does not exist.
32+
- A demo file without exactly one `export default`.
33+
- An `isolated` demo, or a demo needed by a standalone route, outside `src/**/demos/**`.
34+
35+
Dynamic `import()`, workers and local dependencies the live editor can't load produce warnings, not errors. Set `editable={false}` on that `Demo` block.
36+
37+
## API tables
38+
39+
- An `Api` block without a `name`, with an empty `from`, or with a `data` attribute.
40+
- A `name` that doesn't resolve to an exported component.
41+
- A prop typed `any` or `unknown`.
42+
- A JSDoc `@default` that disagrees with the default in the component's destructuring.
43+
44+
## Artifact audit
45+
46+
After the build, the kit checks the output:
47+
48+
- **Internal links and `#hash` targets.** The most common author error. Link with site paths such as `/components/button#api`, and make each hash match a heading slug.
49+
- Every page and standalone demo has its HTML, with the right title, description, canonical and Open Graph tags.
50+
- `llms.txt`, `skills.md`, the sitemap, `robots.txt`, the Pagefind index and the 404 page exist and agree with the content.
51+
- Bundle isolation: pages don't load the live editor, giscus or Pagefind in their initial bundle, and standalone demos don't include the docs chrome. Don't import those from MDX or demos directly.
52+
- With `legacyRedirects`, every recorded legacy page and demo id is still produced.
53+
54+
<Callout title="Reading the error" type="tip">
55+
Each failure names the file and the rule. Fix the first one and rebuild; later errors are often
56+
caused by the first.
57+
</Callout>

‎playground/docs/changelog.mdx‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
---
22
title: Changelog
3-
description: Release history of the playground.
3+
description: Release history of @lobehub/docs-kit.
44
order: 999
55
---
66

7-
import Changelog from '../CHANGELOG.md';
7+
import Changelog from '../../CHANGELOG.md';
88

99
<span aria-hidden="true" id="readme-top" />
1010

1111
<Changelog />
12+
13+
<div align="right">
14+
15+
[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
16+
17+
</div>
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
---
2+
title: Component Pages
3+
description: Write an index.mdx next to a component, with the frontmatter, headings and blocks the kit expects.
4+
order: 3
5+
---
6+
7+
import Callout from '../../src/Callout';
8+
9+
A component page is the `index.mdx` that sits next to a component. Keeping docs in the component folder means the page, its demos and its types change together, and the kit turns each one into a page at `/components/...` with a sidebar entry, live demos and an API table.
10+
11+
## Template
12+
13+
A component page is an `index.mdx` in the component's folder, such as `src/Button/index.mdx`. The [Button page](/components/button) of this site is built from this shape:
14+
15+
```mdx
16+
---
17+
title: Button
18+
description: Button triggers an action. Supports variants, sizes, loading and icon slots.
19+
category: General
20+
order: -1
21+
---
22+
23+
import Basic from './demos/index.tsx?demo';
24+
import Variants from './demos/Variant.tsx?demo';
25+
26+
## Introduction
27+
28+
What it is, when to use it, and when to use something else.
29+
30+
## Basic Usage
31+
32+
<Demo of={Basic} title="Basic usage" />
33+
34+
## Variants
35+
36+
<Demo of={Variants} title="Variants" />
37+
38+
## API
39+
40+
<Api name="Button" />
41+
```
42+
43+
`Demo` and `Api` are available in every MDX file without an import. See [Demos](/guide/demos) and [API Tables](/guide/api-tables).
44+
45+
## Frontmatter
46+
47+
| Field | Required | Effect |
48+
| --- | --- | --- |
49+
| `title` | yes | Page heading, `<title>` and sidebar label. A PascalCase title also shows `import { Title } from '<packageName>'` in the header |
50+
| `description` | yes | Subtitle, meta and Open Graph description, search and `llms.txt`. One or two plain sentences, no Markdown |
51+
| `category` | on component pages | Sidebar group inside the section. `General` sorts first; the others sort alphabetically |
52+
| `order` | no | Number; lower comes first inside the category. Pages without it sort last, then by title |
53+
| `status` | no | `stable`, `beta`, `experimental` or `deprecated`. Stored as search metadata and listed in the page's agent markdown |
54+
| `since` | no | Version string, listed in the page's agent markdown |
55+
| `route` | no | Overrides the URL. Component pages must stay under `/components/` |
56+
57+
Any other field, such as dumi's `group`, `nav` or `hero`, is ignored. The [Callout page](/components/callout) sets `status` and `since`.
58+
59+
<Callout title="Values are validated" type="warning">
60+
A missing `title`, `description` or `category`, an `order` written as a string, or an unknown
61+
`status` stops the build with the file name and the field. See [Build
62+
Validations](/advanced/validations).
63+
</Callout>
64+
65+
## Headings
66+
67+
The page renders `title` as its only `h1`, so start sections at `##`; a stray `#` is rendered as `h2`. Each heading gets an anchor link, an entry in the outline and a line in `llms.txt`, so keep them short and stable: `## Variants`, `## Controlled`, `## API`.
68+
69+
## Header links
70+
71+
For pages under an atom root, the header shows the import line and links to NPM, the source folder and the edit page. They come from `themeConfig.apiHeader`:
72+
73+
```ts
74+
apiHeader: {
75+
packageName: '@lobehub/editor',
76+
github: 'https://github.com/lobehub/lobe-editor',
77+
docUrl: '{github}/edit/main/{atomId}',
78+
sourceUrl: '{github}/tree/main/{atomId}',
79+
match: ['/components/'],
80+
},
81+
```
82+
83+
`{atomId}` is the MDX path for `docUrl` and the component folder for `sourceUrl`. Both templates default to the `master` branch, so set them when your default branch is `main`. `match` limits the links to pages whose URL starts with one of the prefixes.
84+
85+
## Checklist
86+
87+
- `index.mdx` sits in the component folder with `title`, `description` and `category`.
88+
- Every `Demo` block's `of` value has a matching `import X from './demos/….tsx?demo'`.
89+
- Each demo has one default export.
90+
- The `Api` block's `name` matches an exported component whose props are typed with JSDoc.
91+
- `lobedocs dev` shows the demos and API table, and `lobedocs build` passes.

0 commit comments

Comments
 (0)