@rspress/core 2.1.4 → 2.1.5

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 (74) hide show
  1. package/dist/bb~0.js +1 -0
  2. package/dist/b~0.js +3026 -1
  3. package/dist/cli/index.js +1 -1
  4. package/dist/config/loadConfigFile.js +1 -1
  5. package/dist/eject-theme/components/HomeFeature/index.scss +12 -0
  6. package/dist/eject-theme/components/Sidebar/SidebarGroup.scss +14 -0
  7. package/dist/eject-theme/components/Sidebar/SidebarGroup.tsx +6 -1
  8. package/dist/eject-theme/components/Sidebar/SidebarItem.scss +0 -10
  9. package/dist/eject-theme/components/Sidebar/SidebarItem.tsx +2 -2
  10. package/dist/node/PluginDriver.js +1 -1
  11. package/dist/node/auto-nav-sidebar/index.js +1 -1
  12. package/dist/node/auto-nav-sidebar/locales.js +1 -1
  13. package/dist/node/auto-nav-sidebar/normalize.js +1 -1
  14. package/dist/node/auto-nav-sidebar/utils.js +1 -1
  15. package/dist/node/auto-nav-sidebar/walk.js +1 -1
  16. package/dist/node/eject.js +1 -1
  17. package/dist/node/initRsbuild.js +1 -1
  18. package/dist/node/mdx/options.js +1 -1
  19. package/dist/node/mdx/processor.js +1 -1
  20. package/dist/node/mdx/rehypePlugins/codeMeta.js +1 -1
  21. package/dist/node/mdx/rehypePlugins/headerAnchor.js +1 -1
  22. package/dist/node/mdx/rehypePlugins/shiki.js +1 -1
  23. package/dist/node/mdx/remarkPlugins/builtin.js +1 -1
  24. package/dist/node/route/RoutePage.js +1 -1
  25. package/dist/node/route/RouteService.js +1 -1
  26. package/dist/node/route/extractPageData.js +1 -1
  27. package/dist/node/route/normalizeRoutePath.js +1 -1
  28. package/dist/node/runtimeModule/i18n/getI18nData.js +1 -1
  29. package/dist/node/runtimeModule/i18n/rsbuildPlugin.js +1 -1
  30. package/dist/node/runtimeModule/pageData/createPageData.js +1 -1
  31. package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +1 -1
  32. package/dist/node/runtimeModule/searchHooks.js +1 -1
  33. package/dist/node/runtimeModule/siteData/createSiteData.js +1 -1
  34. package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +1 -1
  35. package/dist/node/runtimeModule/siteData/rsbuildPlugin.js +1 -1
  36. package/dist/node/serve.js +1 -1
  37. package/dist/node/sitemap.js +1 -1
  38. package/dist/node/ssg/alternateLinks.js +1 -1
  39. package/dist/node/ssg/renderPages.js +1 -1
  40. package/dist/node/ssg/rsbuildPluginSSG.js +1 -1
  41. package/dist/node/ssg/ssgEnv.js +1 -1
  42. package/dist/node/ssg-md/llms/emitLlmsTxt.js +1 -1
  43. package/dist/node/ssg-md/llms/llmsTxt.js +1 -1
  44. package/dist/node/ssg-md/remarkSplitMdx.d.ts +0 -4
  45. package/dist/node/ssg-md/remarkSplitMdx.js +266 -163
  46. package/dist/node/ssg-md/renderPage.js +1 -1
  47. package/dist/node/ssg-md/renderPages.js +1 -1
  48. package/dist/node/ssg-md/rsbuildPluginSSGMD.js +1 -1
  49. package/dist/node/utils/checkLanguageParity.js +1 -1
  50. package/dist/node/utils/createHash.js +1 -1
  51. package/dist/node/utils/flattenMdxContent.js +1 -1
  52. package/dist/node/utils/getPageKey.js +1 -1
  53. package/dist/node/utils/reactAlias.js +1 -1
  54. package/dist/{tx~0.js → q~0.js} +3 -3
  55. package/dist/shiki-transformers.js +1 -1
  56. package/dist/theme/components/HomeFeature/index.css +10 -0
  57. package/dist/theme/components/Sidebar/SidebarGroup.css +14 -0
  58. package/dist/theme/components/Sidebar/SidebarGroup.js +29 -22
  59. package/dist/theme/components/Sidebar/SidebarItem.css +0 -10
  60. package/dist/theme/components/Sidebar/SidebarItem.js +2 -2
  61. package/dist/y~0.js +1 -1
  62. package/package.json +10 -7
  63. package/skills/rspress-best-practices/SKILL.md +82 -0
  64. package/skills/rspress-custom-theme/SKILL.md +242 -0
  65. package/skills/rspress-custom-theme/references/css-variables.md +177 -0
  66. package/skills/rspress-custom-theme/references/eject-components.md +154 -0
  67. package/skills/rspress-custom-theme/references/layout-slots.md +153 -0
  68. package/skills/rspress-description-generator/SKILL.md +118 -0
  69. package/skills/rspress-docs-generator/SKILL.md +60 -0
  70. package/skills/rspress-docs-generator/references/create-new-docs.md +73 -0
  71. package/skills/rspress-docs-generator/references/doc-structure-conventions.md +117 -0
  72. package/skills/rspress-docs-generator/references/maintain-docs-for-prs.md +31 -0
  73. package/skills/rspress-docs-generator/references/rspress-version-guard.md +13 -0
  74. package/dist/8~0.js +0 -3033
@@ -0,0 +1,154 @@
1
+ # Eject components reference
2
+
3
+ Eject copies a built-in component's source code into your project for full customization. This is the heaviest approach — ejected components do not receive automatic updates when Rspress upgrades. Prefer CSS variables, BEM overrides, or Layout slots whenever possible.
4
+
5
+ Official reference: <https://rspress.rs/api/commands>
6
+
7
+ ---
8
+
9
+ ## Eject command
10
+
11
+ ```bash
12
+ # List all available components
13
+ rspress eject
14
+
15
+ # Eject a specific component
16
+ rspress eject <ComponentName>
17
+ ```
18
+
19
+ Ejected source is placed in `theme/components/<ComponentName>/`.
20
+
21
+ ## Available components
22
+
23
+ | Component | Description | Consider wrapping first? |
24
+ | ---------------- | ----------------------------------------- | ------------------------------------------------ |
25
+ | `Layout` | Main layout container with all slot props | Yes — use Layout slots instead |
26
+ | `Root` | Application root wrapper | Only eject for global providers |
27
+ | `Banner` | Notification banner at top of page | Check `top` slot first |
28
+ | `NavTitle` | Navigation logo and title | Check `navTitle` / `beforeNavTitle` slots |
29
+ | `HomeLayout` | Complete home page layout | Check home page slots first |
30
+ | `HomeHero` | Hero section on home page | Check `beforeHero` / `afterHero` slots |
31
+ | `HomeFeature` | Feature grid cards | Check `beforeFeatures` / `afterFeatures` slots |
32
+ | `HomeBackground` | Home page background effects | Try CSS variables first |
33
+ | `HomeFooter` | Home page footer | Check `bottom` slot first |
34
+ | `DocFooter` | Documentation page footer | Check `beforeDocFooter` / `afterDocFooter` slots |
35
+ | `EditLink` | "Edit this page" link | Configure via `themeConfig.editLink` |
36
+ | `LastUpdated` | Last updated timestamp | Usually config is enough |
37
+ | `PrevNextPage` | Previous/next page navigation | Check `beforeDocFooter` slot |
38
+ | `OverviewGroup` | Overview page group cards | — |
39
+ | `Tag` | Tag/label component | — |
40
+
41
+ ## Step-by-Step Eject workflow
42
+
43
+ 1. **Eject the component:**
44
+
45
+ ```bash
46
+ rspress eject DocFooter
47
+ ```
48
+
49
+ 2. **Re-export in theme/index.tsx:**
50
+
51
+ ```tsx
52
+ // theme/index.tsx
53
+ export * from '@rspress/core/theme-original';
54
+ export { DocFooter } from './components/DocFooter';
55
+ ```
56
+
57
+ The named export takes precedence over the wildcard re-export, so Rspress uses your custom version.
58
+
59
+ 3. **Modify the ejected source** in `theme/components/DocFooter/`.
60
+
61
+ ## Common Pattern: `Root` for global providers
62
+
63
+ The most common eject use case is wrapping the entire app in a context provider (state management, analytics, auth, etc.):
64
+
65
+ ```tsx
66
+ // theme/components/Root/index.tsx
67
+ import type { RootProps } from '@rspress/core/theme';
68
+
69
+ export function Root({ children }: RootProps) {
70
+ return (
71
+ <ThemeProvider>
72
+ <AnalyticsProvider>{children}</AnalyticsProvider>
73
+ </ThemeProvider>
74
+ );
75
+ }
76
+ ```
77
+
78
+ ```tsx
79
+ // theme/index.tsx
80
+ export * from '@rspress/core/theme-original';
81
+ export { Root } from './components/Root';
82
+ ```
83
+
84
+ ## Common Pattern: custom home page (HomeLayout)
85
+
86
+ When the default home page structure (Hero + Features) doesn't meet the design requirements — for example, you need a completely different landing page with custom sections, animations, or a non-standard layout — write a custom `HomeLayout` component and re-export it directly:
87
+
88
+ ```tsx
89
+ // theme/components/HomeLayout/index.tsx
90
+ import { useSite, useLang } from '@rspress/core/runtime';
91
+
92
+ export function HomeLayout() {
93
+ const site = useSite();
94
+ const lang = useLang();
95
+ const { title, description } = site.siteData;
96
+
97
+ return (
98
+ <div className="custom-home">
99
+ <section className="hero">
100
+ <h1>{title}</h1>
101
+ <p>{description}</p>
102
+ <div className="hero-actions">
103
+ <a
104
+ href={lang === 'zh' ? '/zh/guide/start' : '/guide/start'}
105
+ className="primary-btn"
106
+ >
107
+ Get Started
108
+ </a>
109
+ <a href="https://github.com/..." className="secondary-btn">
110
+ GitHub
111
+ </a>
112
+ </div>
113
+ </section>
114
+
115
+ <section className="showcase">
116
+ {/* Custom content: testimonials, stats, demos, etc. */}
117
+ </section>
118
+ </div>
119
+ );
120
+ }
121
+ ```
122
+
123
+ ```tsx
124
+ // theme/index.tsx
125
+ export * from '@rspress/core/theme-original';
126
+ export { HomeLayout } from './components/HomeLayout';
127
+ ```
128
+
129
+ The named export overrides the built-in `HomeLayout` from the wildcard re-export — no need to eject first.
130
+
131
+ If you only need to add content before/after the Hero or Features sections (without replacing the entire home page), prefer Layout slots (`beforeHero`, `afterHero`, `beforeFeatures`, `afterFeatures`) instead — see `references/layout-slots.md`.
132
+
133
+ ## Common Pattern: custom doc footer
134
+
135
+ ```tsx
136
+ // theme/components/DocFooter/index.tsx
137
+ import { useFrontmatter } from '@rspress/core/runtime';
138
+
139
+ export function DocFooter() {
140
+ const frontmatter = useFrontmatter();
141
+ return (
142
+ <footer className="custom-doc-footer">
143
+ {frontmatter.author && <span>Author: {frontmatter.author}</span>}
144
+ <a href="https://github.com/...">Edit this page</a>
145
+ </footer>
146
+ );
147
+ }
148
+ ```
149
+
150
+ ## Important notes
151
+
152
+ - Always import from `@rspress/core/theme-original` in `theme/` files, never from `@rspress/core/theme` (the latter resolves to your own `theme/index.tsx`, causing circular imports).
153
+ - After ejecting, you own that component. Track Rspress changelogs for upstream changes you might want to incorporate manually.
154
+ - Run `rspress eject` (no args) to see the up-to-date list of available components — the list above may change between Rspress versions.
@@ -0,0 +1,153 @@
1
+ # Layout slots reference
2
+
3
+ The `Layout` component accepts slot props (`React.ReactNode`) for injecting content at specific positions without replacing built-in components. This is the recommended way to extend Rspress before considering eject.
4
+
5
+ Official reference: <https://rspress.rs/ui/layout-components/layout>
6
+
7
+ ---
8
+
9
+ ## All available slots
10
+
11
+ ### Navigation bar
12
+
13
+ | Slot | Position |
14
+ | ---------------- | ------------------------------------ |
15
+ | `beforeNav` | Before the entire navigation bar |
16
+ | `afterNav` | After the entire navigation bar |
17
+ | `beforeNavTitle` | Before the nav title/logo (top-left) |
18
+ | `navTitle` | Replaces the nav title content |
19
+ | `afterNavTitle` | After the nav title/logo |
20
+ | `beforeNavMenu` | Before the nav menu items |
21
+ | `afterNavMenu` | After the nav menu items |
22
+
23
+ ### Sidebar & outline
24
+
25
+ | Slot | Position |
26
+ | --------------- | ----------------------------------- |
27
+ | `beforeSidebar` | Above the left sidebar |
28
+ | `afterSidebar` | Below the left sidebar |
29
+ | `beforeOutline` | Above the right outline (TOC) panel |
30
+ | `afterOutline` | Below the right outline panel |
31
+
32
+ ### Home page
33
+
34
+ | Slot | Position |
35
+ | ---------------- | ------------------------ |
36
+ | `beforeHero` | Before the Hero section |
37
+ | `afterHero` | After the Hero section |
38
+ | `beforeFeatures` | Before the Features grid |
39
+ | `afterFeatures` | After the Features grid |
40
+
41
+ ### Doc page
42
+
43
+ | Slot | Position |
44
+ | ------------------ | ------------------------------------- |
45
+ | `beforeDoc` | At the very beginning of the doc page |
46
+ | `afterDoc` | At the very end of the doc page |
47
+ | `beforeDocContent` | Before the document content area |
48
+ | `afterDocContent` | After the document content area |
49
+ | `beforeDocFooter` | Before the doc footer (prev/next nav) |
50
+ | `afterDocFooter` | After the doc footer |
51
+
52
+ ### Global
53
+
54
+ | Slot | Position |
55
+ | ------------ | ---------------------------------------------------------------------- |
56
+ | `top` | At the very top of the entire page |
57
+ | `bottom` | At the very bottom of the entire page |
58
+ | `components` | Custom MDX component overrides (`Record<string, React.ComponentType>`) |
59
+
60
+ ---
61
+
62
+ ## Usage pattern
63
+
64
+ All examples below follow the same structure in `theme/index.tsx`. The key parts:
65
+
66
+ - Import `Layout` from `@rspress/core/theme-original` (not `@rspress/core/theme` — that causes circular imports)
67
+ - Re-export everything: `export * from '@rspress/core/theme-original'`
68
+ - Export your custom `Layout` that wraps the original with slot props
69
+
70
+ ### Basic — single slot
71
+
72
+ ```tsx
73
+ // theme/index.tsx
74
+ import { Layout as OriginalLayout } from '@rspress/core/theme-original';
75
+ export * from '@rspress/core/theme-original';
76
+
77
+ export function Layout() {
78
+ return <OriginalLayout beforeNavTitle={<MyLogo />} />;
79
+ }
80
+ ```
81
+
82
+ ### Multiple slots
83
+
84
+ ```tsx
85
+ // theme/index.tsx
86
+ import { Layout as OriginalLayout } from '@rspress/core/theme-original';
87
+ export * from '@rspress/core/theme-original';
88
+
89
+ export function Layout() {
90
+ return (
91
+ <OriginalLayout
92
+ top={<div className="announcement-bar">New version released!</div>}
93
+ bottom={<footer>© 2025 My Company</footer>}
94
+ afterOutline={<div>Related resources</div>}
95
+ />
96
+ );
97
+ }
98
+ ```
99
+
100
+ ### With i18n hooks
101
+
102
+ ```tsx
103
+ // theme/index.tsx
104
+ import { Layout as OriginalLayout } from '@rspress/core/theme-original';
105
+ import { useLang } from '@rspress/core/runtime';
106
+ export * from '@rspress/core/theme-original';
107
+
108
+ function LocalizedBanner() {
109
+ const lang = useLang();
110
+ return <div>{lang === 'zh' ? '欢迎' : 'Welcome'}</div>;
111
+ }
112
+
113
+ export function Layout() {
114
+ return <OriginalLayout top={<LocalizedBanner />} />;
115
+ }
116
+ ```
117
+
118
+ ### Override MDX components
119
+
120
+ The `components` slot accepts a `Record<string, React.ComponentType>` to override how MDX elements render:
121
+
122
+ ```tsx
123
+ // theme/index.tsx
124
+ import { Layout as OriginalLayout } from '@rspress/core/theme-original';
125
+ export * from '@rspress/core/theme-original';
126
+
127
+ function CustomH1({ children }: { children: React.ReactNode }) {
128
+ return (
129
+ <h1 style={{ borderBottom: '2px solid var(--rp-c-brand)' }}>{children}</h1>
130
+ );
131
+ }
132
+
133
+ export function Layout() {
134
+ return <OriginalLayout components={{ h1: CustomH1 }} />;
135
+ }
136
+ ```
137
+
138
+ ---
139
+
140
+ ## Available hooks
141
+
142
+ Use these hooks inside slot components. Import from `@rspress/core/runtime`.
143
+
144
+ | Hook | Purpose |
145
+ | ------------------ | ----------------------------------- |
146
+ | `useDark()` | Returns whether dark mode is active |
147
+ | `useLang()` | Returns current language code |
148
+ | `useVersion()` | Returns current doc version |
149
+ | `usePage()` | Returns current page metadata |
150
+ | `usePages()` | Returns all pages metadata |
151
+ | `useSite()` | Returns site-level configuration |
152
+ | `useFrontmatter()` | Returns current page frontmatter |
153
+ | `useI18n()` | Returns i18n translation function |
@@ -0,0 +1,118 @@
1
+ ---
2
+ name: rspress-description-generator
3
+ description: Generate missing description frontmatter for Rspress Markdown/MDX pages, including new docs pages and site-wide SEO metadata updates.
4
+ ---
5
+
6
+ # Rspress description generator
7
+
8
+ The `description` field in Rspress frontmatter generates `<meta name="description" content="...">` tags, which are used for search engine snippets, social media previews, and AI-oriented formats like llms.txt.
9
+
10
+ ## Step 1 — locate the docs root
11
+
12
+ 1. Find the Rspress config file. Search for `rspress.config.ts`, `.js`, `.mjs`, or `.cjs`. It may be at the project root or inside a subdirectory like `website/`.
13
+ 2. Read the config and extract the `root` option.
14
+ - The value might be a plain string (`root: 'docs'`) or a JS expression (`root: path.join(__dirname, 'docs')`). In either case, determine the resolved directory path.
15
+ - If `root` is set, resolve it relative to the config file's directory.
16
+ - If `root` is not set, default to `docs` relative to the config file's directory.
17
+ 3. Confirm the directory exists. If neither `docs` nor the configured root exists, check for `doc` as a fallback.
18
+
19
+ ## Step 2 — detect i18n structure
20
+
21
+ Rspress i18n projects place language subdirectories (e.g., `en/`, `zh/`) directly under the docs root:
22
+
23
+ ```
24
+ docs/
25
+ ├── en/
26
+ │ ├── guide/
27
+ │ └── index.md
28
+ └── zh/
29
+ ├── guide/
30
+ └── index.md
31
+ ```
32
+
33
+ Check if the docs root contains language subdirectories (two-letter codes like `en`, `zh`, `ja`, `ko`, etc.). If so, process each language directory separately — the description language should match the content language.
34
+
35
+ If there are no language subdirectories, treat the entire docs root as a single-language site.
36
+
37
+ ## Step 3 — scan and process files
38
+
39
+ Glob for `**/*.md` and `**/*.mdx` under the docs root. Exclude:
40
+
41
+ - `node_modules`, build output (`doc_build`, `.rspress`, `dist`)
42
+ - `_meta.json` / `_nav.json` (sidebar/nav config files, not doc pages)
43
+ - `**/shared/**` directories (reusable snippets included via `@import`, not standalone pages)
44
+
45
+ For each file:
46
+
47
+ 1. **Read the file.**
48
+ 2. **Check for existing `description` in frontmatter.** If it exists and is non-empty, skip.
49
+ 3. **Check `pageType` in frontmatter.** For `home` pages, derive the description from the `hero.text` / `hero.tagline` fields or the features list, not from body content.
50
+ 4. **Generate a description** following the writing guidelines below.
51
+ 5. **Insert `description` into frontmatter:**
52
+ - If the file has frontmatter with a `title` field, insert `description` on the line after `title`.
53
+ - If the file has frontmatter without `title`, insert `description` as the first field.
54
+ - If the file has no frontmatter block, add one:
55
+
56
+ ```yaml
57
+ ---
58
+ description: Your generated description here
59
+ ---
60
+ ```
61
+
62
+ ### YAML formatting
63
+
64
+ Most descriptions can be bare YAML strings:
65
+
66
+ ```yaml
67
+ description: Step-by-step guide to setting up your first Rspress site
68
+ ```
69
+
70
+ If the description contains colons, quotes, or other special YAML characters, wrap in double quotes:
71
+
72
+ ```yaml
73
+ description: 'API reference for Rspress configuration: plugins, themes, and build options'
74
+ ```
75
+
76
+ ## Step 4 — batch processing
77
+
78
+ For sites with many files, use parallel agent calls to process independent files simultaneously. Group by directory (e.g., all files in `guide/`, then all in `api/`) to maintain focus and consistency within each section.
79
+
80
+ After processing all files, do a quick scan to ensure no files were missed — re-glob and check for any remaining files without `description`.
81
+
82
+ ## Description writing guidelines
83
+
84
+ The description serves three audiences: search engines (Google snippet), AI systems (llms.txt, summarization), and humans (scanning search results). A good description helps all three.
85
+
86
+ ### Rules
87
+
88
+ - **Length**: 50–160 characters. Under 50 is too vague for search engines; over 160 gets truncated in snippets.
89
+ - **Language**: Match the document content. Chinese docs get Chinese descriptions, English docs get English descriptions.
90
+ - **Be direct**: State what the page covers. Avoid starting with "This document", "This page", "Learn about" — jump straight to the substance.
91
+ - **Be specific**: Mention concrete technologies, APIs, or concepts the page covers. "Configure Rspress plugins for search, analytics, and internationalization" beats "How to use plugins."
92
+ - **No markdown**: Plain text only, no formatting syntax.
93
+
94
+ ### Examples
95
+
96
+ **Good:**
97
+
98
+ | Content | Description |
99
+ | -------------------------- | ---------------------------------------------------------------------------- |
100
+ | Plugin development guide | Create custom Rspress plugins using the Node.js plugin API and runtime hooks |
101
+ | MDX component usage | Import and use React components in MDX documentation files |
102
+ | Rspress 快速开始 | 从安装到本地预览,搭建 Rspress 文档站点的完整流程 |
103
+ | 主题配置 | 自定义 Rspress 主题的导航栏、侧边栏、页脚和暗色模式 |
104
+ | Home page (pageType: home) | Rspress documentation framework — fast, MDX-powered static site generator |
105
+
106
+ **Bad:**
107
+
108
+ | Description | Why |
109
+ | ------------------------------------------------------- | ------------------------------------------------ |
110
+ | "About plugins" | Too vague — which plugins? what about them? |
111
+ | "This page explains how to configure the Rspress theme" | Wastes characters on "This page explains how to" |
112
+ | "Learn everything about Rspress!" | Marketing fluff, says nothing specific |
113
+
114
+ ## Documentation
115
+
116
+ - Frontmatter fields: <https://rspress.rs/api/config/config-frontmatter>
117
+ - Basic config (`root` option): <https://rspress.rs/api/config/config-basic>
118
+ - Full Rspress docs: <https://rspress.rs/llms.txt>
@@ -0,0 +1,60 @@
1
+ ---
2
+ name: rspress-docs-generator
3
+ description: Create a Rspress v2 docs site or maintain existing Rspress v2 documentation for project changes.
4
+ ---
5
+
6
+ # Rspress docs generator
7
+
8
+ Create and maintain Rspress documentation as part of normal project work. Prefer source-backed docs over generic prose: read the code, tests, examples, package metadata, and existing README before writing.
9
+
10
+ ## Use cases
11
+
12
+ - Create a new Rspress v2 documentation site for a project that has no docs site yet.
13
+ - Update an existing Rspress v2 docs site for a user-facing feature, API change, CLI change, or PR.
14
+ - Detect Rspress v1 version markers before documentation work and hand migration to the dedicated `rspress-v2-upgrade` skill.
15
+ - Integrate Rspress documentation into an Rslib package or workspace while preserving the repository's package manager and scripts.
16
+
17
+ ## Workflow
18
+
19
+ 1. **Inspect the project**
20
+ - Locate package files, source entry points, examples, tests, changelogs, and README files.
21
+ - Search for Rspress config files: `rspress.config.ts`, `.js`, `.mjs`, or `.cjs`.
22
+ - Inspect dependencies for Rspress version markers: `@rspress/core` version, legacy `rspress` package or `rspress/*` imports, and `@rspress/plugin-*`.
23
+ - Detect the package manager and workspace setup from lock files (`pnpm-lock.yaml`, `yarn.lock`, `package-lock.json`, `bun.lock`, `bun.lockb`) and `pnpm-workspace.yaml`.
24
+ - If a config exists, resolve the docs root from its `root` option. When `root` is absent, inspect package scripts, CI commands, and documented commands for Rspress CLI positional roots such as `rspress dev site`, `rspress build site`, or `rspress preview site`; use that argument before falling back to Rspress's default `docs/` directory relative to the config file's project cwd. If no config exists, check common roots such as `docs/`, `doc/`, `website/`, and `site/`.
25
+
26
+ 2. **Choose the correct path**
27
+ - If no Rspress docs site exists, follow [Create New Docs](references/create-new-docs.md).
28
+ - If a Rspress docs site exists but appears to be v1, follow [Rspress Version Guard](references/rspress-version-guard.md) before editing docs.
29
+ - If a Rspress v2 docs site exists, follow [Maintain Docs For PRs](references/maintain-docs-for-prs.md).
30
+
31
+ 3. **Validate before finishing**
32
+ - Run the docs build from the Rspress project directory or through the repo's root script.
33
+ - The build must pass as the primary success criterion.
34
+ - Fix broken links, missing navigation entries, invalid frontmatter, and failed MDX imports before reporting completion.
35
+
36
+ ## Code examples
37
+
38
+ Use the repository's package manager when creating or validating docs:
39
+
40
+ ```bash
41
+ # Create a new Rspress docs site with the detected package manager.
42
+ # Replace pnpm with npm, yarn, or bun when that is the repo package manager.
43
+ pnpm create rspress@latest
44
+
45
+ # Validate from the docs project after replacing starter content.
46
+ pnpm run build
47
+ ```
48
+
49
+ When maintaining docs for a PR, inspect the changed source first, then update the matching docs page and navigation:
50
+
51
+ ```text
52
+ src/formatBytes.ts -> website/docs/api/formatBytes.mdx -> website/docs/api/_meta.json
53
+ ```
54
+
55
+ ## Reference
56
+
57
+ - [Documentation structure conventions](references/doc-structure-conventions.md) — how `_nav.json` and `_meta.json` work, with concrete examples for Guide/API sites, grouped sections, and i18n layouts.
58
+ - [Create New Docs](references/create-new-docs.md) — scaffold a Rspress v2 docs site from an undocumented project.
59
+ - [Maintain Docs For PRs](references/maintain-docs-for-prs.md) — update an existing Rspress v2 docs site for feature work.
60
+ - [Rspress Version Guard](references/rspress-version-guard.md) — detect v1 sites, avoid stale v1 scaffolds, and hand full migration to `rspress-v2-upgrade`.
@@ -0,0 +1,73 @@
1
+ # Create new docs
2
+
3
+ Use this path when the current project has no existing Rspress documentation site.
4
+
5
+ 1. **Understand the project from source**
6
+ - Read the root `README.md` and main `package.json`.
7
+ - Identify the project type: library, CLI tool, application, plugin, monorepo package, etc.
8
+ - Read public source entry points, exported types, examples, and representative tests to understand the user-facing surface.
9
+ - Determine the target audience and what to document: getting started, configuration, API reference, CLI commands, examples, migration notes, or plugin usage.
10
+ - Cross-check Rspress basics against the official docs when choosing structure or syntax:
11
+ - Quick start: <https://rspress.rs/guide/start/getting-started>
12
+ - Conventional route: <https://rspress.rs/guide/basic/conventional-route>
13
+ - Frontmatter: <https://rspress.rs/guide/use-mdx/frontmatter>
14
+
15
+ 2. **Choose the docs site location**
16
+ - If the repository already has a conventional docs directory (`docs/`, `doc/`, `website/`, `site/`), prefer reusing it.
17
+ - Otherwise, propose a short list of options to the user, such as `website/`, `docs/`, or `site/`, and ask which to use.
18
+ - For monorepos, place the docs site so it can reference workspace packages without crossing too many directory boundaries.
19
+
20
+ 3. **Scaffold Rspress v2**
21
+ - See the official getting-started guide for the latest creation steps:
22
+ - <https://rspress.rs/guide/start/getting-started>
23
+ - Scaffold with the package manager used by the repo. Run one command that matches the detected package manager:
24
+
25
+ ```bash
26
+ # interactive (recommended for first-time setup)
27
+ pnpm create rspress@latest
28
+ yarn create rspress@latest
29
+ npm create rspress@latest
30
+ bun create rspress@latest
31
+
32
+ # or non-interactive, e.g. for CI/automation
33
+ pnpm dlx create-rspress@latest my-docs --template basic-theme --tools rslint,prettier
34
+ yarn dlx create-rspress@latest my-docs --template basic-theme --tools rslint,prettier
35
+ npx -y create-rspress@latest my-docs --template basic-theme --tools rslint,prettier
36
+ bun x create-rspress@latest my-docs --template basic-theme --tools rslint,prettier
37
+ ```
38
+
39
+ - After scaffolding, verify the generated docs `package.json` depends on Rspress v2 through `@rspress/core` with a 2.x range. Do not accept a generated `rspress` dependency as v2. If the generated dependency is missing, still v1, or uses the legacy `rspress` package, rerun the scaffold with the detected package manager and pin the scaffold package to a known v2-compatible version, such as `<package-manager> create rspress@2` or `npx -y create-rspress@2`.
40
+ - Prefer the detected package manager for installs and scripts. Do not introduce a second package manager or extra lockfile into an existing workspace.
41
+ - Pick a template that matches the project:
42
+ - `basic` — minimal site with the default theme.
43
+ - `basic-theme` — adds a `theme/` folder for customization.
44
+ - `i18n` — multilingual English/Chinese setup.
45
+ - `i18n-theme` — multilingual setup with a theme folder.
46
+ - If the project uses Rslib, follow the Rslib + Rspress integration guide instead of the generic scaffold:
47
+ - <https://rslib.rs/guide/advanced/rspress.md>
48
+
49
+ 4. **After scaffolding**
50
+ - Install dependencies:
51
+
52
+ ```bash
53
+ cd <docs-project>
54
+ <package-manager> install
55
+ ```
56
+
57
+ - In automated or non-interactive runs, do not run an unbounded dev server. If a dev-server smoke test is useful in an interactive run, start `<package-manager> run dev` with an explicit timeout or background process, confirm it starts, then terminate it before continuing.
58
+ - Check the current Node.js requirement from the official Rspress docs or the installed `@rspress/core` package's `engines.node` field. Compare it with the repo's configured Node version and surface any mismatch before proceeding.
59
+ - Default build output goes to `doc_build/`. Keep it out of source control unless the repository already commits it.
60
+
61
+ 5. **Replace starter content**
62
+ - Remove placeholder pages that do not describe the project.
63
+ - Write source-backed pages from the project README, package exports, public types, examples, and tests.
64
+ - Add `title` and `description` frontmatter to each page.
65
+ - Configure navigation with `_nav.json` (top navbar) and `_meta.json` (sidebar) where the generated structure needs explicit labels or order. See [doc-structure-conventions.md](doc-structure-conventions.md) for examples.
66
+ - Follow official Rspress guidance for content features before inventing custom patterns:
67
+ - MDX and React components: <https://rspress.rs/guide/use-mdx/components>
68
+ - Code blocks: <https://rspress.rs/guide/use-mdx/code-blocks>
69
+ - Links: <https://rspress.rs/guide/use-mdx/link>
70
+ - Static assets: <https://rspress.rs/guide/basic/static-assets>
71
+
72
+ 6. **Wire project commands**
73
+ - Add or reuse scripts for docs development and build, such as `docs:dev` and `docs:build`, following the repo's package manager and workspace conventions.
@@ -0,0 +1,117 @@
1
+ # Documentation structure conventions
2
+
3
+ Rspress generates navigation automatically when `rspress.config.ts` does not define `nav` or `sidebar`. Control the result with `_nav.json` (top navbar) and `_meta.json` (sidebar).
4
+
5
+ Official reference:
6
+
7
+ - Autogenerated navigation: <https://rspress.rs/guide/basic/auto-nav-sidebar>
8
+
9
+ - Place `_nav.json` at the docs root (or at the i18n language root such as `docs/en/`).
10
+ - Place `_meta.json` inside each subdirectory that needs explicit sidebar labels, order, or grouping.
11
+ - For clickable directories, add an `index.mdx` (or `index.md`) inside the directory.
12
+ - In leaf directories with only files, `_meta.json` can be omitted when alphabetical order is acceptable. Use `_meta.json` to customize order or labels; only preserve numeric filename prefixes when the repository already uses that convention.
13
+
14
+ ## Example 1: simple guide + API site
15
+
16
+ ```text
17
+ docs/
18
+ ├── _nav.json
19
+ ├── guide/
20
+ │ ├── _meta.json
21
+ │ ├── index.mdx
22
+ │ ├── getting-started.mdx
23
+ │ └── configuration.mdx
24
+ └── api/
25
+ ├── _meta.json
26
+ ├── index.mdx
27
+ └── commands.mdx
28
+ ```
29
+
30
+ `docs/_nav.json`:
31
+
32
+ ```json
33
+ [
34
+ { "text": "Guide", "link": "/guide/", "activeMatch": "/guide/" },
35
+ { "text": "API", "link": "/api/", "activeMatch": "/api/" }
36
+ ]
37
+ ```
38
+
39
+ `docs/guide/_meta.json`:
40
+
41
+ ```json
42
+ [
43
+ { "type": "file", "name": "index", "label": "Overview" },
44
+ "getting-started",
45
+ "configuration"
46
+ ]
47
+ ```
48
+
49
+ `docs/api/_meta.json`:
50
+
51
+ ```json
52
+ [{ "type": "file", "name": "index", "label": "Overview" }, "commands"]
53
+ ```
54
+
55
+ ## Example 2: site with grouped sections
56
+
57
+ A larger site can use `dir-section-header` to group related directories in the sidebar.
58
+
59
+ ```text
60
+ docs/
61
+ ├── _nav.json
62
+ ├── guide/
63
+ │ ├── _meta.json
64
+ │ ├── start/
65
+ │ │ ├── index.mdx
66
+ │ │ ├── introduction.mdx
67
+ │ │ └── getting-started.mdx
68
+ │ ├── basic/
69
+ │ │ ├── index.mdx
70
+ │ │ └── auto-nav-sidebar.mdx
71
+ │ └── advanced/
72
+ │ └── custom-theme.mdx
73
+ └── api/
74
+ ├── _meta.json
75
+ ├── index.mdx
76
+ └── config/
77
+ ├── _meta.json
78
+ ├── index.mdx
79
+ └── build.mdx
80
+ ```
81
+
82
+ `docs/guide/_meta.json`:
83
+
84
+ ```json
85
+ [
86
+ { "type": "dir-section-header", "name": "start", "label": "Getting Started" },
87
+ { "type": "dir-section-header", "name": "basic", "label": "Features" },
88
+ { "type": "dir-section-header", "name": "advanced", "label": "Advanced" }
89
+ ]
90
+ ```
91
+
92
+ `docs/api/_meta.json`:
93
+
94
+ ```json
95
+ [
96
+ { "type": "section-header", "label": "Overview" },
97
+ { "type": "file", "name": "index", "label": "API Overview" },
98
+ { "type": "section-header", "label": "Config" },
99
+ { "type": "dir", "name": "config", "label": "Config Options" }
100
+ ]
101
+ ```
102
+
103
+ ## Example 3: i18n layout
104
+
105
+ For multilingual sites, place `_nav.json` inside each language root and keep the same directory shape across locales.
106
+
107
+ ```text
108
+ docs/
109
+ ├── en/
110
+ │ ├── _nav.json
111
+ │ ├── guide/
112
+ │ └── api/
113
+ └── zh/
114
+ ├── _nav.json
115
+ ├── guide/
116
+ └── api/
117
+ ```