@rspress/shared 2.0.0-beta.16 → 2.0.0-beta.18
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 +9 -8
- package/dist/index.js +20 -25
- package/dist/node-utils.d.ts +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
@@ -221,7 +221,7 @@ export declare interface FrontMatterMeta {
|
|
221
221
|
* @param currentPathname
|
222
222
|
* @returns
|
223
223
|
*/
|
224
|
-
export declare const getSidebarDataGroup: (sidebar: NormalizedSidebar, currentPathname: string
|
224
|
+
export declare const getSidebarDataGroup: (sidebar: NormalizedSidebar, currentPathname: string) => NormalizedSidebar[string];
|
225
225
|
|
226
226
|
export declare const HASH_REGEXP: RegExp;
|
227
227
|
|
@@ -363,14 +363,14 @@ export declare interface MarkdownOptions {
|
|
363
363
|
crossCompilerCache?: boolean;
|
364
364
|
}
|
365
365
|
|
366
|
-
export declare const matchNavbar: (item: NavItemWithLink, currentPathname: string
|
366
|
+
export declare const matchNavbar: (item: NavItemWithLink, currentPathname: string) => boolean;
|
367
367
|
|
368
368
|
/**
|
369
369
|
* match the sidebar key in user config
|
370
370
|
* @param pattern /zh/guide
|
371
371
|
* @param currentPathname /base/zh/guide/getting-started
|
372
372
|
*/
|
373
|
-
export declare const matchSidebar: (pattern: string, currentPathname: string
|
373
|
+
export declare const matchSidebar: (pattern: string, currentPathname: string) => boolean;
|
374
374
|
|
375
375
|
export declare const MDX_OR_MD_REGEXP: RegExp;
|
376
376
|
|
@@ -415,12 +415,16 @@ export declare interface NormalizedLocales extends Omit<LocaleConfig, 'sidebar'>
|
|
415
415
|
sidebar: NormalizedSidebar;
|
416
416
|
}
|
417
417
|
|
418
|
+
export declare interface NormalizedRuntimeConfig {
|
419
|
+
base: string;
|
420
|
+
}
|
421
|
+
|
418
422
|
export declare interface NormalizedSidebar {
|
419
423
|
[path: string]: (NormalizedSidebarGroup | SidebarItem | SidebarDivider)[];
|
420
424
|
}
|
421
425
|
|
422
426
|
export declare interface NormalizedSidebarGroup extends Omit<SidebarGroup, 'items'> {
|
423
|
-
items: (SidebarDivider | SidebarItem | NormalizedSidebarGroup)[];
|
427
|
+
items: (SidebarDivider | SidebarItem | SidebarSectionHeader | NormalizedSidebarGroup)[];
|
424
428
|
collapsible: boolean;
|
425
429
|
collapsed: boolean;
|
426
430
|
}
|
@@ -676,7 +680,7 @@ export declare interface SidebarGroup {
|
|
676
680
|
text: string;
|
677
681
|
link?: string;
|
678
682
|
tag?: string;
|
679
|
-
items: (
|
683
|
+
items: (SidebarGroup | SidebarItem | SidebarDivider | SidebarSectionHeader)[];
|
680
684
|
collapsible?: boolean;
|
681
685
|
collapsed?: boolean;
|
682
686
|
/**
|
@@ -706,7 +710,6 @@ export declare type SidebarSectionHeader = {
|
|
706
710
|
|
707
711
|
export declare interface SiteData<ThemeConfig = NormalizedConfig> {
|
708
712
|
root: string;
|
709
|
-
base: string;
|
710
713
|
lang: string;
|
711
714
|
route: RouteOptions;
|
712
715
|
locales: {
|
@@ -894,8 +897,6 @@ export declare interface UserConfig<ThemeConfig = DefaultThemeConfig> {
|
|
894
897
|
|
895
898
|
export declare function withBase(url: string, base: string): string;
|
896
899
|
|
897
|
-
export declare function withoutBase(path: string, base: string): string;
|
898
|
-
|
899
900
|
export declare function withoutLang(path: string, langs: string[]): string;
|
900
901
|
|
901
902
|
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?$/;
|
@@ -100,11 +115,11 @@ function replaceLang(rawUrl, lang, version, base = '', cleanUrls = false, isPage
|
|
100
115
|
} else parts.shift();
|
101
116
|
purePathPart = parts.join('/') || '';
|
102
117
|
if ((versionPart || langPart) && !purePathPart) purePathPart = cleanUrls ? 'index' : 'index.html';
|
103
|
-
return
|
118
|
+
return addLeadingSlash([
|
104
119
|
versionPart,
|
105
120
|
langPart,
|
106
121
|
purePathPart
|
107
|
-
].filter(Boolean).join('/'))
|
122
|
+
].filter(Boolean).join('/'));
|
108
123
|
}
|
109
124
|
function replaceVersion(rawUrl, version, base = '', cleanUrls = false, isPageNotFound = false) {
|
110
125
|
let url = removeBase(rawUrl, base);
|
@@ -117,10 +132,10 @@ function replaceVersion(rawUrl, version, base = '', cleanUrls = false, isPageNot
|
|
117
132
|
} else parts.shift();
|
118
133
|
let restPart = parts.join('/') || '';
|
119
134
|
if (versionPart && !restPart) restPart = cleanUrls ? 'index' : 'index.html';
|
120
|
-
return
|
135
|
+
return addLeadingSlash([
|
121
136
|
versionPart,
|
122
137
|
restPart
|
123
|
-
].filter(Boolean).join('/'))
|
138
|
+
].filter(Boolean).join('/'));
|
124
139
|
}
|
125
140
|
const parseUrl = (url)=>{
|
126
141
|
const [withoutHash, hash = ''] = url.split('#');
|
@@ -145,9 +160,6 @@ function withoutLang(path, langs) {
|
|
145
160
|
const langRegexp = new RegExp(`^\\/(${langs.join('|')})`);
|
146
161
|
return addLeadingSlash(path.replace(langRegexp, ''));
|
147
162
|
}
|
148
|
-
function withoutBase(path, base) {
|
149
|
-
return addLeadingSlash(path).replace(normalizeSlash(base), '');
|
150
|
-
}
|
151
163
|
function withBase(url, base) {
|
152
164
|
const normalizedUrl = addLeadingSlash(url);
|
153
165
|
const normalizedBase = normalizeSlash(base);
|
@@ -156,21 +168,4 @@ function withBase(url, base) {
|
|
156
168
|
function removeBase(url, base) {
|
157
169
|
return addLeadingSlash(url).replace(new RegExp(`^${normalizeSlash(base)}`), '');
|
158
170
|
}
|
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 };
|
171
|
+
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, withoutLang };
|
package/dist/node-utils.d.ts
CHANGED
@@ -539,7 +539,7 @@ declare interface SidebarGroup {
|
|
539
539
|
text: string;
|
540
540
|
link?: string;
|
541
541
|
tag?: string;
|
542
|
-
items: (
|
542
|
+
items: (SidebarGroup | SidebarItem | SidebarDivider | SidebarSectionHeader)[];
|
543
543
|
collapsible?: boolean;
|
544
544
|
collapsed?: boolean;
|
545
545
|
/**
|
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.18",
|
4
4
|
"repository": {
|
5
5
|
"type": "git",
|
6
6
|
"url": "git+https://github.com/web-infra-dev/rspress.git",
|
@@ -32,14 +32,14 @@
|
|
32
32
|
"dist"
|
33
33
|
],
|
34
34
|
"dependencies": {
|
35
|
-
"@rsbuild/core": "~1.
|
35
|
+
"@rsbuild/core": "~1.4.0",
|
36
36
|
"@shikijs/rehype": "^3.4.2",
|
37
37
|
"gray-matter": "4.0.3",
|
38
38
|
"lodash-es": "^4.17.21",
|
39
39
|
"unified": "^11.0.5"
|
40
40
|
},
|
41
41
|
"devDependencies": {
|
42
|
-
"@rslib/core": "0.10.
|
42
|
+
"@rslib/core": "0.10.3",
|
43
43
|
"@types/jest": "~29.5.14",
|
44
44
|
"@types/lodash-es": "^4.17.12",
|
45
45
|
"@types/node": "^22.8.1",
|