@rspress-theme-anatole/shared 0.6.3 → 0.6.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/index.js +223 -228
- package/dist/index.mjs +159 -159
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,228 +1,223 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __webpack_require__ = {};
|
|
3
|
-
(()
|
|
4
|
-
__webpack_require__.d = function
|
|
5
|
-
for
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: definition[key]
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
})();
|
|
11
|
-
(()
|
|
12
|
-
__webpack_require__.o = function
|
|
13
|
-
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
14
|
-
};
|
|
15
|
-
})();
|
|
16
|
-
(()
|
|
17
|
-
__webpack_require__.r = function
|
|
18
|
-
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
19
|
-
value: 'Module'
|
|
20
|
-
});
|
|
21
|
-
Object.defineProperty(exports1, '__esModule', {
|
|
22
|
-
value: true
|
|
23
|
-
});
|
|
24
|
-
};
|
|
25
|
-
})();
|
|
26
|
-
var __webpack_exports__ = {};
|
|
27
|
-
__webpack_require__.r(__webpack_exports__);
|
|
28
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
29
|
-
SEARCH_INDEX_NAME: ()
|
|
30
|
-
RSPRESS_TEMP_DIR: ()
|
|
31
|
-
QUERY_REGEXP: ()
|
|
32
|
-
isDebugMode: ()
|
|
33
|
-
addTrailingSlash: ()
|
|
34
|
-
slash: ()
|
|
35
|
-
removeLeadingSlash: ()
|
|
36
|
-
withoutBase: ()
|
|
37
|
-
replaceVersion: ()
|
|
38
|
-
HASH_REGEXP: ()
|
|
39
|
-
isSCM: ()
|
|
40
|
-
MDX_OR_MD_REGEXP: ()
|
|
41
|
-
normalizeHref: ()
|
|
42
|
-
normalizeSlash: ()
|
|
43
|
-
normalizePosixPath: ()
|
|
44
|
-
inBrowser: ()
|
|
45
|
-
isDataUrl: ()
|
|
46
|
-
replaceLang: ()
|
|
47
|
-
removeHash: ()
|
|
48
|
-
cleanUrl: ()
|
|
49
|
-
withBase: ()
|
|
50
|
-
isDevDebugMode: ()
|
|
51
|
-
removeTrailingSlash: ()
|
|
52
|
-
APPEARANCE_KEY: ()
|
|
53
|
-
isExternalUrl: ()
|
|
54
|
-
removeBase: ()
|
|
55
|
-
DEFAULT_HIGHLIGHT_LANGUAGES: ()
|
|
56
|
-
parseUrl: ()
|
|
57
|
-
withoutLang: ()
|
|
58
|
-
isProduction: ()
|
|
59
|
-
addLeadingSlash: ()
|
|
60
|
-
});
|
|
61
|
-
const QUERY_REGEXP = /\?.*$/s;
|
|
62
|
-
const HASH_REGEXP = /#.*$/s;
|
|
63
|
-
const MDX_OR_MD_REGEXP = /\.mdx?$/;
|
|
64
|
-
const APPEARANCE_KEY = 'rspress-theme-appearance';
|
|
65
|
-
const SEARCH_INDEX_NAME = 'search_index';
|
|
66
|
-
const RSPRESS_TEMP_DIR = '.rspress';
|
|
67
|
-
const DEFAULT_HIGHLIGHT_LANGUAGES = [
|
|
68
|
-
[
|
|
69
|
-
'js',
|
|
70
|
-
"javascript"
|
|
71
|
-
],
|
|
72
|
-
[
|
|
73
|
-
'ts',
|
|
74
|
-
"typescript"
|
|
75
|
-
],
|
|
76
|
-
[
|
|
77
|
-
'jsx',
|
|
78
|
-
'tsx'
|
|
79
|
-
],
|
|
80
|
-
[
|
|
81
|
-
'xml',
|
|
82
|
-
'xml-doc'
|
|
83
|
-
],
|
|
84
|
-
[
|
|
85
|
-
'md',
|
|
86
|
-
'markdown'
|
|
87
|
-
],
|
|
88
|
-
[
|
|
89
|
-
'mdx',
|
|
90
|
-
'tsx'
|
|
91
|
-
]
|
|
92
|
-
];
|
|
93
|
-
const isSCM = ()
|
|
94
|
-
const isProduction = ()
|
|
95
|
-
const isDebugMode = ()
|
|
96
|
-
if (!process.env.DEBUG) return false;
|
|
97
|
-
const values = process.env.DEBUG?.toLocaleLowerCase().split(',') ?? [];
|
|
98
|
-
return [
|
|
99
|
-
'rsbuild',
|
|
100
|
-
'builder',
|
|
101
|
-
'*'
|
|
102
|
-
].some((key)
|
|
103
|
-
};
|
|
104
|
-
const isDevDebugMode = ()
|
|
105
|
-
const runtime_utils_cleanUrl = (url)
|
|
106
|
-
function slash(str) {
|
|
107
|
-
return str.replace(/\\/g, '/');
|
|
108
|
-
}
|
|
109
|
-
function removeHash(str) {
|
|
110
|
-
return str.replace(/#.*$/, '');
|
|
111
|
-
}
|
|
112
|
-
function normalizePosixPath(id) {
|
|
113
|
-
const path = slash(id);
|
|
114
|
-
const isAbsolutePath = path.startsWith('/');
|
|
115
|
-
const parts = path.split('/');
|
|
116
|
-
const normalizedParts = [];
|
|
117
|
-
for (const part of parts)
|
|
118
|
-
else if ('..' === part) {
|
|
119
|
-
if (normalizedParts.length > 0 && '..' !== normalizedParts[normalizedParts.length - 1]) normalizedParts.pop();
|
|
120
|
-
else if (isAbsolutePath) normalizedParts.push('..');
|
|
121
|
-
} else normalizedParts.push(part);
|
|
122
|
-
let normalizedPath = normalizedParts.join('/');
|
|
123
|
-
if (isAbsolutePath) normalizedPath = `/${normalizedPath}`;
|
|
124
|
-
return normalizedPath;
|
|
125
|
-
}
|
|
126
|
-
const inBrowser = ()
|
|
127
|
-
function addLeadingSlash(url) {
|
|
128
|
-
return '/' === url.charAt(0) || isExternalUrl(url) ? url : `/${url}`;
|
|
129
|
-
}
|
|
130
|
-
function removeLeadingSlash(url) {
|
|
131
|
-
return '/' === url.charAt(0) ? url.slice(1) : url;
|
|
132
|
-
}
|
|
133
|
-
function addTrailingSlash(url) {
|
|
134
|
-
return '/' === url.charAt(url.length - 1) ? url : `${url}/`;
|
|
135
|
-
}
|
|
136
|
-
function removeTrailingSlash(url) {
|
|
137
|
-
return '/' === url.charAt(url.length - 1) ? url.slice(0, -1) : url;
|
|
138
|
-
}
|
|
139
|
-
function normalizeSlash(url) {
|
|
140
|
-
return removeTrailingSlash(addLeadingSlash(normalizePosixPath(url)));
|
|
141
|
-
}
|
|
142
|
-
function isExternalUrl(url = '') {
|
|
143
|
-
return url.startsWith('http://') || url.startsWith('https://') || url.startsWith('mailto:') || url.startsWith('tel:');
|
|
144
|
-
}
|
|
145
|
-
function isDataUrl(url = '') {
|
|
146
|
-
return /^\s*data:/i.test(url);
|
|
147
|
-
}
|
|
148
|
-
function replaceLang(rawUrl, lang, version, base = '', cleanUrls = false, isPageNotFound = false) {
|
|
149
|
-
let url = removeBase(rawUrl, base);
|
|
150
|
-
if (!url || isPageNotFound) url = cleanUrls ? '/index' : '/index.html';
|
|
151
|
-
if (url.endsWith('/')) url += cleanUrls ? '/index' : '/index.html';
|
|
152
|
-
let versionPart = '';
|
|
153
|
-
let langPart = '';
|
|
154
|
-
let purePathPart = '';
|
|
155
|
-
const parts = url.split('/').filter(Boolean);
|
|
156
|
-
if (version.current && version.current !== version.default) versionPart = parts.shift() || '';
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
if (
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
if (
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
return
|
|
215
|
-
}
|
|
216
|
-
function
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
}
|
|
224
|
-
var __webpack_export_target__ = exports;
|
|
225
|
-
for (var __webpack_i__ in __webpack_exports__) __webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
226
|
-
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
|
|
227
|
-
value: true
|
|
228
|
-
});
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = function(exports1, definition) {
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = function(obj, prop) {
|
|
13
|
+
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
14
|
+
};
|
|
15
|
+
})();
|
|
16
|
+
(()=>{
|
|
17
|
+
__webpack_require__.r = function(exports1) {
|
|
18
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
19
|
+
value: 'Module'
|
|
20
|
+
});
|
|
21
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
22
|
+
value: true
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
})();
|
|
26
|
+
var __webpack_exports__ = {};
|
|
27
|
+
__webpack_require__.r(__webpack_exports__);
|
|
28
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
29
|
+
SEARCH_INDEX_NAME: ()=>SEARCH_INDEX_NAME,
|
|
30
|
+
RSPRESS_TEMP_DIR: ()=>RSPRESS_TEMP_DIR,
|
|
31
|
+
QUERY_REGEXP: ()=>QUERY_REGEXP,
|
|
32
|
+
isDebugMode: ()=>isDebugMode,
|
|
33
|
+
addTrailingSlash: ()=>addTrailingSlash,
|
|
34
|
+
slash: ()=>slash,
|
|
35
|
+
removeLeadingSlash: ()=>removeLeadingSlash,
|
|
36
|
+
withoutBase: ()=>withoutBase,
|
|
37
|
+
replaceVersion: ()=>replaceVersion,
|
|
38
|
+
HASH_REGEXP: ()=>HASH_REGEXP,
|
|
39
|
+
isSCM: ()=>isSCM,
|
|
40
|
+
MDX_OR_MD_REGEXP: ()=>MDX_OR_MD_REGEXP,
|
|
41
|
+
normalizeHref: ()=>normalizeHref,
|
|
42
|
+
normalizeSlash: ()=>normalizeSlash,
|
|
43
|
+
normalizePosixPath: ()=>normalizePosixPath,
|
|
44
|
+
inBrowser: ()=>inBrowser,
|
|
45
|
+
isDataUrl: ()=>isDataUrl,
|
|
46
|
+
replaceLang: ()=>replaceLang,
|
|
47
|
+
removeHash: ()=>removeHash,
|
|
48
|
+
cleanUrl: ()=>runtime_utils_cleanUrl,
|
|
49
|
+
withBase: ()=>withBase,
|
|
50
|
+
isDevDebugMode: ()=>isDevDebugMode,
|
|
51
|
+
removeTrailingSlash: ()=>removeTrailingSlash,
|
|
52
|
+
APPEARANCE_KEY: ()=>APPEARANCE_KEY,
|
|
53
|
+
isExternalUrl: ()=>isExternalUrl,
|
|
54
|
+
removeBase: ()=>removeBase,
|
|
55
|
+
DEFAULT_HIGHLIGHT_LANGUAGES: ()=>DEFAULT_HIGHLIGHT_LANGUAGES,
|
|
56
|
+
parseUrl: ()=>parseUrl,
|
|
57
|
+
withoutLang: ()=>withoutLang,
|
|
58
|
+
isProduction: ()=>isProduction,
|
|
59
|
+
addLeadingSlash: ()=>addLeadingSlash
|
|
60
|
+
});
|
|
61
|
+
const QUERY_REGEXP = /\?.*$/s;
|
|
62
|
+
const HASH_REGEXP = /#.*$/s;
|
|
63
|
+
const MDX_OR_MD_REGEXP = /\.mdx?$/;
|
|
64
|
+
const APPEARANCE_KEY = 'rspress-theme-appearance';
|
|
65
|
+
const SEARCH_INDEX_NAME = 'search_index';
|
|
66
|
+
const RSPRESS_TEMP_DIR = '.rspress';
|
|
67
|
+
const DEFAULT_HIGHLIGHT_LANGUAGES = [
|
|
68
|
+
[
|
|
69
|
+
'js',
|
|
70
|
+
"javascript"
|
|
71
|
+
],
|
|
72
|
+
[
|
|
73
|
+
'ts',
|
|
74
|
+
"typescript"
|
|
75
|
+
],
|
|
76
|
+
[
|
|
77
|
+
'jsx',
|
|
78
|
+
'tsx'
|
|
79
|
+
],
|
|
80
|
+
[
|
|
81
|
+
'xml',
|
|
82
|
+
'xml-doc'
|
|
83
|
+
],
|
|
84
|
+
[
|
|
85
|
+
'md',
|
|
86
|
+
'markdown'
|
|
87
|
+
],
|
|
88
|
+
[
|
|
89
|
+
'mdx',
|
|
90
|
+
'tsx'
|
|
91
|
+
]
|
|
92
|
+
];
|
|
93
|
+
const isSCM = ()=>Boolean(process.env.BUILD_VERSION);
|
|
94
|
+
const isProduction = ()=>'production' === process.env.NODE_ENV;
|
|
95
|
+
const isDebugMode = ()=>{
|
|
96
|
+
if (!process.env.DEBUG) return false;
|
|
97
|
+
const values = process.env.DEBUG?.toLocaleLowerCase().split(',') ?? [];
|
|
98
|
+
return [
|
|
99
|
+
'rsbuild',
|
|
100
|
+
'builder',
|
|
101
|
+
'*'
|
|
102
|
+
].some((key)=>values.includes(key));
|
|
103
|
+
};
|
|
104
|
+
const isDevDebugMode = ()=>'rspress-dev' === process.env.DEBUG;
|
|
105
|
+
const runtime_utils_cleanUrl = (url)=>url.replace(HASH_REGEXP, '').replace(QUERY_REGEXP, '');
|
|
106
|
+
function slash(str) {
|
|
107
|
+
return str.replace(/\\/g, '/');
|
|
108
|
+
}
|
|
109
|
+
function removeHash(str) {
|
|
110
|
+
return str.replace(/#.*$/, '');
|
|
111
|
+
}
|
|
112
|
+
function normalizePosixPath(id) {
|
|
113
|
+
const path = slash(id);
|
|
114
|
+
const isAbsolutePath = path.startsWith('/');
|
|
115
|
+
const parts = path.split('/');
|
|
116
|
+
const normalizedParts = [];
|
|
117
|
+
for (const part of parts)if ('.' === part || '' === part) ;
|
|
118
|
+
else if ('..' === part) {
|
|
119
|
+
if (normalizedParts.length > 0 && '..' !== normalizedParts[normalizedParts.length - 1]) normalizedParts.pop();
|
|
120
|
+
else if (isAbsolutePath) normalizedParts.push('..');
|
|
121
|
+
} else normalizedParts.push(part);
|
|
122
|
+
let normalizedPath = normalizedParts.join('/');
|
|
123
|
+
if (isAbsolutePath) normalizedPath = `/${normalizedPath}`;
|
|
124
|
+
return normalizedPath;
|
|
125
|
+
}
|
|
126
|
+
const inBrowser = ()=>!process.env.__SSR__;
|
|
127
|
+
function addLeadingSlash(url) {
|
|
128
|
+
return '/' === url.charAt(0) || isExternalUrl(url) ? url : `/${url}`;
|
|
129
|
+
}
|
|
130
|
+
function removeLeadingSlash(url) {
|
|
131
|
+
return '/' === url.charAt(0) ? url.slice(1) : url;
|
|
132
|
+
}
|
|
133
|
+
function addTrailingSlash(url) {
|
|
134
|
+
return '/' === url.charAt(url.length - 1) ? url : `${url}/`;
|
|
135
|
+
}
|
|
136
|
+
function removeTrailingSlash(url) {
|
|
137
|
+
return '/' === url.charAt(url.length - 1) ? url.slice(0, -1) : url;
|
|
138
|
+
}
|
|
139
|
+
function normalizeSlash(url) {
|
|
140
|
+
return removeTrailingSlash(addLeadingSlash(normalizePosixPath(url)));
|
|
141
|
+
}
|
|
142
|
+
function isExternalUrl(url = '') {
|
|
143
|
+
return url.startsWith('http://') || url.startsWith('https://') || url.startsWith('mailto:') || url.startsWith('tel:');
|
|
144
|
+
}
|
|
145
|
+
function isDataUrl(url = '') {
|
|
146
|
+
return /^\s*data:/i.test(url);
|
|
147
|
+
}
|
|
148
|
+
function replaceLang(rawUrl, lang, version, base = '', cleanUrls = false, isPageNotFound = false) {
|
|
149
|
+
let url = removeBase(rawUrl, base);
|
|
150
|
+
if (!url || isPageNotFound) url = cleanUrls ? '/index' : '/index.html';
|
|
151
|
+
if (url.endsWith('/')) url += cleanUrls ? '/index' : '/index.html';
|
|
152
|
+
let versionPart = '';
|
|
153
|
+
let langPart = '';
|
|
154
|
+
let purePathPart = '';
|
|
155
|
+
const parts = url.split('/').filter(Boolean);
|
|
156
|
+
if (version.current && version.current !== version.default) versionPart = parts.shift() || '';
|
|
157
|
+
if (lang.target !== lang.default) {
|
|
158
|
+
langPart = lang.target;
|
|
159
|
+
if (lang.current !== lang.default) parts.shift();
|
|
160
|
+
} else parts.shift();
|
|
161
|
+
purePathPart = parts.join('/') || '';
|
|
162
|
+
if ((versionPart || langPart) && !purePathPart) purePathPart = cleanUrls ? 'index' : 'index.html';
|
|
163
|
+
return withBase(addLeadingSlash([
|
|
164
|
+
versionPart,
|
|
165
|
+
langPart,
|
|
166
|
+
purePathPart
|
|
167
|
+
].filter(Boolean).join('/')), base);
|
|
168
|
+
}
|
|
169
|
+
function replaceVersion(rawUrl, version, base = '', cleanUrls = false, isPageNotFound = false) {
|
|
170
|
+
let url = removeBase(rawUrl, base);
|
|
171
|
+
if (!url || isPageNotFound) url = cleanUrls ? '/index' : '/index.html';
|
|
172
|
+
let versionPart = '';
|
|
173
|
+
const parts = url.split('/').filter(Boolean);
|
|
174
|
+
if (version.target !== version.default) {
|
|
175
|
+
versionPart = version.target;
|
|
176
|
+
if (version.current !== version.default) parts.shift();
|
|
177
|
+
} else parts.shift();
|
|
178
|
+
let restPart = parts.join('/') || '';
|
|
179
|
+
if (versionPart && !restPart) restPart = cleanUrls ? 'index' : 'index.html';
|
|
180
|
+
return withBase(addLeadingSlash([
|
|
181
|
+
versionPart,
|
|
182
|
+
restPart
|
|
183
|
+
].filter(Boolean).join('/')), base);
|
|
184
|
+
}
|
|
185
|
+
const parseUrl = (url)=>{
|
|
186
|
+
const [withoutHash, hash = ''] = url.split('#');
|
|
187
|
+
return {
|
|
188
|
+
url: withoutHash,
|
|
189
|
+
hash
|
|
190
|
+
};
|
|
191
|
+
};
|
|
192
|
+
function normalizeHref(url, cleanUrls = false) {
|
|
193
|
+
if (!url) return '/';
|
|
194
|
+
if (isExternalUrl(url)) return url;
|
|
195
|
+
let { url: cleanUrl, hash } = parseUrl(decodeURIComponent(url));
|
|
196
|
+
if (!cleanUrls && !cleanUrl.endsWith('.html')) {
|
|
197
|
+
if (cleanUrl.endsWith('/')) cleanUrl += 'index.html';
|
|
198
|
+
else cleanUrl += '.html';
|
|
199
|
+
}
|
|
200
|
+
if (cleanUrls && cleanUrl.endsWith('/')) cleanUrl += 'index';
|
|
201
|
+
if (cleanUrls && cleanUrl.endsWith('.html')) cleanUrl = cleanUrl.replace(/\.html$/, '');
|
|
202
|
+
return addLeadingSlash(hash ? `${cleanUrl}#${hash}` : cleanUrl);
|
|
203
|
+
}
|
|
204
|
+
function withoutLang(path, langs) {
|
|
205
|
+
const langRegexp = new RegExp(`^\\/(${langs.join('|')})`);
|
|
206
|
+
return addLeadingSlash(path.replace(langRegexp, ''));
|
|
207
|
+
}
|
|
208
|
+
function withoutBase(path, base) {
|
|
209
|
+
return addLeadingSlash(path).replace(normalizeSlash(base), '');
|
|
210
|
+
}
|
|
211
|
+
function withBase(url, base) {
|
|
212
|
+
const normalizedUrl = addLeadingSlash(url);
|
|
213
|
+
const normalizedBase = normalizeSlash(base);
|
|
214
|
+
return normalizedUrl.startsWith(normalizedBase) ? normalizedUrl : `${normalizedBase}${normalizedUrl}`;
|
|
215
|
+
}
|
|
216
|
+
function removeBase(url, base) {
|
|
217
|
+
return addLeadingSlash(url).replace(new RegExp(`^${normalizeSlash(base)}`), '');
|
|
218
|
+
}
|
|
219
|
+
var __webpack_export_target__ = exports;
|
|
220
|
+
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
221
|
+
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
|
|
222
|
+
value: true
|
|
223
|
+
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,159 +1,159 @@
|
|
|
1
|
-
const QUERY_REGEXP = /\?.*$/s;
|
|
2
|
-
const HASH_REGEXP = /#.*$/s;
|
|
3
|
-
const MDX_OR_MD_REGEXP = /\.mdx?$/;
|
|
4
|
-
const APPEARANCE_KEY = 'rspress-theme-appearance';
|
|
5
|
-
const SEARCH_INDEX_NAME = 'search_index';
|
|
6
|
-
const RSPRESS_TEMP_DIR = '.rspress';
|
|
7
|
-
const DEFAULT_HIGHLIGHT_LANGUAGES = [
|
|
8
|
-
[
|
|
9
|
-
'js',
|
|
10
|
-
"javascript"
|
|
11
|
-
],
|
|
12
|
-
[
|
|
13
|
-
'ts',
|
|
14
|
-
"typescript"
|
|
15
|
-
],
|
|
16
|
-
[
|
|
17
|
-
'jsx',
|
|
18
|
-
'tsx'
|
|
19
|
-
],
|
|
20
|
-
[
|
|
21
|
-
'xml',
|
|
22
|
-
'xml-doc'
|
|
23
|
-
],
|
|
24
|
-
[
|
|
25
|
-
'md',
|
|
26
|
-
'markdown'
|
|
27
|
-
],
|
|
28
|
-
[
|
|
29
|
-
'mdx',
|
|
30
|
-
'tsx'
|
|
31
|
-
]
|
|
32
|
-
];
|
|
33
|
-
const isSCM = ()=>Boolean(process.env.BUILD_VERSION);
|
|
34
|
-
const isProduction = ()=>'production' === process.env.NODE_ENV;
|
|
35
|
-
const isDebugMode = ()=>{
|
|
36
|
-
if (!process.env.DEBUG) return false;
|
|
37
|
-
const values = process.env.DEBUG?.toLocaleLowerCase().split(',') ?? [];
|
|
38
|
-
return [
|
|
39
|
-
'rsbuild',
|
|
40
|
-
'builder',
|
|
41
|
-
'*'
|
|
42
|
-
].some((key)=>values.includes(key));
|
|
43
|
-
};
|
|
44
|
-
const isDevDebugMode = ()=>'rspress-dev' === process.env.DEBUG;
|
|
45
|
-
const runtime_utils_cleanUrl = (url)=>url.replace(HASH_REGEXP, '').replace(QUERY_REGEXP, '');
|
|
46
|
-
function slash(str) {
|
|
47
|
-
return str.replace(/\\/g, '/');
|
|
48
|
-
}
|
|
49
|
-
function removeHash(str) {
|
|
50
|
-
return str.replace(/#.*$/, '');
|
|
51
|
-
}
|
|
52
|
-
function normalizePosixPath(id) {
|
|
53
|
-
const path = slash(id);
|
|
54
|
-
const isAbsolutePath = path.startsWith('/');
|
|
55
|
-
const parts = path.split('/');
|
|
56
|
-
const normalizedParts = [];
|
|
57
|
-
for (const part of parts)if ('.' === part || '' === part) ;
|
|
58
|
-
else if ('..' === part) {
|
|
59
|
-
if (normalizedParts.length > 0 && '..' !== normalizedParts[normalizedParts.length - 1]) normalizedParts.pop();
|
|
60
|
-
else if (isAbsolutePath) normalizedParts.push('..');
|
|
61
|
-
} else normalizedParts.push(part);
|
|
62
|
-
let normalizedPath = normalizedParts.join('/');
|
|
63
|
-
if (isAbsolutePath) normalizedPath = `/${normalizedPath}`;
|
|
64
|
-
return normalizedPath;
|
|
65
|
-
}
|
|
66
|
-
const inBrowser = ()=>!process.env.__SSR__;
|
|
67
|
-
function addLeadingSlash(url) {
|
|
68
|
-
return '/' === url.charAt(0) || isExternalUrl(url) ? url : `/${url}`;
|
|
69
|
-
}
|
|
70
|
-
function removeLeadingSlash(url) {
|
|
71
|
-
return '/' === url.charAt(0) ? url.slice(1) : url;
|
|
72
|
-
}
|
|
73
|
-
function addTrailingSlash(url) {
|
|
74
|
-
return '/' === url.charAt(url.length - 1) ? url : `${url}/`;
|
|
75
|
-
}
|
|
76
|
-
function removeTrailingSlash(url) {
|
|
77
|
-
return '/' === url.charAt(url.length - 1) ? url.slice(0, -1) : url;
|
|
78
|
-
}
|
|
79
|
-
function normalizeSlash(url) {
|
|
80
|
-
return removeTrailingSlash(addLeadingSlash(normalizePosixPath(url)));
|
|
81
|
-
}
|
|
82
|
-
function isExternalUrl(url = '') {
|
|
83
|
-
return url.startsWith('http://') || url.startsWith('https://') || url.startsWith('mailto:') || url.startsWith('tel:');
|
|
84
|
-
}
|
|
85
|
-
function isDataUrl(url = '') {
|
|
86
|
-
return /^\s*data:/i.test(url);
|
|
87
|
-
}
|
|
88
|
-
function replaceLang(rawUrl, lang, version, base = '', cleanUrls = false, isPageNotFound = false) {
|
|
89
|
-
let url = removeBase(rawUrl, base);
|
|
90
|
-
if (!url || isPageNotFound) url = cleanUrls ? '/index' : '/index.html';
|
|
91
|
-
if (url.endsWith('/')) url += cleanUrls ? '/index' : '/index.html';
|
|
92
|
-
let versionPart = '';
|
|
93
|
-
let langPart = '';
|
|
94
|
-
let purePathPart = '';
|
|
95
|
-
const parts = url.split('/').filter(Boolean);
|
|
96
|
-
if (version.current && version.current !== version.default) versionPart = parts.shift() || '';
|
|
97
|
-
if (lang.target !== lang.default) {
|
|
98
|
-
langPart = lang.target;
|
|
99
|
-
if (lang.current !== lang.default) parts.shift();
|
|
100
|
-
} else parts.shift();
|
|
101
|
-
purePathPart = parts.join('/') || '';
|
|
102
|
-
if ((versionPart || langPart) && !purePathPart) purePathPart = cleanUrls ? 'index' : 'index.html';
|
|
103
|
-
return withBase(addLeadingSlash([
|
|
104
|
-
versionPart,
|
|
105
|
-
langPart,
|
|
106
|
-
purePathPart
|
|
107
|
-
].filter(Boolean).join('/')), base);
|
|
108
|
-
}
|
|
109
|
-
function replaceVersion(rawUrl, version, base = '', cleanUrls = false, isPageNotFound = false) {
|
|
110
|
-
let url = removeBase(rawUrl, base);
|
|
111
|
-
if (!url || isPageNotFound) url = cleanUrls ? '/index' : '/index.html';
|
|
112
|
-
let versionPart = '';
|
|
113
|
-
const parts = url.split('/').filter(Boolean);
|
|
114
|
-
if (version.target !== version.default) {
|
|
115
|
-
versionPart = version.target;
|
|
116
|
-
if (version.current !== version.default) parts.shift();
|
|
117
|
-
} else parts.shift();
|
|
118
|
-
let restPart = parts.join('/') || '';
|
|
119
|
-
if (versionPart && !restPart) restPart = cleanUrls ? 'index' : 'index.html';
|
|
120
|
-
return withBase(addLeadingSlash([
|
|
121
|
-
versionPart,
|
|
122
|
-
restPart
|
|
123
|
-
].filter(Boolean).join('/')), base);
|
|
124
|
-
}
|
|
125
|
-
const parseUrl = (url)=>{
|
|
126
|
-
const [withoutHash, hash = ''] = url.split('#');
|
|
127
|
-
return {
|
|
128
|
-
url: withoutHash,
|
|
129
|
-
hash
|
|
130
|
-
};
|
|
131
|
-
};
|
|
132
|
-
function normalizeHref(url, cleanUrls = false) {
|
|
133
|
-
if (!url) return '/';
|
|
134
|
-
if (isExternalUrl(url)) return url;
|
|
135
|
-
let { url: cleanUrl, hash } = parseUrl(decodeURIComponent(url));
|
|
136
|
-
if (!cleanUrls && !cleanUrl.endsWith('.html')) {
|
|
137
|
-
if (cleanUrl.endsWith('/')) cleanUrl += 'index.html';
|
|
138
|
-
else cleanUrl += '.html';
|
|
139
|
-
}
|
|
140
|
-
if (cleanUrls && cleanUrl.endsWith('/')) cleanUrl += 'index';
|
|
141
|
-
if (cleanUrls && cleanUrl.endsWith('.html')) cleanUrl = cleanUrl.replace(/\.html$/, '');
|
|
142
|
-
return addLeadingSlash(hash ? `${cleanUrl}#${hash}` : cleanUrl);
|
|
143
|
-
}
|
|
144
|
-
function withoutLang(path, langs) {
|
|
145
|
-
const langRegexp = new RegExp(`^\\/(${langs.join('|')})`);
|
|
146
|
-
return addLeadingSlash(path.replace(langRegexp, ''));
|
|
147
|
-
}
|
|
148
|
-
function withoutBase(path, base) {
|
|
149
|
-
return addLeadingSlash(path).replace(normalizeSlash(base), '');
|
|
150
|
-
}
|
|
151
|
-
function withBase(url, base) {
|
|
152
|
-
const normalizedUrl = addLeadingSlash(url);
|
|
153
|
-
const normalizedBase = normalizeSlash(base);
|
|
154
|
-
return normalizedUrl.startsWith(normalizedBase) ? normalizedUrl : `${normalizedBase}${normalizedUrl}`;
|
|
155
|
-
}
|
|
156
|
-
function removeBase(url, base) {
|
|
157
|
-
return addLeadingSlash(url).replace(new RegExp(`^${normalizeSlash(base)}`), '');
|
|
158
|
-
}
|
|
159
|
-
export { APPEARANCE_KEY, DEFAULT_HIGHLIGHT_LANGUAGES, HASH_REGEXP, MDX_OR_MD_REGEXP, QUERY_REGEXP, RSPRESS_TEMP_DIR, SEARCH_INDEX_NAME, addLeadingSlash, addTrailingSlash, runtime_utils_cleanUrl as cleanUrl, inBrowser, isDataUrl, isDebugMode, isDevDebugMode, isExternalUrl, isProduction, isSCM, normalizeHref, normalizePosixPath, normalizeSlash, parseUrl, removeBase, removeHash, removeLeadingSlash, removeTrailingSlash, replaceLang, replaceVersion, slash, withBase, withoutBase, withoutLang };
|
|
1
|
+
const QUERY_REGEXP = /\?.*$/s;
|
|
2
|
+
const HASH_REGEXP = /#.*$/s;
|
|
3
|
+
const MDX_OR_MD_REGEXP = /\.mdx?$/;
|
|
4
|
+
const APPEARANCE_KEY = 'rspress-theme-appearance';
|
|
5
|
+
const SEARCH_INDEX_NAME = 'search_index';
|
|
6
|
+
const RSPRESS_TEMP_DIR = '.rspress';
|
|
7
|
+
const DEFAULT_HIGHLIGHT_LANGUAGES = [
|
|
8
|
+
[
|
|
9
|
+
'js',
|
|
10
|
+
"javascript"
|
|
11
|
+
],
|
|
12
|
+
[
|
|
13
|
+
'ts',
|
|
14
|
+
"typescript"
|
|
15
|
+
],
|
|
16
|
+
[
|
|
17
|
+
'jsx',
|
|
18
|
+
'tsx'
|
|
19
|
+
],
|
|
20
|
+
[
|
|
21
|
+
'xml',
|
|
22
|
+
'xml-doc'
|
|
23
|
+
],
|
|
24
|
+
[
|
|
25
|
+
'md',
|
|
26
|
+
'markdown'
|
|
27
|
+
],
|
|
28
|
+
[
|
|
29
|
+
'mdx',
|
|
30
|
+
'tsx'
|
|
31
|
+
]
|
|
32
|
+
];
|
|
33
|
+
const isSCM = ()=>Boolean(process.env.BUILD_VERSION);
|
|
34
|
+
const isProduction = ()=>'production' === process.env.NODE_ENV;
|
|
35
|
+
const isDebugMode = ()=>{
|
|
36
|
+
if (!process.env.DEBUG) return false;
|
|
37
|
+
const values = process.env.DEBUG?.toLocaleLowerCase().split(',') ?? [];
|
|
38
|
+
return [
|
|
39
|
+
'rsbuild',
|
|
40
|
+
'builder',
|
|
41
|
+
'*'
|
|
42
|
+
].some((key)=>values.includes(key));
|
|
43
|
+
};
|
|
44
|
+
const isDevDebugMode = ()=>'rspress-dev' === process.env.DEBUG;
|
|
45
|
+
const runtime_utils_cleanUrl = (url)=>url.replace(HASH_REGEXP, '').replace(QUERY_REGEXP, '');
|
|
46
|
+
function slash(str) {
|
|
47
|
+
return str.replace(/\\/g, '/');
|
|
48
|
+
}
|
|
49
|
+
function removeHash(str) {
|
|
50
|
+
return str.replace(/#.*$/, '');
|
|
51
|
+
}
|
|
52
|
+
function normalizePosixPath(id) {
|
|
53
|
+
const path = slash(id);
|
|
54
|
+
const isAbsolutePath = path.startsWith('/');
|
|
55
|
+
const parts = path.split('/');
|
|
56
|
+
const normalizedParts = [];
|
|
57
|
+
for (const part of parts)if ('.' === part || '' === part) ;
|
|
58
|
+
else if ('..' === part) {
|
|
59
|
+
if (normalizedParts.length > 0 && '..' !== normalizedParts[normalizedParts.length - 1]) normalizedParts.pop();
|
|
60
|
+
else if (isAbsolutePath) normalizedParts.push('..');
|
|
61
|
+
} else normalizedParts.push(part);
|
|
62
|
+
let normalizedPath = normalizedParts.join('/');
|
|
63
|
+
if (isAbsolutePath) normalizedPath = `/${normalizedPath}`;
|
|
64
|
+
return normalizedPath;
|
|
65
|
+
}
|
|
66
|
+
const inBrowser = ()=>!process.env.__SSR__;
|
|
67
|
+
function addLeadingSlash(url) {
|
|
68
|
+
return '/' === url.charAt(0) || isExternalUrl(url) ? url : `/${url}`;
|
|
69
|
+
}
|
|
70
|
+
function removeLeadingSlash(url) {
|
|
71
|
+
return '/' === url.charAt(0) ? url.slice(1) : url;
|
|
72
|
+
}
|
|
73
|
+
function addTrailingSlash(url) {
|
|
74
|
+
return '/' === url.charAt(url.length - 1) ? url : `${url}/`;
|
|
75
|
+
}
|
|
76
|
+
function removeTrailingSlash(url) {
|
|
77
|
+
return '/' === url.charAt(url.length - 1) ? url.slice(0, -1) : url;
|
|
78
|
+
}
|
|
79
|
+
function normalizeSlash(url) {
|
|
80
|
+
return removeTrailingSlash(addLeadingSlash(normalizePosixPath(url)));
|
|
81
|
+
}
|
|
82
|
+
function isExternalUrl(url = '') {
|
|
83
|
+
return url.startsWith('http://') || url.startsWith('https://') || url.startsWith('mailto:') || url.startsWith('tel:');
|
|
84
|
+
}
|
|
85
|
+
function isDataUrl(url = '') {
|
|
86
|
+
return /^\s*data:/i.test(url);
|
|
87
|
+
}
|
|
88
|
+
function replaceLang(rawUrl, lang, version, base = '', cleanUrls = false, isPageNotFound = false) {
|
|
89
|
+
let url = removeBase(rawUrl, base);
|
|
90
|
+
if (!url || isPageNotFound) url = cleanUrls ? '/index' : '/index.html';
|
|
91
|
+
if (url.endsWith('/')) url += cleanUrls ? '/index' : '/index.html';
|
|
92
|
+
let versionPart = '';
|
|
93
|
+
let langPart = '';
|
|
94
|
+
let purePathPart = '';
|
|
95
|
+
const parts = url.split('/').filter(Boolean);
|
|
96
|
+
if (version.current && version.current !== version.default) versionPart = parts.shift() || '';
|
|
97
|
+
if (lang.target !== lang.default) {
|
|
98
|
+
langPart = lang.target;
|
|
99
|
+
if (lang.current !== lang.default) parts.shift();
|
|
100
|
+
} else parts.shift();
|
|
101
|
+
purePathPart = parts.join('/') || '';
|
|
102
|
+
if ((versionPart || langPart) && !purePathPart) purePathPart = cleanUrls ? 'index' : 'index.html';
|
|
103
|
+
return withBase(addLeadingSlash([
|
|
104
|
+
versionPart,
|
|
105
|
+
langPart,
|
|
106
|
+
purePathPart
|
|
107
|
+
].filter(Boolean).join('/')), base);
|
|
108
|
+
}
|
|
109
|
+
function replaceVersion(rawUrl, version, base = '', cleanUrls = false, isPageNotFound = false) {
|
|
110
|
+
let url = removeBase(rawUrl, base);
|
|
111
|
+
if (!url || isPageNotFound) url = cleanUrls ? '/index' : '/index.html';
|
|
112
|
+
let versionPart = '';
|
|
113
|
+
const parts = url.split('/').filter(Boolean);
|
|
114
|
+
if (version.target !== version.default) {
|
|
115
|
+
versionPart = version.target;
|
|
116
|
+
if (version.current !== version.default) parts.shift();
|
|
117
|
+
} else parts.shift();
|
|
118
|
+
let restPart = parts.join('/') || '';
|
|
119
|
+
if (versionPart && !restPart) restPart = cleanUrls ? 'index' : 'index.html';
|
|
120
|
+
return withBase(addLeadingSlash([
|
|
121
|
+
versionPart,
|
|
122
|
+
restPart
|
|
123
|
+
].filter(Boolean).join('/')), base);
|
|
124
|
+
}
|
|
125
|
+
const parseUrl = (url)=>{
|
|
126
|
+
const [withoutHash, hash = ''] = url.split('#');
|
|
127
|
+
return {
|
|
128
|
+
url: withoutHash,
|
|
129
|
+
hash
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
function normalizeHref(url, cleanUrls = false) {
|
|
133
|
+
if (!url) return '/';
|
|
134
|
+
if (isExternalUrl(url)) return url;
|
|
135
|
+
let { url: cleanUrl, hash } = parseUrl(decodeURIComponent(url));
|
|
136
|
+
if (!cleanUrls && !cleanUrl.endsWith('.html')) {
|
|
137
|
+
if (cleanUrl.endsWith('/')) cleanUrl += 'index.html';
|
|
138
|
+
else cleanUrl += '.html';
|
|
139
|
+
}
|
|
140
|
+
if (cleanUrls && cleanUrl.endsWith('/')) cleanUrl += 'index';
|
|
141
|
+
if (cleanUrls && cleanUrl.endsWith('.html')) cleanUrl = cleanUrl.replace(/\.html$/, '');
|
|
142
|
+
return addLeadingSlash(hash ? `${cleanUrl}#${hash}` : cleanUrl);
|
|
143
|
+
}
|
|
144
|
+
function withoutLang(path, langs) {
|
|
145
|
+
const langRegexp = new RegExp(`^\\/(${langs.join('|')})`);
|
|
146
|
+
return addLeadingSlash(path.replace(langRegexp, ''));
|
|
147
|
+
}
|
|
148
|
+
function withoutBase(path, base) {
|
|
149
|
+
return addLeadingSlash(path).replace(normalizeSlash(base), '');
|
|
150
|
+
}
|
|
151
|
+
function withBase(url, base) {
|
|
152
|
+
const normalizedUrl = addLeadingSlash(url);
|
|
153
|
+
const normalizedBase = normalizeSlash(base);
|
|
154
|
+
return normalizedUrl.startsWith(normalizedBase) ? normalizedUrl : `${normalizedBase}${normalizedUrl}`;
|
|
155
|
+
}
|
|
156
|
+
function removeBase(url, base) {
|
|
157
|
+
return addLeadingSlash(url).replace(new RegExp(`^${normalizeSlash(base)}`), '');
|
|
158
|
+
}
|
|
159
|
+
export { APPEARANCE_KEY, DEFAULT_HIGHLIGHT_LANGUAGES, HASH_REGEXP, MDX_OR_MD_REGEXP, QUERY_REGEXP, RSPRESS_TEMP_DIR, SEARCH_INDEX_NAME, addLeadingSlash, addTrailingSlash, runtime_utils_cleanUrl as cleanUrl, inBrowser, isDataUrl, isDebugMode, isDevDebugMode, isExternalUrl, isProduction, isSCM, normalizeHref, normalizePosixPath, normalizeSlash, parseUrl, removeBase, removeHash, removeLeadingSlash, removeTrailingSlash, replaceLang, replaceVersion, slash, withBase, withoutBase, withoutLang };
|