@rspress/core 2.1.3 → 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.
- package/dist/bb~0.js +1 -0
- package/dist/b~0.js +3026 -1
- package/dist/cli/index.js +1 -1
- package/dist/config/loadConfigFile.js +1 -1
- package/dist/eject-theme/components/Callout/index.test.tsx +52 -0
- package/dist/eject-theme/components/Callout/index.tsx +11 -0
- package/dist/eject-theme/components/CodeBlock/index.tsx +1 -1
- package/dist/eject-theme/components/HomeFeature/index.scss +12 -0
- package/dist/eject-theme/components/HomeHero/index.scss +4 -1
- package/dist/eject-theme/components/PageTabs/index.test.tsx +45 -0
- package/dist/eject-theme/components/PageTabs/index.tsx +17 -0
- package/dist/eject-theme/components/Prompt/index.tsx +2 -1
- package/dist/eject-theme/components/Sidebar/SidebarGroup.scss +14 -0
- package/dist/eject-theme/components/Sidebar/SidebarGroup.tsx +6 -1
- package/dist/eject-theme/components/Sidebar/SidebarItem.scss +0 -10
- package/dist/eject-theme/components/Sidebar/SidebarItem.tsx +2 -2
- package/dist/eject-theme/components/Tabs/index.test.tsx +26 -4
- package/dist/eject-theme/components/Tabs/index.tsx +8 -5
- package/dist/node/PluginDriver.js +1 -1
- package/dist/node/auto-nav-sidebar/index.js +1 -1
- package/dist/node/auto-nav-sidebar/locales.js +1 -1
- package/dist/node/auto-nav-sidebar/normalize.js +1 -1
- package/dist/node/auto-nav-sidebar/utils.js +1 -1
- package/dist/node/auto-nav-sidebar/walk.js +1 -1
- package/dist/node/eject.js +1 -1
- package/dist/node/initRsbuild.js +6 -1
- package/dist/node/mdx/options.js +1 -1
- package/dist/node/mdx/processor.js +1 -1
- package/dist/node/mdx/rehypePlugins/codeMeta.js +1 -1
- package/dist/node/mdx/rehypePlugins/headerAnchor.js +1 -1
- package/dist/node/mdx/rehypePlugins/shiki.js +1 -1
- package/dist/node/mdx/remarkPlugins/builtin.js +1 -1
- package/dist/node/route/RoutePage.js +1 -1
- package/dist/node/route/RouteService.js +1 -1
- package/dist/node/route/extractPageData.js +19 -3
- package/dist/node/route/normalizeRoutePath.js +1 -1
- package/dist/node/route/routeChunkAssets.d.ts +2 -0
- package/dist/node/route/routeChunkAssets.js +6 -0
- package/dist/node/runtimeModule/i18n/getI18nData.js +1 -1
- package/dist/node/runtimeModule/i18n/rsbuildPlugin.js +1 -1
- package/dist/node/runtimeModule/pageData/createPageData.js +1 -1
- package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +1 -1
- package/dist/node/runtimeModule/searchHooks.js +1 -1
- package/dist/node/runtimeModule/siteData/createSiteData.js +1 -1
- package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +1 -1
- package/dist/node/runtimeModule/siteData/rsbuildPlugin.js +1 -1
- package/dist/node/serve.js +1 -1
- package/dist/node/sitemap.js +1 -1
- package/dist/node/ssg/alternateLinks.js +1 -1
- package/dist/node/ssg/renderHtmlTemplate.js +5 -1
- package/dist/node/ssg/renderPageWorker.js +1 -1
- package/dist/node/ssg/renderPages.js +1 -1
- package/dist/node/ssg/rsbuildPluginSSG.js +1 -1
- package/dist/node/ssg/ssgEnv.js +1 -1
- package/dist/node/ssg-md/llms/emitLlmsTxt.js +1 -1
- package/dist/node/ssg-md/llms/llmsTxt.js +1 -1
- package/dist/node/ssg-md/remarkSplitMdx.d.ts +0 -4
- package/dist/node/ssg-md/remarkSplitMdx.js +266 -163
- package/dist/node/ssg-md/renderPage.js +1 -1
- package/dist/node/ssg-md/renderPages.js +1 -1
- package/dist/node/ssg-md/rsbuildPluginSSGMD.js +1 -1
- package/dist/node/utils/checkLanguageParity.js +1 -1
- package/dist/node/utils/createHash.js +1 -1
- package/dist/node/utils/flattenMdxContent.js +1 -1
- package/dist/node/utils/getPageKey.js +1 -1
- package/dist/node/utils/reactAlias.js +3 -1
- package/dist/n~0.js +1 -1
- package/dist/{tx~0.js → q~0.js} +3 -3
- package/dist/shiki-transformers.js +1 -1
- package/dist/theme/components/Callout/index.js +10 -0
- package/dist/theme/components/CodeBlock/index.d.ts +1 -1
- package/dist/theme/components/HomeFeature/index.css +10 -0
- package/dist/theme/components/HomeHero/index.css +5 -1
- package/dist/theme/components/PageTabs/index.js +12 -0
- package/dist/theme/components/Prompt/index.js +1 -1
- package/dist/theme/components/Sidebar/SidebarGroup.css +14 -0
- package/dist/theme/components/Sidebar/SidebarGroup.js +29 -22
- package/dist/theme/components/Sidebar/SidebarItem.css +0 -10
- package/dist/theme/components/Sidebar/SidebarItem.js +2 -2
- package/dist/theme/components/Tabs/index.js +8 -5
- package/dist/tinypool~0.js +2 -2
- package/dist/y~0.js +1 -1
- package/package.json +14 -11
- package/skills/rspress-best-practices/SKILL.md +82 -0
- package/skills/rspress-custom-theme/SKILL.md +242 -0
- package/skills/rspress-custom-theme/references/css-variables.md +177 -0
- package/skills/rspress-custom-theme/references/eject-components.md +154 -0
- package/skills/rspress-custom-theme/references/layout-slots.md +153 -0
- package/skills/rspress-description-generator/SKILL.md +118 -0
- package/skills/rspress-docs-generator/SKILL.md +60 -0
- package/skills/rspress-docs-generator/references/create-new-docs.md +73 -0
- package/skills/rspress-docs-generator/references/doc-structure-conventions.md +117 -0
- package/skills/rspress-docs-generator/references/maintain-docs-for-prs.md +31 -0
- package/skills/rspress-docs-generator/references/rspress-version-guard.md +13 -0
- package/dist/p~0.js +0 -3032
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: rspress-custom-theme
|
|
3
|
+
description: Customize Rspress v2 themes with CSS variables, class overrides, Layout slots, icons, or component ejection.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Rspress custom theme
|
|
7
|
+
|
|
8
|
+
Guide for customizing Rspress (v2) themes. Rspress offers four levels of customization, from lightest to heaviest. Always prefer the lightest approach that meets the requirement — lighter approaches are more maintainable and survive Rspress upgrades.
|
|
9
|
+
|
|
10
|
+
## Workflow
|
|
11
|
+
|
|
12
|
+
1. **Understand the user's goal** — what do they want to change? (colors, layout, inject content, replace a component entirely?)
|
|
13
|
+
2. **Pick the right level** using the decision flow below
|
|
14
|
+
3. **Set up `theme/index.tsx`** if needed (Levels 1A, 3, 4 all need it)
|
|
15
|
+
4. **Implement** following the patterns in this skill and reference files
|
|
16
|
+
5. **Verify** the user's Rspress version is v2 (imports use `@rspress/core/*` not `rspress/*`)
|
|
17
|
+
|
|
18
|
+
## Decision flow
|
|
19
|
+
|
|
20
|
+
| User wants to... | Level | Approach |
|
|
21
|
+
| ---------------------------------------------------------------- | ----- | --------------------------- |
|
|
22
|
+
| Change brand colors, fonts, spacing, shadows | 1 | CSS variables |
|
|
23
|
+
| Adjust a specific component's style (borders, padding, etc.) | 2 | BEM class overrides |
|
|
24
|
+
| Add content around existing components (banners, footers, logos) | 3 | Layout slots (wrap) |
|
|
25
|
+
| Override MDX rendering (custom `<h1>`, `<code>`, etc.) | 3 | `components` slot |
|
|
26
|
+
| Wrap the app in a provider (state, analytics, auth) | 4 | Eject `Root` |
|
|
27
|
+
| Replace built-in icons (logo, GitHub, search, etc.) | — | Icon re-export |
|
|
28
|
+
| Completely replace a built-in component | 4 | Eject that component |
|
|
29
|
+
| Add a global floating component (back-to-top, chat widget) | — | `globalUIComponents` config |
|
|
30
|
+
| Control page layout structure (hide sidebar, blank page) | — | Frontmatter `pageType` |
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## theme/index.tsx — The entry point
|
|
35
|
+
|
|
36
|
+
Levels 1A, 3, and 4 all require a `theme/index.tsx` file in the project root (sibling to `docs/`). This is the single entry point for all theme customizations:
|
|
37
|
+
|
|
38
|
+
```text
|
|
39
|
+
project/
|
|
40
|
+
├── docs/
|
|
41
|
+
├── theme/
|
|
42
|
+
│ ├── index.tsx # Theme entry — re-exports + overrides
|
|
43
|
+
│ ├── index.css # CSS variable / BEM overrides (optional)
|
|
44
|
+
│ └── components/ # Ejected components (Level 4)
|
|
45
|
+
└── rspress.config.ts
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Minimal setup:
|
|
49
|
+
|
|
50
|
+
```tsx
|
|
51
|
+
// theme/index.tsx
|
|
52
|
+
import './index.css'; // optional
|
|
53
|
+
export * from '@rspress/core/theme-original';
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
**Critical import rule**: Inside `theme/` files, always import from `@rspress/core/theme-original`. The path `@rspress/core/theme` resolves to your own `theme/index.tsx`, which causes circular imports. (In `docs/` MDX files, `@rspress/core/theme` is fine — it correctly points to your custom theme.)
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## Level 1: CSS variables
|
|
61
|
+
|
|
62
|
+
Override CSS custom properties for brand colors, backgrounds, text, code blocks, and more.
|
|
63
|
+
|
|
64
|
+
**Option A** — `theme/index.css` (use when you also have component overrides in `theme/index.tsx`):
|
|
65
|
+
|
|
66
|
+
```css
|
|
67
|
+
/* theme/index.css */
|
|
68
|
+
:root {
|
|
69
|
+
--rp-c-brand: #7c3aed;
|
|
70
|
+
--rp-c-brand-light: #8b5cf6;
|
|
71
|
+
--rp-c-brand-dark: #6d28d9;
|
|
72
|
+
}
|
|
73
|
+
.dark {
|
|
74
|
+
--rp-c-brand: #a78bfa;
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
**Option B** — `globalStyles` (use when you only need CSS changes, no component overrides):
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
// rspress.config.ts
|
|
82
|
+
export default defineConfig({
|
|
83
|
+
globalStyles: path.join(__dirname, 'styles/custom.css'),
|
|
84
|
+
});
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
> **Full variable list**: Read `references/css-variables.md` for all available CSS variables with light/dark defaults.
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## Level 2: BEM class overrides
|
|
92
|
+
|
|
93
|
+
All built-in components follow BEM naming: `.rp-[component]__[element]--[modifier]`.
|
|
94
|
+
|
|
95
|
+
Common targets: `.rp-nav`, `.rp-link`, `.rp-tabs`, `.rp-codeblock`, `.rp-codeblock__title`, `.rp-nav-menu__item--active`.
|
|
96
|
+
|
|
97
|
+
Use these in your CSS file for targeted style changes when CSS variables aren't granular enough.
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## Level 3: wrap (Layout Slots)
|
|
102
|
+
|
|
103
|
+
Inject content at specific positions in the layout without replacing built-in components. Override `Layout` in `theme/index.tsx`:
|
|
104
|
+
|
|
105
|
+
```tsx
|
|
106
|
+
// theme/index.tsx
|
|
107
|
+
import { Layout as OriginalLayout } from '@rspress/core/theme-original';
|
|
108
|
+
export * from '@rspress/core/theme-original';
|
|
109
|
+
|
|
110
|
+
export function Layout() {
|
|
111
|
+
return (
|
|
112
|
+
<OriginalLayout beforeNavTitle={<MyLogo />} bottom={<CustomFooter />} />
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Use runtime hooks inside slot components — import from `@rspress/core/runtime`: `useDark()`, `useLang()`, `useVersion()`, `usePage()`, `useSite()`, `useFrontmatter()`, `useI18n()`.
|
|
118
|
+
|
|
119
|
+
> **All slots & examples**: Read `references/layout-slots.md` for the complete slot list and usage patterns including i18n and MDX component overrides.
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## Level 4: eject
|
|
124
|
+
|
|
125
|
+
Copy a built-in component's source for full replacement. Only use when wrap/slots cannot achieve the customization.
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
rspress eject # list available components
|
|
129
|
+
rspress eject DocFooter # eject to theme/components/DocFooter/
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Then re-export in `theme/index.tsx` (named export takes precedence over the wildcard):
|
|
133
|
+
|
|
134
|
+
```tsx
|
|
135
|
+
export * from '@rspress/core/theme-original';
|
|
136
|
+
export { DocFooter } from './components/DocFooter';
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
> **Component list & patterns**: Read `references/eject-components.md` for available components, workflow, and common patterns.
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## Custom icons
|
|
144
|
+
|
|
145
|
+
Rspress has 27 built-in icons used across the UI. You can replace any of them by re-exporting your own icon component with the same name — no ejection needed. This uses the same `theme/index.tsx` mechanism: your named export takes precedence over the wildcard re-export.
|
|
146
|
+
|
|
147
|
+
**Icon type**: Each icon is a React component or a URL string:
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
import type { FC, SVGProps } from 'react';
|
|
151
|
+
type Icon = FC<SVGProps<SVGSVGElement>> | string;
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
**Example 1** — Replace an icon with a custom SVG component:
|
|
155
|
+
|
|
156
|
+
```tsx
|
|
157
|
+
// theme/index.tsx
|
|
158
|
+
export * from '@rspress/core/theme-original';
|
|
159
|
+
|
|
160
|
+
// Named export overrides the wildcard — replaces the GitHub icon site-wide
|
|
161
|
+
export const IconGithub = (props: React.SVGProps<SVGSVGElement>) => (
|
|
162
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" {...props}>
|
|
163
|
+
<path d="M12 2C6.477 2 2 6.484 2 12.017c0 ..." fill="currentColor" />
|
|
164
|
+
</svg>
|
|
165
|
+
);
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
**Example 2** — Use an SVGR import:
|
|
169
|
+
|
|
170
|
+
```tsx
|
|
171
|
+
// theme/index.tsx
|
|
172
|
+
export * from '@rspress/core/theme-original';
|
|
173
|
+
|
|
174
|
+
import CustomGithubIcon from './icons/github.svg?react';
|
|
175
|
+
export const IconGithub = CustomGithubIcon;
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
**Using `SvgWrapper` in MDX or custom components**:
|
|
179
|
+
|
|
180
|
+
```mdx
|
|
181
|
+
import { SvgWrapper, IconGithub } from '@rspress/core/theme';
|
|
182
|
+
|
|
183
|
+
<SvgWrapper icon={IconGithub} width={24} height={24} />
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
**Available icons**: `IconArrowDown`, `IconArrowRight`, `IconClose`, `IconCopy`, `IconDeprecated`, `IconDown`, `IconEdit`, `IconEmpty`, `IconExperimental`, `IconExternalLink`, `IconFile`, `IconGithub`, `IconGitlab`, `IconHeader`, `IconJump`, `IconLink`, `IconLoading`, `IconMenu`, `IconMoon`, `IconScrollToTop`, `IconSearch`, `IconSmallMenu`, `IconSuccess`, `IconSun`, `IconTitle`, `IconWrap`, `IconWrapped`.
|
|
187
|
+
|
|
188
|
+
> **Source**: See the [icons source](https://github.com/web-infra-dev/rspress/blob/main/packages/core/src/theme/icons.ts) for default implementations.
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
## Global UI components
|
|
193
|
+
|
|
194
|
+
For components that should render on every page without theme overrides:
|
|
195
|
+
|
|
196
|
+
```ts
|
|
197
|
+
// rspress.config.ts
|
|
198
|
+
export default defineConfig({
|
|
199
|
+
globalUIComponents: [
|
|
200
|
+
path.join(__dirname, 'components', 'BackToTop.tsx'),
|
|
201
|
+
[
|
|
202
|
+
path.join(__dirname, 'components', 'Analytics.tsx'),
|
|
203
|
+
{ trackingId: '...' },
|
|
204
|
+
],
|
|
205
|
+
],
|
|
206
|
+
});
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
---
|
|
210
|
+
|
|
211
|
+
## Page types
|
|
212
|
+
|
|
213
|
+
Control layout per page via frontmatter `pageType`:
|
|
214
|
+
|
|
215
|
+
| Value | Description |
|
|
216
|
+
| ---------- | ------------------------------------- |
|
|
217
|
+
| `home` | Home page with navbar |
|
|
218
|
+
| `doc` | Standard doc with sidebar and outline |
|
|
219
|
+
| `doc-wide` | Doc without sidebar/outline |
|
|
220
|
+
| `custom` | Custom content with navbar only |
|
|
221
|
+
| `blank` | Custom content without navbar |
|
|
222
|
+
| `404` | 404 error page |
|
|
223
|
+
|
|
224
|
+
Fine-grained: set `navbar: false`, `sidebar: false`, `outline: false`, `footer: false` individually.
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
## Common pitfalls
|
|
229
|
+
|
|
230
|
+
- **Circular import**: Using `@rspress/core/theme` instead of `@rspress/core/theme-original` in `theme/` files — causes infinite loop.
|
|
231
|
+
- **Eject over-use**: Ejecting when a Layout slot or CSS variable would suffice — creates upgrade burden.
|
|
232
|
+
- **Missing re-export**: Forgetting `export * from '@rspress/core/theme-original'` in `theme/index.tsx` — breaks all un-overridden components.
|
|
233
|
+
- **v1 imports**: Using `rspress/theme` or `@rspress/theme-default` — these are v1 paths. v2 uses `@rspress/core/theme-original`.
|
|
234
|
+
|
|
235
|
+
## Reference
|
|
236
|
+
|
|
237
|
+
- Custom theme guide: <https://rspress.rs/guide/basic/custom-theme>
|
|
238
|
+
- CSS variables: <https://rspress.rs/ui/vars>
|
|
239
|
+
- Layout component: <https://rspress.rs/ui/layout-components/layout>
|
|
240
|
+
- Built-in icons: <https://rspress.rs/ui/icons/>
|
|
241
|
+
- Built-in hooks: <https://rspress.rs/ui/hooks/>
|
|
242
|
+
- CLI commands (eject): <https://rspress.rs/api/commands>
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# CSS variables reference
|
|
2
|
+
|
|
3
|
+
Complete list of CSS variables exposed by Rspress for theme customization.
|
|
4
|
+
|
|
5
|
+
- **Override location**: `theme/index.css` or `globalStyles` in `rspress.config.ts`
|
|
6
|
+
- **Dark mode selector**: `.dark { ... }`
|
|
7
|
+
- **Official docs**: <https://rspress.rs/ui/vars>
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Brand colors (shared)
|
|
12
|
+
|
|
13
|
+
```css
|
|
14
|
+
:root {
|
|
15
|
+
--rp-c-brand: #0095ff;
|
|
16
|
+
--rp-c-brand-light: #33adff;
|
|
17
|
+
--rp-c-brand-lighter: #c6e0fd;
|
|
18
|
+
--rp-c-brand-dark: #0077ff;
|
|
19
|
+
--rp-c-brand-darker: #005fcc;
|
|
20
|
+
--rp-c-brand-tint: rgba(127, 163, 255, 0.16);
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Base variables
|
|
25
|
+
|
|
26
|
+
| Variable | Light | Dark |
|
|
27
|
+
| ---------------------- | --------------------- | ------------------------ |
|
|
28
|
+
| `--rp-c-bg` | `#ffffff` | `#121212` |
|
|
29
|
+
| `--rp-c-bg-soft` | `#f8f8f9` | `#292e37` |
|
|
30
|
+
| `--rp-c-bg-mute` | `#f1f1f1` | `#343a46` |
|
|
31
|
+
| `--rp-c-bg-alt` | `#fff` | `#000` |
|
|
32
|
+
| `--rp-c-divider` | `rgba(0, 0, 0, 0.25)` | `rgba(84, 84, 84, 0.65)` |
|
|
33
|
+
| `--rp-c-divider-light` | `rgba(0, 0, 0, 0.12)` | `rgba(84, 84, 84, 0.48)` |
|
|
34
|
+
|
|
35
|
+
## Text colors
|
|
36
|
+
|
|
37
|
+
| Variable | Light | Dark |
|
|
38
|
+
| --------------- | ------------------------ | --------------------------- |
|
|
39
|
+
| `--rp-c-text-0` | `#000000` | `#ffffff` |
|
|
40
|
+
| `--rp-c-text-1` | `#242424` | `rgba(255, 255, 245, 0.93)` |
|
|
41
|
+
| `--rp-c-text-2` | `rgba(0, 0, 0, 0.7)` | `rgba(255, 255, 245, 0.65)` |
|
|
42
|
+
| `--rp-c-text-3` | `rgba(60, 60, 60, 0.33)` | `rgba(235, 235, 235, 0.38)` |
|
|
43
|
+
| `--rp-c-text-4` | `rgba(60, 60, 60, 0.18)` | `rgba(235, 235, 235, 0.18)` |
|
|
44
|
+
| `--rp-c-link` | `var(--rp-c-brand-dark)` | `var(--rp-c-brand-light)` |
|
|
45
|
+
|
|
46
|
+
## Inline code
|
|
47
|
+
|
|
48
|
+
| Variable | Light | Dark |
|
|
49
|
+
| ------------------------- | --------------------------- | --------------------------- |
|
|
50
|
+
| `--rp-c-text-code` | `#476582` | `#c9def1` |
|
|
51
|
+
| `--rp-c-text-code-bg` | `rgba(153, 161, 179, 0.06)` | `rgba(255, 255, 255, 0.06)` |
|
|
52
|
+
| `--rp-c-text-code-border` | `rgba(0, 0, 0, 0.035)` | `rgba(255, 255, 255, 0.04)` |
|
|
53
|
+
|
|
54
|
+
## Code blocks
|
|
55
|
+
|
|
56
|
+
| Variable | Light | Dark |
|
|
57
|
+
| ------------------------ | ------------------------------------- | ------------------------------------- |
|
|
58
|
+
| `--rp-code-font-size` | `0.875rem` | `0.875rem` |
|
|
59
|
+
| `--rp-code-title-bg` | `#f8f8f9` | `#191919` |
|
|
60
|
+
| `--rp-code-block-color` | `rgb(46, 52, 64)` | `rgb(229, 231, 235)` |
|
|
61
|
+
| `--rp-code-block-bg` | `var(--rp-c-bg)` | `var(--rp-c-bg)` |
|
|
62
|
+
| `--rp-code-block-border` | `1px solid var(--rp-c-divider-light)` | `1px solid var(--rp-c-divider-light)` |
|
|
63
|
+
| `--rp-code-block-shadow` | `none` | `none` |
|
|
64
|
+
|
|
65
|
+
## Shiki syntax highlighting
|
|
66
|
+
|
|
67
|
+
Rspress uses `.dark` on `html` as the public dark-mode toggle for general theme overrides. The Shiki token blocks below target `html:not(.rp-dark)` and `html.rp-dark`, which Rspress uses internally for syntax highlighting variables.
|
|
68
|
+
|
|
69
|
+
### Light
|
|
70
|
+
|
|
71
|
+
```css
|
|
72
|
+
html:not(.rp-dark) {
|
|
73
|
+
--shiki-foreground: inherit;
|
|
74
|
+
--shiki-background: transparent;
|
|
75
|
+
--shiki-token-constant: #1976d2;
|
|
76
|
+
--shiki-token-string: #31a94d;
|
|
77
|
+
--shiki-token-comment: rgb(182, 180, 180);
|
|
78
|
+
--shiki-token-keyword: #cf2727;
|
|
79
|
+
--shiki-token-parameter: #f59403;
|
|
80
|
+
--shiki-token-function: #7041c8;
|
|
81
|
+
--shiki-token-string-expression: #218438;
|
|
82
|
+
--shiki-token-punctuation: #242323;
|
|
83
|
+
--shiki-token-link: #22863a;
|
|
84
|
+
--shiki-token-deleted: #d32828;
|
|
85
|
+
--shiki-token-inserted: #22863a;
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Dark
|
|
90
|
+
|
|
91
|
+
```css
|
|
92
|
+
html.rp-dark {
|
|
93
|
+
--shiki-foreground: inherit;
|
|
94
|
+
--shiki-background: transparent;
|
|
95
|
+
--shiki-token-constant: #6fb0fa;
|
|
96
|
+
--shiki-token-string: #f9a86e;
|
|
97
|
+
--shiki-token-comment: #6a727b;
|
|
98
|
+
--shiki-token-keyword: #f47481;
|
|
99
|
+
--shiki-token-parameter: #ff9800;
|
|
100
|
+
--shiki-token-function: #ae8eeb;
|
|
101
|
+
--shiki-token-string-expression: #4fb74d;
|
|
102
|
+
--shiki-token-punctuation: #bbbbbb;
|
|
103
|
+
--shiki-token-link: #f9a76d;
|
|
104
|
+
--shiki-token-deleted: #ee6d7a;
|
|
105
|
+
--shiki-token-inserted: #36c47f;
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Grays (shared)
|
|
110
|
+
|
|
111
|
+
```css
|
|
112
|
+
:root {
|
|
113
|
+
--rp-c-gray: #8e8e8e;
|
|
114
|
+
--rp-c-gray-light-1: #aeaeae;
|
|
115
|
+
--rp-c-gray-light-2: #c7c7c7;
|
|
116
|
+
--rp-c-gray-light-3: #d1d1d1;
|
|
117
|
+
--rp-c-gray-light-4: #e5e5e5;
|
|
118
|
+
--rp-c-gray-light-5: #f2f2f2;
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Shadows (shared)
|
|
123
|
+
|
|
124
|
+
```css
|
|
125
|
+
:root {
|
|
126
|
+
--rp-shadow-1: 0 1px 2px rgba(0, 0, 0, 0.02), 0 1px 0 rgba(0, 0, 0, 0.06);
|
|
127
|
+
--rp-shadow-2: 0 3px 12px rgba(0, 0, 0, 0.06), 0 1px 4px rgba(0, 0, 0, 0.07);
|
|
128
|
+
--rp-shadow-3: 0 12px 32px rgba(0, 0, 0, 0.1), 0 2px 6px rgba(0, 0, 0, 0.08);
|
|
129
|
+
--rp-shadow-4: 0 14px 44px rgba(0, 0, 0, 0.12), 0 3px 9px rgba(0, 0, 0, 0.12);
|
|
130
|
+
--rp-shadow-5:
|
|
131
|
+
0 18px 56px rgba(0, 0, 0, 0.16), 0 4px 12px rgba(0, 0, 0, 0.16);
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Radius (shared)
|
|
136
|
+
|
|
137
|
+
```css
|
|
138
|
+
:root {
|
|
139
|
+
--rp-radius: 1rem;
|
|
140
|
+
--rp-radius-small: 0.5rem;
|
|
141
|
+
--rp-radius-large: 1.5rem;
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Home page
|
|
146
|
+
|
|
147
|
+
Note: `...` in gradient values marks omitted gradient parameters, not literal CSS. See the official docs link above for complete values.
|
|
148
|
+
|
|
149
|
+
| Variable | Light | Dark |
|
|
150
|
+
| -------------------------------- | ------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------- |
|
|
151
|
+
| `--rp-home-hero-secondary-color` | `#a673ff` | `#a673ff` |
|
|
152
|
+
| `--rp-home-hero-title-color` | `transparent` | `transparent` |
|
|
153
|
+
| `--rp-home-hero-title-bg` | `linear-gradient(90deg, var(--rp-c-brand-dark) 0%, var(--rp-c-brand-dark) 30%, var(--rp-home-hero-secondary-color) 100%)` | (same) |
|
|
154
|
+
| `--rp-home-background-bg` | `radial-gradient(...), radial-gradient(...), radial-gradient(...), #fff` | `radial-gradient(...), radial-gradient(...), radial-gradient(...), #121212` |
|
|
155
|
+
| `--rp-home-feature-bg` | `linear-gradient(135deg, #fff, #f9f9f980)` | `linear-gradient(135deg, #ffffff00, #ffffff08)` |
|
|
156
|
+
|
|
157
|
+
## Quick start
|
|
158
|
+
|
|
159
|
+
```css
|
|
160
|
+
/* Example brand color overrides for the custom theme scaffold. */
|
|
161
|
+
/* For more CSS variables, see https://rspress.rs/ui/vars. */
|
|
162
|
+
:root {
|
|
163
|
+
--rp-c-brand: #ff5e00;
|
|
164
|
+
--rp-c-brand-dark: #ff704d;
|
|
165
|
+
--rp-c-brand-darker: #ff704d;
|
|
166
|
+
--rp-c-brand-light: #ff7524;
|
|
167
|
+
--rp-c-brand-lighter: #ff7524;
|
|
168
|
+
--rp-c-brand-tint: rgba(255, 94, 0, 0.07);
|
|
169
|
+
|
|
170
|
+
--rp-home-hero-secondary-color: #ff5e00;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
.dark {
|
|
174
|
+
--rp-c-brand: #ff8c4d;
|
|
175
|
+
--rp-home-hero-secondary-color: #ff8c4d;
|
|
176
|
+
}
|
|
177
|
+
```
|
|
@@ -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.
|