@rspress/shared 2.0.0-beta.2 → 2.0.0-beta.21
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/index.d.ts +24 -41
- package/dist/index.js +20 -26
- package/dist/logger.js +2 -3
- package/dist/node-utils.d.ts +27 -30
- package/dist/node-utils.js +30 -12
- package/package.json +7 -6
package/dist/index.d.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import type { loadConfig } from '@rsbuild/core';
|
2
2
|
import type { PluggableList } from 'unified';
|
3
|
+
import type { RehypeShikiOptions } from '@shikijs/rehype';
|
3
4
|
import type { RsbuildConfig } from '@rsbuild/core';
|
4
|
-
import type { RsbuildPlugin } from '@rsbuild/core';
|
5
5
|
|
6
6
|
/**
|
7
7
|
* There are two ways to define what addition routes represent.
|
@@ -143,7 +143,7 @@ export declare interface DefaultThemeConfig {
|
|
143
143
|
* Whether to redirect to the closest locale when the user visits the site
|
144
144
|
* @default 'auto'
|
145
145
|
*/
|
146
|
-
localeRedirect?: 'auto' | 'never';
|
146
|
+
localeRedirect?: 'auto' | 'never' | 'only-default-lang';
|
147
147
|
/**
|
148
148
|
* Whether to show the fallback heading title when the heading title is not presented but `frontmatter.title` exists
|
149
149
|
* @default true
|
@@ -220,7 +220,7 @@ export declare interface FrontMatterMeta {
|
|
220
220
|
* @param currentPathname
|
221
221
|
* @returns
|
222
222
|
*/
|
223
|
-
export declare const getSidebarDataGroup: (sidebar: NormalizedSidebar, currentPathname: string
|
223
|
+
export declare const getSidebarDataGroup: (sidebar: NormalizedSidebar, currentPathname: string) => NormalizedSidebar[string];
|
224
224
|
|
225
225
|
export declare const HASH_REGEXP: RegExp;
|
226
226
|
|
@@ -273,8 +273,6 @@ export declare function isExternalUrl(url?: string): boolean;
|
|
273
273
|
|
274
274
|
export declare const isProduction: () => boolean;
|
275
275
|
|
276
|
-
export declare const isSCM: () => boolean;
|
277
|
-
|
278
276
|
export declare interface Locale {
|
279
277
|
lang: string;
|
280
278
|
label: string;
|
@@ -330,7 +328,7 @@ export declare type LocalSearchOptions = SearchHooks & {
|
|
330
328
|
versioned?: boolean;
|
331
329
|
/**
|
332
330
|
* If enabled, the search index will include code block content, which allows users to search code blocks.
|
333
|
-
* @default
|
331
|
+
* @default true
|
334
332
|
*/
|
335
333
|
codeBlocks?: boolean;
|
336
334
|
};
|
@@ -352,23 +350,24 @@ export declare interface MarkdownOptions {
|
|
352
350
|
*/
|
353
351
|
globalComponents?: string[];
|
354
352
|
/**
|
355
|
-
*
|
353
|
+
* @type import('@shikijs/rehype').RehypeShikiOptions
|
356
354
|
*/
|
357
|
-
|
355
|
+
shiki?: Partial<PluginShikiOptions>;
|
358
356
|
/**
|
359
|
-
*
|
357
|
+
* Speed up build time by caching mdx parsing result in `rspress build`
|
358
|
+
* @default true
|
360
359
|
*/
|
361
|
-
|
360
|
+
crossCompilerCache?: boolean;
|
362
361
|
}
|
363
362
|
|
364
|
-
export declare const matchNavbar: (item: NavItemWithLink, currentPathname: string
|
363
|
+
export declare const matchNavbar: (item: NavItemWithLink, currentPathname: string) => boolean;
|
365
364
|
|
366
365
|
/**
|
367
366
|
* match the sidebar key in user config
|
368
367
|
* @param pattern /zh/guide
|
369
368
|
* @param currentPathname /base/zh/guide/getting-started
|
370
369
|
*/
|
371
|
-
export declare const matchSidebar: (pattern: string, currentPathname: string
|
370
|
+
export declare const matchSidebar: (pattern: string, currentPathname: string) => boolean;
|
372
371
|
|
373
372
|
export declare const MDX_OR_MD_REGEXP: RegExp;
|
374
373
|
|
@@ -413,12 +412,16 @@ export declare interface NormalizedLocales extends Omit<LocaleConfig, 'sidebar'>
|
|
413
412
|
sidebar: NormalizedSidebar;
|
414
413
|
}
|
415
414
|
|
415
|
+
export declare interface NormalizedRuntimeConfig {
|
416
|
+
base: string;
|
417
|
+
}
|
418
|
+
|
416
419
|
export declare interface NormalizedSidebar {
|
417
420
|
[path: string]: (NormalizedSidebarGroup | SidebarItem | SidebarDivider)[];
|
418
421
|
}
|
419
422
|
|
420
423
|
export declare interface NormalizedSidebarGroup extends Omit<SidebarGroup, 'items'> {
|
421
|
-
items: (SidebarDivider | SidebarItem | NormalizedSidebarGroup)[];
|
424
|
+
items: (SidebarDivider | SidebarItem | SidebarSectionHeader | NormalizedSidebarGroup)[];
|
422
425
|
collapsible: boolean;
|
423
426
|
collapsed: boolean;
|
424
427
|
}
|
@@ -447,9 +450,8 @@ export declare interface PageData {
|
|
447
450
|
* and should not be used in the runtime (usePageData).
|
448
451
|
*/
|
449
452
|
export declare interface PageIndexInfo {
|
450
|
-
id: number;
|
451
|
-
title: string;
|
452
453
|
routePath: string;
|
454
|
+
title: string;
|
453
455
|
toc: Header[];
|
454
456
|
content: string;
|
455
457
|
_flattenContent?: string;
|
@@ -457,7 +459,6 @@ export declare interface PageIndexInfo {
|
|
457
459
|
frontmatter: FrontMatterMeta;
|
458
460
|
lang: string;
|
459
461
|
version: string;
|
460
|
-
domain: string;
|
461
462
|
_filepath: string;
|
462
463
|
_relativePath: string;
|
463
464
|
}
|
@@ -476,6 +477,8 @@ export declare const parseUrl: (url: string) => {
|
|
476
477
|
hash: string;
|
477
478
|
};
|
478
479
|
|
480
|
+
declare type PluginShikiOptions = RehypeShikiOptions;
|
481
|
+
|
479
482
|
export declare const QUERY_REGEXP: RegExp;
|
480
483
|
|
481
484
|
export declare type RemotePageInfo = PageIndexInfo & {
|
@@ -487,20 +490,6 @@ export declare type RemotePageInfo = PageIndexInfo & {
|
|
487
490
|
};
|
488
491
|
};
|
489
492
|
|
490
|
-
export declare type RemoteSearchIndexInfo = string | {
|
491
|
-
value: string;
|
492
|
-
label: string;
|
493
|
-
};
|
494
|
-
|
495
|
-
export declare type RemoteSearchOptions = SearchHooks & {
|
496
|
-
mode: 'remote';
|
497
|
-
apiUrl: string;
|
498
|
-
domain?: string;
|
499
|
-
indexName: string;
|
500
|
-
searchIndexes?: RemoteSearchIndexInfo[];
|
501
|
-
searchLoading?: boolean;
|
502
|
-
};
|
503
|
-
|
504
493
|
export declare function removeBase(url: string, base: string): string;
|
505
494
|
|
506
495
|
export declare function removeHash(str: string): string;
|
@@ -622,6 +611,7 @@ declare interface RspressPlugin {
|
|
622
611
|
addPages?: (config: UserConfig, isProd: boolean) => AdditionalPage[] | Promise<AdditionalPage[]>;
|
623
612
|
/**
|
624
613
|
* Add runtime modules
|
614
|
+
* @deprecated use [rsbuild-plugin-virtual-module](https://github.com/rspack-contrib/rsbuild-plugin-virtual-module) instead.
|
625
615
|
*/
|
626
616
|
addRuntimeModules?: (config: UserConfig, isProd: boolean) => Record<string, string> | Promise<Record<string, string>>;
|
627
617
|
/**
|
@@ -658,7 +648,7 @@ export declare interface SearchHooks {
|
|
658
648
|
searchHooks?: string;
|
659
649
|
}
|
660
650
|
|
661
|
-
export declare type SearchOptions = LocalSearchOptions |
|
651
|
+
export declare type SearchOptions = LocalSearchOptions | false;
|
662
652
|
|
663
653
|
export declare interface Sidebar {
|
664
654
|
[path: string]: (SidebarGroup | SidebarItem | SidebarDivider | SidebarSectionHeader)[];
|
@@ -672,7 +662,7 @@ export declare interface SidebarGroup {
|
|
672
662
|
text: string;
|
673
663
|
link?: string;
|
674
664
|
tag?: string;
|
675
|
-
items: (
|
665
|
+
items: (SidebarGroup | SidebarItem | SidebarDivider | SidebarSectionHeader)[];
|
676
666
|
collapsible?: boolean;
|
677
667
|
collapsed?: boolean;
|
678
668
|
/**
|
@@ -702,7 +692,6 @@ export declare type SidebarSectionHeader = {
|
|
702
692
|
|
703
693
|
export declare interface SiteData<ThemeConfig = NormalizedConfig> {
|
704
694
|
root: string;
|
705
|
-
base: string;
|
706
695
|
lang: string;
|
707
696
|
route: RouteOptions;
|
708
697
|
locales: {
|
@@ -724,7 +713,7 @@ export declare interface SiteData<ThemeConfig = NormalizedConfig> {
|
|
724
713
|
markdown: {
|
725
714
|
showLineNumbers: boolean;
|
726
715
|
defaultWrapCode: boolean;
|
727
|
-
|
716
|
+
shiki: Partial<PluginShikiOptions>;
|
728
717
|
};
|
729
718
|
multiVersion: {
|
730
719
|
default: string;
|
@@ -770,7 +759,7 @@ export declare interface UserConfig<ThemeConfig = DefaultThemeConfig> {
|
|
770
759
|
/**
|
771
760
|
* Path to html icon file.
|
772
761
|
*/
|
773
|
-
icon?: string;
|
762
|
+
icon?: string | URL;
|
774
763
|
/**
|
775
764
|
* Default language of the site.
|
776
765
|
*/
|
@@ -852,10 +841,6 @@ export declare interface UserConfig<ThemeConfig = DefaultThemeConfig> {
|
|
852
841
|
selector?: string;
|
853
842
|
options?: ZoomOptions;
|
854
843
|
};
|
855
|
-
/**
|
856
|
-
* Add some extra builder plugins
|
857
|
-
*/
|
858
|
-
builderPlugins?: RsbuildPlugin[];
|
859
844
|
/**
|
860
845
|
* Multi version config
|
861
846
|
*/
|
@@ -890,8 +875,6 @@ export declare interface UserConfig<ThemeConfig = DefaultThemeConfig> {
|
|
890
875
|
|
891
876
|
export declare function withBase(url: string, base: string): string;
|
892
877
|
|
893
|
-
export declare function withoutBase(path: string, base: string): string;
|
894
|
-
|
895
878
|
export declare function withoutLang(path: string, langs: string[]): string;
|
896
879
|
|
897
880
|
declare interface ZoomContainer {
|
package/dist/index.js
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
const matchSidebar = (pattern, currentPathname)=>{
|
2
|
+
if (pattern === currentPathname) return true;
|
3
|
+
if (currentPathname.startsWith(pattern)) return true;
|
4
|
+
const prefixWithDot = `${pattern}.`;
|
5
|
+
return currentPathname.startsWith(prefixWithDot);
|
6
|
+
};
|
7
|
+
const getSidebarDataGroup = (sidebar, currentPathname)=>{
|
8
|
+
const navRoutes = Object.keys(sidebar).sort((a, b)=>b.length - a.length);
|
9
|
+
for (const name of navRoutes)if (matchSidebar(name, currentPathname)) {
|
10
|
+
const sidebarGroup = sidebar[name];
|
11
|
+
return sidebarGroup;
|
12
|
+
}
|
13
|
+
return [];
|
14
|
+
};
|
15
|
+
const matchNavbar = (item, currentPathname)=>new RegExp(item.activeMatch || item.link).test(currentPathname);
|
1
16
|
const QUERY_REGEXP = /\?.*$/s;
|
2
17
|
const HASH_REGEXP = /#.*$/s;
|
3
18
|
const MDX_OR_MD_REGEXP = /\.mdx?$/;
|
@@ -30,7 +45,6 @@ const DEFAULT_HIGHLIGHT_LANGUAGES = [
|
|
30
45
|
'tsx'
|
31
46
|
]
|
32
47
|
];
|
33
|
-
const isSCM = ()=>Boolean(process.env.BUILD_VERSION);
|
34
48
|
const isProduction = ()=>'production' === process.env.NODE_ENV;
|
35
49
|
const isDebugMode = ()=>{
|
36
50
|
if (!process.env.DEBUG) return false;
|
@@ -100,11 +114,11 @@ function replaceLang(rawUrl, lang, version, base = '', cleanUrls = false, isPage
|
|
100
114
|
} else parts.shift();
|
101
115
|
purePathPart = parts.join('/') || '';
|
102
116
|
if ((versionPart || langPart) && !purePathPart) purePathPart = cleanUrls ? 'index' : 'index.html';
|
103
|
-
return
|
117
|
+
return addLeadingSlash([
|
104
118
|
versionPart,
|
105
119
|
langPart,
|
106
120
|
purePathPart
|
107
|
-
].filter(Boolean).join('/'))
|
121
|
+
].filter(Boolean).join('/'));
|
108
122
|
}
|
109
123
|
function replaceVersion(rawUrl, version, base = '', cleanUrls = false, isPageNotFound = false) {
|
110
124
|
let url = removeBase(rawUrl, base);
|
@@ -117,10 +131,10 @@ function replaceVersion(rawUrl, version, base = '', cleanUrls = false, isPageNot
|
|
117
131
|
} else parts.shift();
|
118
132
|
let restPart = parts.join('/') || '';
|
119
133
|
if (versionPart && !restPart) restPart = cleanUrls ? 'index' : 'index.html';
|
120
|
-
return
|
134
|
+
return addLeadingSlash([
|
121
135
|
versionPart,
|
122
136
|
restPart
|
123
|
-
].filter(Boolean).join('/'))
|
137
|
+
].filter(Boolean).join('/'));
|
124
138
|
}
|
125
139
|
const parseUrl = (url)=>{
|
126
140
|
const [withoutHash, hash = ''] = url.split('#');
|
@@ -145,9 +159,6 @@ function withoutLang(path, langs) {
|
|
145
159
|
const langRegexp = new RegExp(`^\\/(${langs.join('|')})`);
|
146
160
|
return addLeadingSlash(path.replace(langRegexp, ''));
|
147
161
|
}
|
148
|
-
function withoutBase(path, base) {
|
149
|
-
return addLeadingSlash(path).replace(normalizeSlash(base), '');
|
150
|
-
}
|
151
162
|
function withBase(url, base) {
|
152
163
|
const normalizedUrl = addLeadingSlash(url);
|
153
164
|
const normalizedBase = normalizeSlash(base);
|
@@ -156,21 +167,4 @@ function withBase(url, base) {
|
|
156
167
|
function removeBase(url, base) {
|
157
168
|
return addLeadingSlash(url).replace(new RegExp(`^${normalizeSlash(base)}`), '');
|
158
169
|
}
|
159
|
-
|
160
|
-
const prefix = withBase(pattern, base);
|
161
|
-
if (prefix === currentPathname) return true;
|
162
|
-
const prefixWithTrailingSlash = addTrailingSlash(prefix);
|
163
|
-
if (currentPathname.startsWith(prefixWithTrailingSlash)) return true;
|
164
|
-
const prefixWithDot = `${prefix}.`;
|
165
|
-
return currentPathname.startsWith(prefixWithDot);
|
166
|
-
};
|
167
|
-
const getSidebarDataGroup = (sidebar, currentPathname, base)=>{
|
168
|
-
const navRoutes = Object.keys(sidebar).sort((a, b)=>b.length - a.length);
|
169
|
-
for (const name of navRoutes)if (matchSidebar(name, currentPathname, base)) {
|
170
|
-
const sidebarGroup = sidebar[name];
|
171
|
-
return sidebarGroup;
|
172
|
-
}
|
173
|
-
return [];
|
174
|
-
};
|
175
|
-
const matchNavbar = (item, currentPathname, base)=>new RegExp(item.activeMatch || item.link).test(withoutBase(currentPathname, base));
|
176
|
-
export { APPEARANCE_KEY, DEFAULT_HIGHLIGHT_LANGUAGES, HASH_REGEXP, MDX_OR_MD_REGEXP, QUERY_REGEXP, RSPRESS_TEMP_DIR, SEARCH_INDEX_NAME, addLeadingSlash, addTrailingSlash, utils_cleanUrl as cleanUrl, getSidebarDataGroup, inBrowser, isDataUrl, isDebugMode, isDevDebugMode, isExternalUrl, isProduction, isSCM, matchNavbar, matchSidebar, normalizeHref, normalizePosixPath, normalizeSlash, parseUrl, removeBase, removeHash, removeLeadingSlash, removeTrailingSlash, replaceLang, replaceVersion, slash, withBase, withoutBase, withoutLang };
|
170
|
+
export { APPEARANCE_KEY, DEFAULT_HIGHLIGHT_LANGUAGES, HASH_REGEXP, MDX_OR_MD_REGEXP, QUERY_REGEXP, RSPRESS_TEMP_DIR, SEARCH_INDEX_NAME, addLeadingSlash, addTrailingSlash, utils_cleanUrl as cleanUrl, getSidebarDataGroup, inBrowser, isDataUrl, isDebugMode, isDevDebugMode, isExternalUrl, isProduction, matchNavbar, matchSidebar, normalizeHref, normalizePosixPath, normalizeSlash, parseUrl, removeBase, removeHash, removeLeadingSlash, removeTrailingSlash, replaceLang, replaceVersion, slash, withBase, withoutLang };
|
package/dist/logger.js
CHANGED
@@ -1,3 +1,2 @@
|
|
1
|
-
import
|
2
|
-
|
3
|
-
export { __webpack_exports__logger as logger };
|
1
|
+
import { logger } from "@rsbuild/core";
|
2
|
+
export { logger };
|
package/dist/node-utils.d.ts
CHANGED
@@ -4,8 +4,8 @@ import type { MdxJsxExpressionAttribute } from 'mdast-util-mdx-jsx';
|
|
4
4
|
import type { MdxJsxFlowElement } from 'mdast-util-mdx-jsx';
|
5
5
|
import type { MdxJsxTextElement } from 'mdast-util-mdx-jsx';
|
6
6
|
import type { PluggableList } from 'unified';
|
7
|
+
import type { RehypeShikiOptions } from '@shikijs/rehype';
|
7
8
|
import type { RsbuildConfig } from '@rsbuild/core';
|
8
|
-
import type { RsbuildPlugin } from '@rsbuild/core';
|
9
9
|
|
10
10
|
/**
|
11
11
|
* There are two ways to define what addition routes represent.
|
@@ -131,7 +131,7 @@ declare interface Config {
|
|
131
131
|
* Whether to redirect to the closest locale when the user visits the site
|
132
132
|
* @default 'auto'
|
133
133
|
*/
|
134
|
-
localeRedirect?: 'auto' | 'never';
|
134
|
+
localeRedirect?: 'auto' | 'never' | 'only-default-lang';
|
135
135
|
/**
|
136
136
|
* Whether to show the fallback heading title when the heading title is not presented but `frontmatter.title` exists
|
137
137
|
* @default true
|
@@ -207,6 +207,18 @@ declare interface FrontMatterMeta {
|
|
207
207
|
[key: string]: unknown;
|
208
208
|
}
|
209
209
|
|
210
|
+
/**
|
211
|
+
* Transform `config.icon` into final url path in the web app
|
212
|
+
*
|
213
|
+
* @param icon original icon in config
|
214
|
+
* @returns final url path in the web app
|
215
|
+
*/
|
216
|
+
export declare function getIconUrlPath(icon: '' | undefined): undefined;
|
217
|
+
|
218
|
+
export declare function getIconUrlPath(icon: string | URL): string;
|
219
|
+
|
220
|
+
export declare function getIconUrlPath(icon: string | URL | undefined): string | undefined;
|
221
|
+
|
210
222
|
export declare function getNodeAttribute(node: MdxJsxFlowElement | MdxJsxTextElement, attrName: string, attribute?: false): string | MdxJsxAttributeValueExpression | null | undefined;
|
211
223
|
|
212
224
|
export declare function getNodeAttribute(node: MdxJsxFlowElement | MdxJsxTextElement, attrName: string, attribute: true): MdxJsxAttribute | MdxJsxExpressionAttribute | undefined;
|
@@ -245,6 +257,7 @@ declare interface Hero {
|
|
245
257
|
export declare function loadFrontMatter<TFrontmatter extends Record<string, unknown> = FrontMatterMeta>(source: string, filepath: string, root: string, outputWarning?: boolean): {
|
246
258
|
frontmatter: TFrontmatter;
|
247
259
|
content: string;
|
260
|
+
emptyLinesSource: string;
|
248
261
|
};
|
249
262
|
|
250
263
|
declare interface Locale {
|
@@ -292,7 +305,7 @@ declare type LocalSearchOptions = SearchHooks & {
|
|
292
305
|
versioned?: boolean;
|
293
306
|
/**
|
294
307
|
* If enabled, the search index will include code block content, which allows users to search code blocks.
|
295
|
-
* @default
|
308
|
+
* @default true
|
296
309
|
*/
|
297
310
|
codeBlocks?: boolean;
|
298
311
|
};
|
@@ -314,13 +327,14 @@ declare interface MarkdownOptions {
|
|
314
327
|
*/
|
315
328
|
globalComponents?: string[];
|
316
329
|
/**
|
317
|
-
*
|
330
|
+
* @type import('@shikijs/rehype').RehypeShikiOptions
|
318
331
|
*/
|
319
|
-
|
332
|
+
shiki?: Partial<PluginShikiOptions>;
|
320
333
|
/**
|
321
|
-
*
|
334
|
+
* Speed up build time by caching mdx parsing result in `rspress build`
|
335
|
+
* @default true
|
322
336
|
*/
|
323
|
-
|
337
|
+
crossCompilerCache?: boolean;
|
324
338
|
}
|
325
339
|
|
326
340
|
export declare const mergeDocConfig: (...configs: UserConfig[]) => Promise<UserConfig>;
|
@@ -361,9 +375,8 @@ declare interface NavItemWithLinkAndChildren {
|
|
361
375
|
* and should not be used in the runtime (usePageData).
|
362
376
|
*/
|
363
377
|
declare interface PageIndexInfo {
|
364
|
-
id: number;
|
365
|
-
title: string;
|
366
378
|
routePath: string;
|
379
|
+
title: string;
|
367
380
|
toc: Header[];
|
368
381
|
content: string;
|
369
382
|
_flattenContent?: string;
|
@@ -371,26 +384,13 @@ declare interface PageIndexInfo {
|
|
371
384
|
frontmatter: FrontMatterMeta;
|
372
385
|
lang: string;
|
373
386
|
version: string;
|
374
|
-
domain: string;
|
375
387
|
_filepath: string;
|
376
388
|
_relativePath: string;
|
377
389
|
}
|
378
390
|
|
379
391
|
declare type PageType = 'home' | 'doc' | 'custom' | '404' | 'blank';
|
380
392
|
|
381
|
-
declare type
|
382
|
-
value: string;
|
383
|
-
label: string;
|
384
|
-
};
|
385
|
-
|
386
|
-
declare type RemoteSearchOptions = SearchHooks & {
|
387
|
-
mode: 'remote';
|
388
|
-
apiUrl: string;
|
389
|
-
domain?: string;
|
390
|
-
indexName: string;
|
391
|
-
searchIndexes?: RemoteSearchIndexInfo[];
|
392
|
-
searchLoading?: boolean;
|
393
|
-
};
|
393
|
+
declare type PluginShikiOptions = RehypeShikiOptions;
|
394
394
|
|
395
395
|
declare interface ReplaceRule {
|
396
396
|
search: string | RegExp;
|
@@ -476,6 +476,7 @@ declare interface RspressPlugin {
|
|
476
476
|
addPages?: (config: UserConfig, isProd: boolean) => AdditionalPage[] | Promise<AdditionalPage[]>;
|
477
477
|
/**
|
478
478
|
* Add runtime modules
|
479
|
+
* @deprecated use [rsbuild-plugin-virtual-module](https://github.com/rspack-contrib/rsbuild-plugin-virtual-module) instead.
|
479
480
|
*/
|
480
481
|
addRuntimeModules?: (config: UserConfig, isProd: boolean) => Record<string, string> | Promise<Record<string, string>>;
|
481
482
|
/**
|
@@ -508,7 +509,7 @@ declare interface SearchHooks {
|
|
508
509
|
searchHooks?: string;
|
509
510
|
}
|
510
511
|
|
511
|
-
declare type SearchOptions = LocalSearchOptions |
|
512
|
+
declare type SearchOptions = LocalSearchOptions | false;
|
512
513
|
|
513
514
|
declare interface Sidebar {
|
514
515
|
[path: string]: (SidebarGroup | SidebarItem | SidebarDivider | SidebarSectionHeader)[];
|
@@ -522,7 +523,7 @@ declare interface SidebarGroup {
|
|
522
523
|
text: string;
|
523
524
|
link?: string;
|
524
525
|
tag?: string;
|
525
|
-
items: (
|
526
|
+
items: (SidebarGroup | SidebarItem | SidebarDivider | SidebarSectionHeader)[];
|
526
527
|
collapsible?: boolean;
|
527
528
|
collapsed?: boolean;
|
528
529
|
/**
|
@@ -586,7 +587,7 @@ declare interface UserConfig<ThemeConfig = Config> {
|
|
586
587
|
/**
|
587
588
|
* Path to html icon file.
|
588
589
|
*/
|
589
|
-
icon?: string;
|
590
|
+
icon?: string | URL;
|
590
591
|
/**
|
591
592
|
* Default language of the site.
|
592
593
|
*/
|
@@ -668,10 +669,6 @@ declare interface UserConfig<ThemeConfig = Config> {
|
|
668
669
|
selector?: string;
|
669
670
|
options?: ZoomOptions;
|
670
671
|
};
|
671
|
-
/**
|
672
|
-
* Add some extra builder plugins
|
673
|
-
*/
|
674
|
-
builderPlugins?: RsbuildPlugin[];
|
675
672
|
/**
|
676
673
|
* Multi version config
|
677
674
|
*/
|
package/dist/node-utils.js
CHANGED
@@ -1,36 +1,54 @@
|
|
1
|
-
import
|
2
|
-
import
|
3
|
-
import
|
1
|
+
import node_path from "node:path";
|
2
|
+
import { fileURLToPath } from "node:url";
|
3
|
+
import gray_matter from "gray-matter";
|
4
|
+
import { logger } from "@rsbuild/core";
|
4
5
|
const extractTextAndId = (title)=>{
|
5
6
|
if (!title) return [
|
6
7
|
'',
|
7
8
|
''
|
8
9
|
];
|
9
10
|
const customIdReg = /\\?{#.*}/;
|
10
|
-
|
11
|
-
|
11
|
+
if (customIdReg.test(title)) {
|
12
|
+
const text = title.replace(customIdReg, '').trimEnd();
|
13
|
+
const customId = title.match(customIdReg)?.[0]?.slice(2, -1) || '';
|
14
|
+
return [
|
15
|
+
text,
|
16
|
+
customId
|
17
|
+
];
|
18
|
+
}
|
12
19
|
return [
|
13
|
-
|
14
|
-
|
20
|
+
title,
|
21
|
+
''
|
15
22
|
];
|
16
23
|
};
|
24
|
+
function getIconUrlPath(icon) {
|
25
|
+
if (!icon) return;
|
26
|
+
icon = icon.toString();
|
27
|
+
if (icon.startsWith('file://')) icon = fileURLToPath(icon);
|
28
|
+
if (!node_path.isAbsolute(icon)) return icon;
|
29
|
+
return `/${node_path.basename(icon)}`;
|
30
|
+
}
|
17
31
|
function getNodeAttribute(node, attrName, attribute) {
|
18
32
|
const found = node.attributes.find((attr)=>'name' in attr && attr.name === attrName);
|
19
33
|
return attribute ? found : found?.value;
|
20
34
|
}
|
21
35
|
function loadFrontMatter(source, filepath, root, outputWarning = false) {
|
22
36
|
try {
|
23
|
-
const { content, data } = (
|
37
|
+
const { content, data } = gray_matter(source);
|
38
|
+
const rawFrontMatter = source.slice(0, source.length - content.length);
|
39
|
+
const emptyLinesSource = rawFrontMatter.length ? `${rawFrontMatter.replace(/[^\n]/g, '')}${content}` : content;
|
24
40
|
return {
|
25
41
|
content,
|
26
|
-
frontmatter: data
|
42
|
+
frontmatter: data,
|
43
|
+
emptyLinesSource
|
27
44
|
};
|
28
45
|
} catch (e) {
|
29
|
-
if (outputWarning)
|
46
|
+
if (outputWarning) logger.warn(`Parse frontmatter error in ${node_path.relative(root, filepath)}: \n`, e);
|
30
47
|
}
|
31
48
|
return {
|
32
49
|
content: '',
|
33
|
-
frontmatter: {}
|
50
|
+
frontmatter: {},
|
51
|
+
emptyLinesSource: source
|
34
52
|
};
|
35
53
|
}
|
36
54
|
const castArray = (value)=>Array.isArray(value) ? value : [
|
@@ -50,4 +68,4 @@ const mergeDocConfig = async (...configs)=>{
|
|
50
68
|
];
|
51
69
|
});
|
52
70
|
};
|
53
|
-
export { extractTextAndId, getNodeAttribute, loadFrontMatter, mergeDocConfig };
|
71
|
+
export { extractTextAndId, getIconUrlPath, getNodeAttribute, loadFrontMatter, mergeDocConfig };
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@rspress/shared",
|
3
|
-
"version": "2.0.0-beta.
|
3
|
+
"version": "2.0.0-beta.21",
|
4
4
|
"repository": {
|
5
5
|
"type": "git",
|
6
6
|
"url": "git+https://github.com/web-infra-dev/rspress.git",
|
@@ -32,21 +32,22 @@
|
|
32
32
|
"dist"
|
33
33
|
],
|
34
34
|
"dependencies": {
|
35
|
-
"@rsbuild/core": "1.
|
35
|
+
"@rsbuild/core": "~1.4.6",
|
36
|
+
"@shikijs/rehype": "^3.4.2",
|
36
37
|
"gray-matter": "4.0.3",
|
37
38
|
"lodash-es": "^4.17.21",
|
38
39
|
"unified": "^11.0.5"
|
39
40
|
},
|
40
41
|
"devDependencies": {
|
41
|
-
"@rslib/core": "0.
|
42
|
+
"@rslib/core": "0.10.5",
|
42
43
|
"@types/jest": "~29.5.14",
|
43
44
|
"@types/lodash-es": "^4.17.12",
|
44
|
-
"@types/node": "^
|
45
|
-
"@types/react": "^
|
45
|
+
"@types/node": "^22.8.1",
|
46
|
+
"@types/react": "^19.1.8",
|
46
47
|
"mdast-util-mdx-jsx": "^3.2.0",
|
47
48
|
"medium-zoom": "1.1.0",
|
48
49
|
"rimraf": "^6.0.1",
|
49
|
-
"rsbuild-plugin-publint": "^0.3.
|
50
|
+
"rsbuild-plugin-publint": "^0.3.2",
|
50
51
|
"typescript": "^5.8.2"
|
51
52
|
},
|
52
53
|
"publishConfig": {
|