@rspress/core 2.0.9 → 2.0.11
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/0~execa.js +1 -1
- package/dist/3323.js +8 -0
- package/dist/{740.js → 5810.js} +127 -139
- package/dist/{2240.js → 6162.js} +1 -4
- package/dist/8006.js +1 -1
- package/dist/8857.js +2 -3
- package/dist/cli/index.js +7 -4
- package/dist/common-Qw-RoVFD.js +25 -0
- package/dist/eject-theme/components/CodeButtonGroup/CopyCodeButton.tsx +17 -21
- package/dist/eject-theme/components/DocContent/doc.scss +14 -41
- package/dist/eject-theme/components/Llms/LlmsContainer.tsx +1 -2
- package/dist/eject-theme/components/Llms/LlmsCopyButton.tsx +14 -8
- package/dist/eject-theme/components/Llms/LlmsCopyRow.tsx +13 -5
- package/dist/eject-theme/components/Llms/LlmsViewOptions.tsx +8 -5
- package/dist/eject-theme/components/Outline/index.scss +1 -1
- package/dist/eject-theme/components/Prompt/icons.tsx +80 -0
- package/dist/eject-theme/components/Prompt/index.scss +423 -0
- package/dist/eject-theme/components/Prompt/index.tsx +335 -0
- package/dist/eject-theme/components/Search/logic/search.ts +10 -5
- package/dist/eject-theme/components/Search/logic/util.test.ts +20 -1
- package/dist/eject-theme/components/Search/logic/util.ts +4 -1
- package/dist/eject-theme/components/SidebarMenu/index.tsx +5 -1
- package/dist/entry/process.d.ts +1 -0
- package/dist/entry/process.js +65 -0
- package/dist/entry/utils.d.ts +7 -0
- package/dist/entry/utils.js +2 -0
- package/dist/entry/worker.d.ts +1 -0
- package/dist/entry/worker.js +74 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -0
- 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 +2 -2
- 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 -0
- package/dist/node/index.d.ts +1 -0
- package/dist/node/initRsbuild.js +1 -1
- package/dist/node/mdx/options.js +2 -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/rehypePlugins/transformers/index.d.ts +1 -1
- package/dist/node/mdx/remarkPlugins/builtin.js +1 -1
- package/dist/node/mdx/remarkPlugins/fileCodeBlock.d.ts +1 -0
- package/dist/node/mdx/remarkPlugins/fileCodeBlock.js +9 -4
- package/dist/node/mdx/remarkPlugins/image.js +1 -1
- package/dist/node/mdx/remarkPlugins/link.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 +1 -1
- package/dist/node/route/normalizeRoutePath.js +1 -1
- package/dist/node/runtimeModule/DEFAULT_I18N_TEXT.d.ts +28 -0
- package/dist/node/runtimeModule/DEFAULT_I18N_TEXT.js +28 -0
- package/dist/node/runtimeModule/i18n.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/ssg/renderPages.js +2 -2
- 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.js +1 -1
- 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 +1 -1
- package/dist/runtime/BrowserOnly.d.ts +7 -0
- package/dist/runtime/BrowserOnly.js +40 -0
- package/dist/runtime/BrowserOnly.test.d.ts +1 -0
- package/dist/runtime/index.d.ts +1 -0
- package/dist/runtime/index.js +1 -0
- package/dist/theme/components/CodeButtonGroup/CopyCodeButton.js +14 -12
- package/dist/theme/components/DocContent/doc.css +13 -21
- package/dist/theme/components/Llms/LlmsCopyButton.js +5 -6
- package/dist/theme/components/Llms/LlmsCopyRow.js +5 -5
- package/dist/theme/components/Llms/LlmsViewOptions.js +1 -3
- package/dist/theme/components/Outline/index.css +1 -1
- package/dist/theme/components/Prompt/icons.d.ts +10 -0
- package/dist/theme/components/Prompt/icons.js +64 -0
- package/dist/theme/components/Prompt/index.css +326 -0
- package/dist/theme/components/Prompt/index.d.ts +33 -0
- package/dist/theme/components/Prompt/index.js +262 -0
- package/dist/theme/components/Search/logic/search.js +5 -3
- package/dist/theme/components/Search/logic/util.js +2 -1
- package/dist/theme/components/SidebarMenu/index.js +2 -1
- package/dist/theme/index.d.ts +3 -0
- package/dist/theme/index.js +3 -0
- package/dist/theme/layout/DocLayout/index.css +9 -1
- package/dist/theme/layout/DocLayout/index.js +11 -6
- package/dist/theme/logic/copyToClipboard.d.ts +1 -0
- package/dist/theme/{components/Llms/copy.js → logic/copyToClipboard.js} +4 -3
- package/dist/theme/logic/getCopyableText.d.ts +5 -0
- package/dist/theme/logic/getCopyableText.js +52 -0
- package/dist/theme/logic/useThemeState.d.ts +5 -10
- package/dist/theme/logic/useThemeState.js +15 -20
- package/dist/theme/styles/vars/base-vars.css +4 -4
- package/dist/utils-B--2TaWv.js +34 -0
- package/dist/utils-De75vAgL.js +7 -0
- package/package.json +16 -16
- package/dist/3425.js +0 -6
- package/dist/eject-theme/components/Llms/copy.ts +0 -12
- package/dist/runtime/getSidebarDataGroup.test.js +0 -68
- package/dist/runtime/hooks/useWindowSize.test.js +0 -36
- package/dist/runtime/route.test.js +0 -154
- package/dist/runtime/utils.test.js +0 -34
- package/dist/theme/components/Llms/copy.d.ts +0 -1
- package/dist/theme/components/Search/logic/util.test.js +0 -51
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
import { useI18n } from '@rspress/core/runtime';
|
|
2
|
+
import {
|
|
3
|
+
copyToClipboard,
|
|
4
|
+
IconArrowDown,
|
|
5
|
+
IconCopy,
|
|
6
|
+
IconSuccess,
|
|
7
|
+
renderInlineMarkdown,
|
|
8
|
+
SvgWrapper,
|
|
9
|
+
} from '@rspress/core/theme';
|
|
10
|
+
import clsx from 'clsx';
|
|
11
|
+
import { useCallback, useEffect, useId, useRef, useState } from 'react';
|
|
12
|
+
import { AGENT_ICONS } from './icons';
|
|
13
|
+
import './index.scss';
|
|
14
|
+
|
|
15
|
+
const ROTATE_INTERVAL = 3500;
|
|
16
|
+
const FADE_DURATION = 400;
|
|
17
|
+
|
|
18
|
+
function RotatingIcon({ index, fading }: { index: number; fading: boolean }) {
|
|
19
|
+
return (
|
|
20
|
+
<span
|
|
21
|
+
className={clsx('rp-prompt__icon', fading && 'rp-prompt__icon--fade-out')}
|
|
22
|
+
title={AGENT_ICONS[index].name}
|
|
23
|
+
>
|
|
24
|
+
{AGENT_ICONS[index].svg}
|
|
25
|
+
</span>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function useRotatingIcon() {
|
|
30
|
+
const [iconIndex, setIconIndex] = useState(0);
|
|
31
|
+
const [fading, setFading] = useState(false);
|
|
32
|
+
const rotateTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
33
|
+
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
const timer = setInterval(() => {
|
|
36
|
+
setFading(true);
|
|
37
|
+
rotateTimeoutRef.current = setTimeout(() => {
|
|
38
|
+
setIconIndex(prev => (prev + 1) % AGENT_ICONS.length);
|
|
39
|
+
setFading(false);
|
|
40
|
+
rotateTimeoutRef.current = null;
|
|
41
|
+
}, FADE_DURATION);
|
|
42
|
+
}, ROTATE_INTERVAL);
|
|
43
|
+
return () => {
|
|
44
|
+
clearInterval(timer);
|
|
45
|
+
if (rotateTimeoutRef.current) {
|
|
46
|
+
clearTimeout(rotateTimeoutRef.current);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}, []);
|
|
50
|
+
|
|
51
|
+
return { fading, iconIndex };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface PromptProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
55
|
+
/**
|
|
56
|
+
* Render custom MDX content without copy or collapse behavior.
|
|
57
|
+
* @default false
|
|
58
|
+
*/
|
|
59
|
+
custom?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Inline description rendered in the prompt header.
|
|
62
|
+
*/
|
|
63
|
+
description?: string;
|
|
64
|
+
/**
|
|
65
|
+
* Header label for the prompt block.
|
|
66
|
+
* @default 'Agent Prompt'
|
|
67
|
+
*/
|
|
68
|
+
title?: string;
|
|
69
|
+
/**
|
|
70
|
+
* Eyebrow label shown above the title.
|
|
71
|
+
* @default 'For your Agent'
|
|
72
|
+
*/
|
|
73
|
+
eyebrow?: string;
|
|
74
|
+
/**
|
|
75
|
+
* Controls the initial folded state.
|
|
76
|
+
* @default true
|
|
77
|
+
*/
|
|
78
|
+
defaultCollapsed?: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* The prompt text to display and copy.
|
|
81
|
+
*/
|
|
82
|
+
prompt?: string;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function CustomPrompt({
|
|
86
|
+
children,
|
|
87
|
+
className,
|
|
88
|
+
defaultCollapsed: _defaultCollapsed,
|
|
89
|
+
description: _description,
|
|
90
|
+
eyebrow = 'For your Agent',
|
|
91
|
+
prompt: _prompt,
|
|
92
|
+
style,
|
|
93
|
+
title: _title,
|
|
94
|
+
...props
|
|
95
|
+
}: PromptProps) {
|
|
96
|
+
const { fading, iconIndex } = useRotatingIcon();
|
|
97
|
+
|
|
98
|
+
return (
|
|
99
|
+
<div
|
|
100
|
+
{...props}
|
|
101
|
+
className={clsx('rp-prompt', 'rp-prompt--custom', className)}
|
|
102
|
+
style={
|
|
103
|
+
{
|
|
104
|
+
'--rp-prompt-accent': AGENT_ICONS[iconIndex].color,
|
|
105
|
+
...style,
|
|
106
|
+
} as React.CSSProperties
|
|
107
|
+
}
|
|
108
|
+
>
|
|
109
|
+
<div className="rp-prompt__backdrop" />
|
|
110
|
+
<div className="rp-prompt__panel">
|
|
111
|
+
<div className="rp-prompt__meta">
|
|
112
|
+
<span className="rp-prompt__eyebrow">
|
|
113
|
+
<RotatingIcon index={iconIndex} fading={fading} />
|
|
114
|
+
{eyebrow}
|
|
115
|
+
</span>
|
|
116
|
+
</div>
|
|
117
|
+
<div className="rp-prompt__custom-content">{children}</div>
|
|
118
|
+
</div>
|
|
119
|
+
</div>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function CopyablePrompt({
|
|
124
|
+
className,
|
|
125
|
+
defaultCollapsed = true,
|
|
126
|
+
description,
|
|
127
|
+
eyebrow = 'For your Agent',
|
|
128
|
+
onClick,
|
|
129
|
+
prompt,
|
|
130
|
+
style,
|
|
131
|
+
title = 'Agent Prompt',
|
|
132
|
+
...props
|
|
133
|
+
}: PromptProps) {
|
|
134
|
+
const t = useI18n();
|
|
135
|
+
const contentId = useId();
|
|
136
|
+
const [collapsed, setCollapsed] = useState(defaultCollapsed);
|
|
137
|
+
const [copied, setCopied] = useState(false);
|
|
138
|
+
const { fading, iconIndex } = useRotatingIcon();
|
|
139
|
+
const [ripples, setRipples] = useState<
|
|
140
|
+
Array<{ id: number; x: number; y: number }>
|
|
141
|
+
>([]);
|
|
142
|
+
const cardRef = useRef<HTMLDivElement>(null);
|
|
143
|
+
const copyTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
144
|
+
const rippleTimersRef = useRef<Set<ReturnType<typeof setTimeout>>>(new Set());
|
|
145
|
+
|
|
146
|
+
useEffect(() => {
|
|
147
|
+
return () => {
|
|
148
|
+
copyTimerRef.current && clearTimeout(copyTimerRef.current);
|
|
149
|
+
rippleTimersRef.current.forEach(clearTimeout);
|
|
150
|
+
rippleTimersRef.current.clear();
|
|
151
|
+
};
|
|
152
|
+
}, []);
|
|
153
|
+
|
|
154
|
+
const handleCopy = useCallback(async () => {
|
|
155
|
+
if (!prompt) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const isCopied = await copyToClipboard(prompt);
|
|
160
|
+
if (!isCopied) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
setCopied(true);
|
|
165
|
+
|
|
166
|
+
if (copyTimerRef.current) {
|
|
167
|
+
clearTimeout(copyTimerRef.current);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
copyTimerRef.current = setTimeout(() => {
|
|
171
|
+
setCopied(false);
|
|
172
|
+
copyTimerRef.current = null;
|
|
173
|
+
}, 2000);
|
|
174
|
+
}, [prompt]);
|
|
175
|
+
|
|
176
|
+
const handleCardActivate = useCallback(
|
|
177
|
+
(e: React.MouseEvent<HTMLDivElement>) => {
|
|
178
|
+
onClick?.(e);
|
|
179
|
+
if (e.defaultPrevented) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (window.getSelection()?.toString()) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const target = e.target as HTMLElement;
|
|
188
|
+
if (
|
|
189
|
+
target.closest(
|
|
190
|
+
'a, button, .rp-prompt__action-copy, .rp-prompt__action-toggle',
|
|
191
|
+
)
|
|
192
|
+
) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const rect = cardRef.current?.getBoundingClientRect();
|
|
197
|
+
if (!rect) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const id = Date.now() + Math.random();
|
|
202
|
+
setRipples(prev => [
|
|
203
|
+
...prev,
|
|
204
|
+
{ id, x: e.clientX - rect.left, y: e.clientY - rect.top },
|
|
205
|
+
]);
|
|
206
|
+
const timer = setTimeout(() => {
|
|
207
|
+
setRipples(prev => prev.filter(r => r.id !== id));
|
|
208
|
+
rippleTimersRef.current.delete(timer);
|
|
209
|
+
}, 600);
|
|
210
|
+
rippleTimersRef.current.add(timer);
|
|
211
|
+
|
|
212
|
+
void handleCopy();
|
|
213
|
+
},
|
|
214
|
+
[handleCopy, onClick],
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
return (
|
|
218
|
+
<div
|
|
219
|
+
{...props}
|
|
220
|
+
ref={cardRef}
|
|
221
|
+
className={clsx('rp-prompt', className)}
|
|
222
|
+
style={
|
|
223
|
+
{
|
|
224
|
+
'--rp-prompt-accent': AGENT_ICONS[iconIndex].color,
|
|
225
|
+
...style,
|
|
226
|
+
} as React.CSSProperties
|
|
227
|
+
}
|
|
228
|
+
onClick={handleCardActivate}
|
|
229
|
+
>
|
|
230
|
+
<div className="rp-prompt__backdrop" />
|
|
231
|
+
{ripples.map(r => (
|
|
232
|
+
<span
|
|
233
|
+
key={r.id}
|
|
234
|
+
className="rp-prompt__ripple"
|
|
235
|
+
style={{ left: r.x, top: r.y }}
|
|
236
|
+
/>
|
|
237
|
+
))}
|
|
238
|
+
<div className="rp-prompt__panel">
|
|
239
|
+
<div className="rp-prompt__header">
|
|
240
|
+
<div
|
|
241
|
+
className={clsx(
|
|
242
|
+
'rp-prompt__meta',
|
|
243
|
+
copied && 'rp-prompt__meta--copied',
|
|
244
|
+
)}
|
|
245
|
+
>
|
|
246
|
+
<span className="rp-prompt__eyebrow">
|
|
247
|
+
<RotatingIcon index={iconIndex} fading={fading} />
|
|
248
|
+
{eyebrow}
|
|
249
|
+
</span>
|
|
250
|
+
</div>
|
|
251
|
+
<div className="rp-prompt__header-row">
|
|
252
|
+
<div className="rp-prompt__header-left">
|
|
253
|
+
<div className="rp-prompt__title-with-icon">
|
|
254
|
+
<div className="rp-prompt__title">{title}</div>
|
|
255
|
+
</div>
|
|
256
|
+
{description ? (
|
|
257
|
+
<p
|
|
258
|
+
className="rp-prompt__description"
|
|
259
|
+
{...renderInlineMarkdown(description)}
|
|
260
|
+
/>
|
|
261
|
+
) : null}
|
|
262
|
+
</div>
|
|
263
|
+
<div className="rp-prompt__header-actions">
|
|
264
|
+
<button
|
|
265
|
+
type="button"
|
|
266
|
+
className={clsx(
|
|
267
|
+
'rp-prompt__action-copy',
|
|
268
|
+
copied && 'rp-prompt__action-copy--copied',
|
|
269
|
+
)}
|
|
270
|
+
onClick={e => {
|
|
271
|
+
e.stopPropagation();
|
|
272
|
+
void handleCopy();
|
|
273
|
+
}}
|
|
274
|
+
title={t('promptCopyText')}
|
|
275
|
+
>
|
|
276
|
+
<SvgWrapper
|
|
277
|
+
icon={copied ? IconSuccess : IconCopy}
|
|
278
|
+
className="rp-prompt__action-icon"
|
|
279
|
+
/>
|
|
280
|
+
<span>
|
|
281
|
+
{copied ? t('promptCopiedText') : t('promptCopyText')}
|
|
282
|
+
</span>
|
|
283
|
+
</button>
|
|
284
|
+
<button
|
|
285
|
+
type="button"
|
|
286
|
+
className="rp-prompt__action-toggle"
|
|
287
|
+
onClick={e => {
|
|
288
|
+
e.stopPropagation();
|
|
289
|
+
setCollapsed(value => !value);
|
|
290
|
+
}}
|
|
291
|
+
aria-controls={contentId}
|
|
292
|
+
aria-expanded={!collapsed}
|
|
293
|
+
title={
|
|
294
|
+
collapsed ? t('promptExpandText') : t('promptCollapseText')
|
|
295
|
+
}
|
|
296
|
+
>
|
|
297
|
+
<SvgWrapper
|
|
298
|
+
icon={IconArrowDown}
|
|
299
|
+
className={clsx(
|
|
300
|
+
'rp-prompt__action-toggle-icon',
|
|
301
|
+
!collapsed && 'rp-prompt__action-toggle-icon--expanded',
|
|
302
|
+
)}
|
|
303
|
+
/>
|
|
304
|
+
</button>
|
|
305
|
+
</div>
|
|
306
|
+
</div>
|
|
307
|
+
</div>
|
|
308
|
+
|
|
309
|
+
<div
|
|
310
|
+
id={contentId}
|
|
311
|
+
className={clsx(
|
|
312
|
+
'rp-prompt__content',
|
|
313
|
+
collapsed && 'rp-prompt__content--collapsed',
|
|
314
|
+
)}
|
|
315
|
+
aria-hidden={collapsed}
|
|
316
|
+
>
|
|
317
|
+
<div className="rp-prompt__content-inner">
|
|
318
|
+
<div
|
|
319
|
+
className="rp-prompt__content-body"
|
|
320
|
+
style={{ whiteSpace: 'pre-wrap' }}
|
|
321
|
+
>
|
|
322
|
+
{prompt}
|
|
323
|
+
</div>
|
|
324
|
+
</div>
|
|
325
|
+
</div>
|
|
326
|
+
</div>
|
|
327
|
+
</div>
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
export function Prompt({ custom = false, ...props }: PromptProps) {
|
|
332
|
+
return custom ? <CustomPrompt {...props} /> : <CopyablePrompt {...props} />;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
export default Prompt;
|
|
@@ -248,15 +248,17 @@ export class PageSearcher {
|
|
|
248
248
|
let statementStartIndex = content.slice(0, queryIndex).lastIndexOf('\n');
|
|
249
249
|
statementStartIndex =
|
|
250
250
|
statementStartIndex === -1 ? 0 : statementStartIndex;
|
|
251
|
-
|
|
251
|
+
let statementEndIndex = content.indexOf(
|
|
252
252
|
'\n\n',
|
|
253
253
|
queryIndex + query.length,
|
|
254
254
|
);
|
|
255
|
+
statementEndIndex =
|
|
256
|
+
statementEndIndex === -1 ? content.length : statementEndIndex;
|
|
255
257
|
let statement = content.slice(statementStartIndex, statementEndIndex);
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
258
|
+
statement = this.#normalizeStatement(statement, query);
|
|
259
|
+
const highlightIndex = normalizeTextCase(statement).indexOf(
|
|
260
|
+
normalizeTextCase(query),
|
|
261
|
+
);
|
|
260
262
|
const highlightInfoList = [
|
|
261
263
|
{
|
|
262
264
|
start: highlightIndex,
|
|
@@ -286,6 +288,9 @@ export class PageSearcher {
|
|
|
286
288
|
}
|
|
287
289
|
|
|
288
290
|
#normalizeStatement(statement: string, query: string) {
|
|
291
|
+
if (statement.length <= THRESHOLD_CONTENT_LENGTH) {
|
|
292
|
+
return statement;
|
|
293
|
+
}
|
|
289
294
|
// If statement is too long, we will only show 120 characters
|
|
290
295
|
const queryIndex = normalizeTextCase(statement).indexOf(
|
|
291
296
|
normalizeTextCase(query),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Header } from '@rspress/core';
|
|
2
2
|
import { describe, expect, test } from '@rstest/core';
|
|
3
|
-
import { backTrackHeaders } from './util';
|
|
3
|
+
import { backTrackHeaders, normalizeTextCase } from './util';
|
|
4
4
|
|
|
5
5
|
describe('utils logic', () => {
|
|
6
6
|
test('back track the headers', () => {
|
|
@@ -19,3 +19,22 @@ describe('utils logic', () => {
|
|
|
19
19
|
]);
|
|
20
20
|
});
|
|
21
21
|
});
|
|
22
|
+
|
|
23
|
+
describe('normalizeTextCase', () => {
|
|
24
|
+
test('normalize latin text without accents for search', () => {
|
|
25
|
+
expect(normalizeTextCase('CAFÉ')).toBe('cafe');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('normalize japanese text without accents for search', () => {
|
|
29
|
+
expect(normalizeTextCase('ご')).toBe('ご');
|
|
30
|
+
expect(normalizeTextCase('ガ')).toBe('ガ');
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('normalize cyrillic text without accents for search', () => {
|
|
34
|
+
expect(normalizeTextCase('ПРИВЕТ')).toBe('привет');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('normalize korean text without accents for search', () => {
|
|
38
|
+
expect(normalizeTextCase('안녕하세요')).toBe('안녕하세요');
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Header } from '@rspress/core';
|
|
2
2
|
|
|
3
3
|
const MAX_TITLE_LENGTH = 20;
|
|
4
|
+
const jRegex = /[\u3040-\u309f\u30a0-\u30ff\u31f0-\u31ff]/u;
|
|
4
5
|
const kRegex = /[\u3131-\u314e|\u314f-\u3163|\uac00-\ud7a3]/u;
|
|
5
6
|
const cyrillicRegex = /[\u0400-\u04FF]/u;
|
|
6
7
|
|
|
@@ -46,9 +47,11 @@ export function normalizeTextCase(text: string | number) {
|
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
const resultWithoutAccents = textNormalized.replace(/[\u0300-\u036f]/g, '');
|
|
49
|
-
|
|
50
|
+
|
|
51
|
+
if (jRegex.test(String(text)) || kRegex.test(String(text))) {
|
|
50
52
|
return resultWithoutAccents.normalize('NFC');
|
|
51
53
|
}
|
|
54
|
+
|
|
52
55
|
return resultWithoutAccents;
|
|
53
56
|
}
|
|
54
57
|
|
|
@@ -37,8 +37,12 @@ export const SidebarMenu = forwardRef(
|
|
|
37
37
|
const { scrolledHeader } = useActiveAnchor(headers);
|
|
38
38
|
|
|
39
39
|
const {
|
|
40
|
-
frontmatter: {
|
|
40
|
+
frontmatter: {
|
|
41
|
+
sidebar: sidebarConfig = true,
|
|
42
|
+
outline: showOutline = true,
|
|
43
|
+
},
|
|
41
44
|
} = useFrontmatter();
|
|
45
|
+
const showSidebar = sidebarConfig === true;
|
|
42
46
|
|
|
43
47
|
function openSidebar() {
|
|
44
48
|
onIsSidebarOpenChange(true);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { stderr, stdout } from "../utils-De75vAgL.js";
|
|
2
|
+
import { getHandler, throwInNextTick } from "../utils-B--2TaWv.js";
|
|
3
|
+
process.__tinypool_state__ = {
|
|
4
|
+
isChildProcess: true,
|
|
5
|
+
isTinypoolWorker: true,
|
|
6
|
+
workerData: null,
|
|
7
|
+
workerId: Number(process.env.TINYPOOL_WORKER_ID)
|
|
8
|
+
};
|
|
9
|
+
const memoryUsage = process.memoryUsage.bind(process);
|
|
10
|
+
const send = process.send.bind(process);
|
|
11
|
+
process.on("message", (message)=>{
|
|
12
|
+
if (!message || !message.__tinypool_worker_message__) return;
|
|
13
|
+
if ("pool" === message.source) {
|
|
14
|
+
const { filename, name } = message;
|
|
15
|
+
(async function() {
|
|
16
|
+
if (null !== filename) await getHandler(filename, name);
|
|
17
|
+
send({
|
|
18
|
+
ready: true,
|
|
19
|
+
source: "pool",
|
|
20
|
+
__tinypool_worker_message__: true
|
|
21
|
+
}, ()=>{});
|
|
22
|
+
})().catch(throwInNextTick);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if ("port" === message.source) return void onMessage(message).catch(throwInNextTick);
|
|
26
|
+
throw new Error(`Unexpected TinypoolWorkerMessage ${JSON.stringify(message)}`);
|
|
27
|
+
});
|
|
28
|
+
async function onMessage(message) {
|
|
29
|
+
const { taskId, task, filename, name } = message;
|
|
30
|
+
let response;
|
|
31
|
+
try {
|
|
32
|
+
const handler = await getHandler(filename, name);
|
|
33
|
+
if (null === handler) throw new Error(`No handler function "${name}" exported from "${filename}"`);
|
|
34
|
+
const result = await handler(task);
|
|
35
|
+
response = {
|
|
36
|
+
source: "port",
|
|
37
|
+
__tinypool_worker_message__: true,
|
|
38
|
+
taskId,
|
|
39
|
+
result,
|
|
40
|
+
error: null,
|
|
41
|
+
usedMemory: memoryUsage().heapUsed
|
|
42
|
+
};
|
|
43
|
+
if (stdout()?.writableLength > 0) await new Promise((resolve)=>process.stdout.write("", resolve));
|
|
44
|
+
if (stderr()?.writableLength > 0) await new Promise((resolve)=>process.stderr.write("", resolve));
|
|
45
|
+
} catch (error) {
|
|
46
|
+
response = {
|
|
47
|
+
source: "port",
|
|
48
|
+
__tinypool_worker_message__: true,
|
|
49
|
+
taskId,
|
|
50
|
+
result: null,
|
|
51
|
+
error: serializeError(error),
|
|
52
|
+
usedMemory: memoryUsage().heapUsed
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
send(response);
|
|
56
|
+
}
|
|
57
|
+
function serializeError(error) {
|
|
58
|
+
if (error instanceof Error) return {
|
|
59
|
+
...error,
|
|
60
|
+
name: error.name,
|
|
61
|
+
stack: error.stack,
|
|
62
|
+
message: error.message
|
|
63
|
+
};
|
|
64
|
+
return String(error);
|
|
65
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { isMovable, kRequestCountField, kResponseCountField, kTransferable, kValue } from "../common-Qw-RoVFD.js";
|
|
2
|
+
import { stderr, stdout } from "../utils-De75vAgL.js";
|
|
3
|
+
import { getHandler, throwInNextTick } from "../utils-B--2TaWv.js";
|
|
4
|
+
import { parentPort, receiveMessageOnPort, workerData } from "node:worker_threads";
|
|
5
|
+
const [tinypoolPrivateData, workerData$1] = workerData;
|
|
6
|
+
process.__tinypool_state__ = {
|
|
7
|
+
isWorkerThread: true,
|
|
8
|
+
isTinypoolWorker: true,
|
|
9
|
+
workerData: workerData$1,
|
|
10
|
+
workerId: tinypoolPrivateData.workerId
|
|
11
|
+
};
|
|
12
|
+
const memoryUsage = process.memoryUsage.bind(process);
|
|
13
|
+
let useAtomics = "1" !== process.env.PISCINA_DISABLE_ATOMICS;
|
|
14
|
+
parentPort.on("message", (message)=>{
|
|
15
|
+
useAtomics = "1" === process.env.PISCINA_DISABLE_ATOMICS ? false : message.useAtomics;
|
|
16
|
+
const { port, sharedBuffer, filename, name } = message;
|
|
17
|
+
(async function() {
|
|
18
|
+
if (null !== filename) await getHandler(filename, name);
|
|
19
|
+
const readyMessage = {
|
|
20
|
+
ready: true
|
|
21
|
+
};
|
|
22
|
+
parentPort.postMessage(readyMessage);
|
|
23
|
+
port.start();
|
|
24
|
+
port.on("message", onMessage.bind(null, port, sharedBuffer));
|
|
25
|
+
atomicsWaitLoop(port, sharedBuffer);
|
|
26
|
+
})().catch(throwInNextTick);
|
|
27
|
+
});
|
|
28
|
+
let currentTasks = 0;
|
|
29
|
+
let lastSeenRequestCount = 0;
|
|
30
|
+
function atomicsWaitLoop(port, sharedBuffer) {
|
|
31
|
+
if (!useAtomics) return;
|
|
32
|
+
while(0 === currentTasks){
|
|
33
|
+
Atomics.wait(sharedBuffer, kRequestCountField, lastSeenRequestCount);
|
|
34
|
+
lastSeenRequestCount = Atomics.load(sharedBuffer, kRequestCountField);
|
|
35
|
+
let entry;
|
|
36
|
+
while(void 0 !== (entry = receiveMessageOnPort(port)))onMessage(port, sharedBuffer, entry.message);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function onMessage(port, sharedBuffer, message) {
|
|
40
|
+
currentTasks++;
|
|
41
|
+
const { taskId, task, filename, name } = message;
|
|
42
|
+
(async function() {
|
|
43
|
+
let response;
|
|
44
|
+
let transferList = [];
|
|
45
|
+
try {
|
|
46
|
+
const handler = await getHandler(filename, name);
|
|
47
|
+
if (null === handler) throw new Error(`No handler function "${name}" exported from "${filename}"`);
|
|
48
|
+
let result = await handler(task);
|
|
49
|
+
if (isMovable(result)) {
|
|
50
|
+
transferList = transferList.concat(result[kTransferable]);
|
|
51
|
+
result = result[kValue];
|
|
52
|
+
}
|
|
53
|
+
response = {
|
|
54
|
+
taskId,
|
|
55
|
+
result,
|
|
56
|
+
error: null,
|
|
57
|
+
usedMemory: memoryUsage().heapUsed
|
|
58
|
+
};
|
|
59
|
+
if (stdout()?.writableLength > 0) await new Promise((resolve)=>process.stdout.write("", resolve));
|
|
60
|
+
if (stderr()?.writableLength > 0) await new Promise((resolve)=>process.stderr.write("", resolve));
|
|
61
|
+
} catch (error) {
|
|
62
|
+
response = {
|
|
63
|
+
taskId,
|
|
64
|
+
result: null,
|
|
65
|
+
error,
|
|
66
|
+
usedMemory: memoryUsage().heapUsed
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
currentTasks--;
|
|
70
|
+
port.postMessage(response, transferList);
|
|
71
|
+
Atomics.add(sharedBuffer, kResponseCountField, 1);
|
|
72
|
+
atomicsWaitLoop(port, sharedBuffer);
|
|
73
|
+
})().catch(throwInNextTick);
|
|
74
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export { getIconUrlPath, getNodeAttribute, mergeDocConfig, } from '@rspress/shar
|
|
|
5
5
|
export { matchPath } from 'react-router-dom';
|
|
6
6
|
export type { UserConfigAsyncFn } from './config/defineConfig.js';
|
|
7
7
|
export { defineConfig } from './config/defineConfig.js';
|
|
8
|
-
export { build, dev, remarkFileCodeBlock, remarkLink, serve } from './node/index.js';
|
|
8
|
+
export { build, dev, remarkFileCodeBlock, remarkImage, remarkLink, serve, } from './node/index.js';
|
|
9
9
|
export type { CustomLinkMeta, DirSectionHeaderSideMeta, DirSideMeta, DividerSideMeta, FileSideMeta, MetaJson, NavJson, SectionHeaderMeta, SideMeta, SideMetaItem, } from './node/auto-nav-sidebar/type.js';
|
|
10
10
|
export { PluginDriver } from './node/PluginDriver.js';
|
|
11
11
|
export { RouteService } from './node/route/RouteService.js';
|
package/dist/index.js
CHANGED
|
@@ -5,5 +5,6 @@ export { build } from "./node/build.js";
|
|
|
5
5
|
export { defineConfig } from "./config/defineConfig.js";
|
|
6
6
|
export { dev } from "./node/dev.js";
|
|
7
7
|
export { remarkFileCodeBlock } from "./node/mdx/remarkPlugins/fileCodeBlock.js";
|
|
8
|
+
export { remarkImage } from "./node/mdx/remarkPlugins/image.js";
|
|
8
9
|
export { remarkLink } from "./node/mdx/remarkPlugins/link.js";
|
|
9
10
|
export { serve } from "./node/serve.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { addTrailingSlash, node_path, addLeadingSlash } from "../
|
|
1
|
+
import { addTrailingSlash, node_path, addLeadingSlash } from "../5810.js";
|
|
2
2
|
import { createError } from "./utils/error.js";
|
|
3
3
|
import { haveNavSidebarConfig as auto_nav_sidebar_haveNavSidebarConfig } from "./auto-nav-sidebar/index.js";
|
|
4
4
|
class PluginDriver {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DEFAULT_PAGE_EXTENSIONS, node_path } from "../../
|
|
1
|
+
import { DEFAULT_PAGE_EXTENSIONS, node_path } from "../../5810.js";
|
|
2
2
|
import { processLocales, combineWalkResult } from "./locales.js";
|
|
3
3
|
import { walk } from "./walk.js";
|
|
4
4
|
async function runAutoNavSide(config, metaFileSet, mdFileSet) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __webpack_require__ } from "../../0~rslib-runtime.js";
|
|
2
2
|
import "../../8006.js";
|
|
3
|
-
import { extname, logger,
|
|
3
|
+
import { extname, logger, promises_readdir, external_node_path_relative, isExternalUrl, slash, promises_stat, join } from "../../5810.js";
|
|
4
4
|
import { createError } from "../utils/error.js";
|
|
5
5
|
import { PUBLIC_DIR } from "../constants.js";
|
|
6
6
|
import { pathExists, extractInfoFromFrontmatterWithAbsolutePath, readJson } from "./utils.js";
|
|
@@ -15,7 +15,7 @@ function getFileKey(realPath, docsDir) {
|
|
|
15
15
|
async function fsDirToMetaItems(workDir, docsDir, extensions) {
|
|
16
16
|
let subItems;
|
|
17
17
|
try {
|
|
18
|
-
subItems = (await
|
|
18
|
+
subItems = (await promises_readdir(workDir)).sort((a, b)=>{
|
|
19
19
|
const aIsIndex = 'index' === a.replace(/\.[^/.]+$/, '');
|
|
20
20
|
const bIsIndex = 'index' === b.replace(/\.[^/.]+$/, '');
|
|
21
21
|
if (aIsIndex !== bIsIndex) return aIsIndex ? -1 : 1;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isExternalUrl, node_path, promises } from "../../
|
|
1
|
+
import { isExternalUrl, node_path, promises } from "../../5810.js";
|
|
2
2
|
import { pathExists } from "../utils/fs.js";
|
|
3
3
|
import { readJson } from "./utils.js";
|
|
4
4
|
import { addRoutePrefix } from "../route/RoutePage.js";
|