@rspress/shared 2.0.0-beta.0 → 2.0.0-beta.2

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/constants.js CHANGED
@@ -1,33 +1,3 @@
1
- "use strict";
2
- var __webpack_require__ = {};
3
- (()=>{
4
- __webpack_require__.d = (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 = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
- })();
14
- (()=>{
15
- __webpack_require__.r = (exports1)=>{
16
- if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
- value: 'Module'
18
- });
19
- Object.defineProperty(exports1, '__esModule', {
20
- value: true
21
- });
22
- };
23
- })();
24
- var __webpack_exports__ = {};
25
- __webpack_require__.r(__webpack_exports__);
26
- __webpack_require__.d(__webpack_exports__, {
27
- DEFAULT_CONFIG_EXTENSIONS: ()=>DEFAULT_CONFIG_EXTENSIONS,
28
- DEFAULT_CONFIG_NAME: ()=>DEFAULT_CONFIG_NAME,
29
- DEFAULT_PAGE_EXTENSIONS: ()=>DEFAULT_PAGE_EXTENSIONS
30
- });
31
1
  const DEFAULT_CONFIG_NAME = 'rspress.config';
32
2
  const DEFAULT_CONFIG_EXTENSIONS = [
33
3
  '.js',
@@ -45,14 +15,4 @@ const DEFAULT_PAGE_EXTENSIONS = [
45
15
  '.md',
46
16
  '.mdx'
47
17
  ];
48
- exports.DEFAULT_CONFIG_EXTENSIONS = __webpack_exports__.DEFAULT_CONFIG_EXTENSIONS;
49
- exports.DEFAULT_CONFIG_NAME = __webpack_exports__.DEFAULT_CONFIG_NAME;
50
- exports.DEFAULT_PAGE_EXTENSIONS = __webpack_exports__.DEFAULT_PAGE_EXTENSIONS;
51
- for(var __webpack_i__ in __webpack_exports__)if (-1 === [
52
- "DEFAULT_CONFIG_EXTENSIONS",
53
- "DEFAULT_CONFIG_NAME",
54
- "DEFAULT_PAGE_EXTENSIONS"
55
- ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
56
- Object.defineProperty(exports, '__esModule', {
57
- value: true
58
- });
18
+ export { DEFAULT_CONFIG_EXTENSIONS, DEFAULT_CONFIG_NAME, DEFAULT_PAGE_EXTENSIONS };
package/dist/index.d.ts CHANGED
@@ -214,6 +214,14 @@ export declare interface FrontMatterMeta {
214
214
  [key: string]: unknown;
215
215
  }
216
216
 
217
+ /**
218
+ * get the sidebar group for the current page
219
+ * @param sidebar const { sidebar } = useLocaleSiteData();
220
+ * @param currentPathname
221
+ * @returns
222
+ */
223
+ export declare const getSidebarDataGroup: (sidebar: NormalizedSidebar, currentPathname: string, base: string) => NormalizedSidebar[string];
224
+
217
225
  export declare const HASH_REGEXP: RegExp;
218
226
 
219
227
  export declare interface Header {
@@ -351,24 +359,18 @@ export declare interface MarkdownOptions {
351
359
  * Register prism languages
352
360
  */
353
361
  highlightLanguages?: (string | [string, string])[];
354
- /**
355
- * Whether to enable mdx-rs, default is true
356
- */
357
- mdxRs?: boolean | MdxRsOptions;
358
- /**
359
- * @deprecated, use `mdxRs` instead
360
- */
361
- experimentalMdxRs?: boolean;
362
362
  }
363
363
 
364
- export declare const MDX_OR_MD_REGEXP: RegExp;
364
+ export declare const matchNavbar: (item: NavItemWithLink, currentPathname: string, base: string) => boolean;
365
365
 
366
- export declare interface MdxRsOptions {
367
- /**
368
- * Determine whether the file use mdxRs compiler
369
- */
370
- include?: (filepath: string) => boolean;
371
- }
366
+ /**
367
+ * match the sidebar key in user config
368
+ * @param pattern /zh/guide
369
+ * @param currentPathname /base/zh/guide/getting-started
370
+ */
371
+ export declare const matchSidebar: (pattern: string, currentPathname: string, base: string) => boolean;
372
+
373
+ export declare const MDX_OR_MD_REGEXP: RegExp;
372
374
 
373
375
  export declare type Nav = NavItem[] | {
374
376
  [key: string]: NavItem[];
@@ -450,6 +452,7 @@ export declare interface PageIndexInfo {
450
452
  routePath: string;
451
453
  toc: Header[];
452
454
  content: string;
455
+ _flattenContent?: string;
453
456
  _html: string;
454
457
  frontmatter: FrontMatterMeta;
455
458
  lang: string;
@@ -625,6 +628,10 @@ declare interface RspressPlugin {
625
628
  * Callback after route generated
626
629
  */
627
630
  routeGenerated?: (routes: RouteMeta[], isProd: boolean) => Promise<void> | void;
631
+ /**
632
+ * Callback after routeService generated
633
+ */
634
+ routeServiceGenerated?: (routeService: any, isProd: boolean) => Promise<void> | void;
628
635
  /**
629
636
  * Add addition ssg routes, for dynamic routes.
630
637
  */
package/dist/index.js CHANGED
@@ -1,61 +1,3 @@
1
- "use strict";
2
- var __webpack_require__ = {};
3
- (()=>{
4
- __webpack_require__.d = (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 = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
- })();
14
- (()=>{
15
- __webpack_require__.r = (exports1)=>{
16
- if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
- value: 'Module'
18
- });
19
- Object.defineProperty(exports1, '__esModule', {
20
- value: true
21
- });
22
- };
23
- })();
24
- var __webpack_exports__ = {};
25
- __webpack_require__.r(__webpack_exports__);
26
- __webpack_require__.d(__webpack_exports__, {
27
- RSPRESS_TEMP_DIR: ()=>RSPRESS_TEMP_DIR,
28
- parseUrl: ()=>parseUrl,
29
- withBase: ()=>withBase,
30
- slash: ()=>slash,
31
- removeBase: ()=>removeBase,
32
- replaceLang: ()=>replaceLang,
33
- removeLeadingSlash: ()=>removeLeadingSlash,
34
- addLeadingSlash: ()=>addLeadingSlash,
35
- replaceVersion: ()=>replaceVersion,
36
- isDevDebugMode: ()=>isDevDebugMode,
37
- HASH_REGEXP: ()=>HASH_REGEXP,
38
- withoutLang: ()=>withoutLang,
39
- MDX_OR_MD_REGEXP: ()=>MDX_OR_MD_REGEXP,
40
- SEARCH_INDEX_NAME: ()=>SEARCH_INDEX_NAME,
41
- withoutBase: ()=>withoutBase,
42
- isDebugMode: ()=>isDebugMode,
43
- isExternalUrl: ()=>isExternalUrl,
44
- isSCM: ()=>isSCM,
45
- addTrailingSlash: ()=>addTrailingSlash,
46
- normalizeSlash: ()=>normalizeSlash,
47
- APPEARANCE_KEY: ()=>APPEARANCE_KEY,
48
- normalizeHref: ()=>normalizeHref,
49
- normalizePosixPath: ()=>normalizePosixPath,
50
- removeHash: ()=>removeHash,
51
- removeTrailingSlash: ()=>removeTrailingSlash,
52
- QUERY_REGEXP: ()=>QUERY_REGEXP,
53
- isProduction: ()=>isProduction,
54
- DEFAULT_HIGHLIGHT_LANGUAGES: ()=>DEFAULT_HIGHLIGHT_LANGUAGES,
55
- inBrowser: ()=>inBrowser,
56
- isDataUrl: ()=>isDataUrl,
57
- cleanUrl: ()=>runtime_utils_cleanUrl
58
- });
59
1
  const QUERY_REGEXP = /\?.*$/s;
60
2
  const HASH_REGEXP = /#.*$/s;
61
3
  const MDX_OR_MD_REGEXP = /\.mdx?$/;
@@ -100,7 +42,7 @@ const isDebugMode = ()=>{
100
42
  ].some((key)=>values.includes(key));
101
43
  };
102
44
  const isDevDebugMode = ()=>'rspress-dev' === process.env.DEBUG;
103
- const runtime_utils_cleanUrl = (url)=>url.replace(HASH_REGEXP, '').replace(QUERY_REGEXP, '');
45
+ const utils_cleanUrl = (url)=>url.replace(HASH_REGEXP, '').replace(QUERY_REGEXP, '');
104
46
  function slash(str) {
105
47
  return str.replace(/\\/g, '/');
106
48
  }
@@ -214,70 +156,21 @@ function withBase(url, base) {
214
156
  function removeBase(url, base) {
215
157
  return addLeadingSlash(url).replace(new RegExp(`^${normalizeSlash(base)}`), '');
216
158
  }
217
- exports.APPEARANCE_KEY = __webpack_exports__.APPEARANCE_KEY;
218
- exports.DEFAULT_HIGHLIGHT_LANGUAGES = __webpack_exports__.DEFAULT_HIGHLIGHT_LANGUAGES;
219
- exports.HASH_REGEXP = __webpack_exports__.HASH_REGEXP;
220
- exports.MDX_OR_MD_REGEXP = __webpack_exports__.MDX_OR_MD_REGEXP;
221
- exports.QUERY_REGEXP = __webpack_exports__.QUERY_REGEXP;
222
- exports.RSPRESS_TEMP_DIR = __webpack_exports__.RSPRESS_TEMP_DIR;
223
- exports.SEARCH_INDEX_NAME = __webpack_exports__.SEARCH_INDEX_NAME;
224
- exports.addLeadingSlash = __webpack_exports__.addLeadingSlash;
225
- exports.addTrailingSlash = __webpack_exports__.addTrailingSlash;
226
- exports.cleanUrl = __webpack_exports__.cleanUrl;
227
- exports.inBrowser = __webpack_exports__.inBrowser;
228
- exports.isDataUrl = __webpack_exports__.isDataUrl;
229
- exports.isDebugMode = __webpack_exports__.isDebugMode;
230
- exports.isDevDebugMode = __webpack_exports__.isDevDebugMode;
231
- exports.isExternalUrl = __webpack_exports__.isExternalUrl;
232
- exports.isProduction = __webpack_exports__.isProduction;
233
- exports.isSCM = __webpack_exports__.isSCM;
234
- exports.normalizeHref = __webpack_exports__.normalizeHref;
235
- exports.normalizePosixPath = __webpack_exports__.normalizePosixPath;
236
- exports.normalizeSlash = __webpack_exports__.normalizeSlash;
237
- exports.parseUrl = __webpack_exports__.parseUrl;
238
- exports.removeBase = __webpack_exports__.removeBase;
239
- exports.removeHash = __webpack_exports__.removeHash;
240
- exports.removeLeadingSlash = __webpack_exports__.removeLeadingSlash;
241
- exports.removeTrailingSlash = __webpack_exports__.removeTrailingSlash;
242
- exports.replaceLang = __webpack_exports__.replaceLang;
243
- exports.replaceVersion = __webpack_exports__.replaceVersion;
244
- exports.slash = __webpack_exports__.slash;
245
- exports.withBase = __webpack_exports__.withBase;
246
- exports.withoutBase = __webpack_exports__.withoutBase;
247
- exports.withoutLang = __webpack_exports__.withoutLang;
248
- for(var __webpack_i__ in __webpack_exports__)if (-1 === [
249
- "APPEARANCE_KEY",
250
- "DEFAULT_HIGHLIGHT_LANGUAGES",
251
- "HASH_REGEXP",
252
- "MDX_OR_MD_REGEXP",
253
- "QUERY_REGEXP",
254
- "RSPRESS_TEMP_DIR",
255
- "SEARCH_INDEX_NAME",
256
- "addLeadingSlash",
257
- "addTrailingSlash",
258
- "cleanUrl",
259
- "inBrowser",
260
- "isDataUrl",
261
- "isDebugMode",
262
- "isDevDebugMode",
263
- "isExternalUrl",
264
- "isProduction",
265
- "isSCM",
266
- "normalizeHref",
267
- "normalizePosixPath",
268
- "normalizeSlash",
269
- "parseUrl",
270
- "removeBase",
271
- "removeHash",
272
- "removeLeadingSlash",
273
- "removeTrailingSlash",
274
- "replaceLang",
275
- "replaceVersion",
276
- "slash",
277
- "withBase",
278
- "withoutBase",
279
- "withoutLang"
280
- ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
281
- Object.defineProperty(exports, '__esModule', {
282
- value: true
283
- });
159
+ const matchSidebar = (pattern, currentPathname, base)=>{
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 };
package/dist/logger.js CHANGED
@@ -1,36 +1,3 @@
1
- "use strict";
2
- var __webpack_require__ = {};
3
- (()=>{
4
- __webpack_require__.d = (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 = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
- })();
14
- (()=>{
15
- __webpack_require__.r = (exports1)=>{
16
- if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
- value: 'Module'
18
- });
19
- Object.defineProperty(exports1, '__esModule', {
20
- value: true
21
- });
22
- };
23
- })();
24
- var __webpack_exports__ = {};
25
- __webpack_require__.r(__webpack_exports__);
26
- __webpack_require__.d(__webpack_exports__, {
27
- logger: ()=>core_namespaceObject.logger
28
- });
29
- const core_namespaceObject = require("@rsbuild/core");
30
- exports.logger = __webpack_exports__.logger;
31
- for(var __webpack_i__ in __webpack_exports__)if (-1 === [
32
- "logger"
33
- ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
34
- Object.defineProperty(exports, '__esModule', {
35
- value: true
36
- });
1
+ import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__ from "@rsbuild/core";
2
+ var __webpack_exports__logger = __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger;
3
+ export { __webpack_exports__logger as logger };
@@ -321,21 +321,6 @@ declare interface MarkdownOptions {
321
321
  * Register prism languages
322
322
  */
323
323
  highlightLanguages?: (string | [string, string])[];
324
- /**
325
- * Whether to enable mdx-rs, default is true
326
- */
327
- mdxRs?: boolean | MdxRsOptions;
328
- /**
329
- * @deprecated, use `mdxRs` instead
330
- */
331
- experimentalMdxRs?: boolean;
332
- }
333
-
334
- declare interface MdxRsOptions {
335
- /**
336
- * Determine whether the file use mdxRs compiler
337
- */
338
- include?: (filepath: string) => boolean;
339
324
  }
340
325
 
341
326
  export declare const mergeDocConfig: (...configs: UserConfig[]) => Promise<UserConfig>;
@@ -381,6 +366,7 @@ declare interface PageIndexInfo {
381
366
  routePath: string;
382
367
  toc: Header[];
383
368
  content: string;
369
+ _flattenContent?: string;
384
370
  _html: string;
385
371
  frontmatter: FrontMatterMeta;
386
372
  lang: string;
@@ -496,6 +482,10 @@ declare interface RspressPlugin {
496
482
  * Callback after route generated
497
483
  */
498
484
  routeGenerated?: (routes: RouteMeta[], isProd: boolean) => Promise<void> | void;
485
+ /**
486
+ * Callback after routeService generated
487
+ */
488
+ routeServiceGenerated?: (routeService: any, isProd: boolean) => Promise<void> | void;
499
489
  /**
500
490
  * Add addition ssg routes, for dynamic routes.
501
491
  */
@@ -1,125 +1,53 @@
1
- "use strict";
2
- var __webpack_modules__ = {
3
- "lodash-es": function(module) {
4
- module.exports = import("lodash-es").then(function(module) {
5
- return module;
6
- });
7
- }
1
+ import * as __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__ from "node:path";
2
+ import * as __WEBPACK_EXTERNAL_MODULE_gray_matter_90c6cd0b__ from "gray-matter";
3
+ import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__ from "@rsbuild/core";
4
+ const extractTextAndId = (title)=>{
5
+ if (!title) return [
6
+ '',
7
+ ''
8
+ ];
9
+ const customIdReg = /\\?{#.*}/;
10
+ const text = title.replace(customIdReg, '').trimEnd();
11
+ const customId = title.match(customIdReg)?.[0]?.slice(2, -1) || '';
12
+ return [
13
+ text,
14
+ customId
15
+ ];
8
16
  };
9
- var __webpack_module_cache__ = {};
10
- function __webpack_require__(moduleId) {
11
- var cachedModule = __webpack_module_cache__[moduleId];
12
- if (void 0 !== cachedModule) return cachedModule.exports;
13
- var module = __webpack_module_cache__[moduleId] = {
14
- exports: {}
15
- };
16
- __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
17
- return module.exports;
17
+ function getNodeAttribute(node, attrName, attribute) {
18
+ const found = node.attributes.find((attr)=>'name' in attr && attr.name === attrName);
19
+ return attribute ? found : found?.value;
18
20
  }
19
- (()=>{
20
- __webpack_require__.n = (module)=>{
21
- var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
22
- __webpack_require__.d(getter, {
23
- a: getter
24
- });
25
- return getter;
26
- };
27
- })();
28
- (()=>{
29
- __webpack_require__.d = (exports1, definition)=>{
30
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
31
- enumerable: true,
32
- get: definition[key]
33
- });
34
- };
35
- })();
36
- (()=>{
37
- __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
38
- })();
39
- (()=>{
40
- __webpack_require__.r = (exports1)=>{
41
- if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
42
- value: 'Module'
43
- });
44
- Object.defineProperty(exports1, '__esModule', {
45
- value: true
46
- });
47
- };
48
- })();
49
- var __webpack_exports__ = {};
50
- (()=>{
51
- __webpack_require__.r(__webpack_exports__);
52
- __webpack_require__.d(__webpack_exports__, {
53
- extractTextAndId: ()=>extractTextAndId,
54
- loadFrontMatter: ()=>loadFrontMatter,
55
- mergeDocConfig: ()=>mergeDocConfig,
56
- getNodeAttribute: ()=>getNodeAttribute
57
- });
58
- const extractTextAndId = (title)=>{
59
- if (!title) return [
60
- '',
61
- ''
62
- ];
63
- const customIdReg = /\\?{#.*}/;
64
- const text = title.replace(customIdReg, '').trimEnd();
65
- const customId = title.match(customIdReg)?.[0]?.slice(2, -1) || '';
66
- return [
67
- text,
68
- customId
69
- ];
70
- };
71
- function getNodeAttribute(node, attrName, attribute) {
72
- const found = node.attributes.find((attr)=>'name' in attr && attr.name === attrName);
73
- return attribute ? found : found?.value;
74
- }
75
- const external_node_path_namespaceObject = require("node:path");
76
- var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
77
- const external_gray_matter_namespaceObject = require("gray-matter");
78
- var external_gray_matter_default = /*#__PURE__*/ __webpack_require__.n(external_gray_matter_namespaceObject);
79
- const core_namespaceObject = require("@rsbuild/core");
80
- function loadFrontMatter(source, filepath, root, outputWarning = false) {
81
- try {
82
- const { content, data } = external_gray_matter_default()(source);
83
- return {
84
- content,
85
- frontmatter: data
86
- };
87
- } catch (e) {
88
- if (outputWarning) core_namespaceObject.logger.warn(`Parse frontmatter error in ${external_node_path_default().relative(root, filepath)}: \n`, e);
89
- }
21
+ function loadFrontMatter(source, filepath, root, outputWarning = false) {
22
+ try {
23
+ const { content, data } = (0, __WEBPACK_EXTERNAL_MODULE_gray_matter_90c6cd0b__["default"])(source);
90
24
  return {
91
- content: '',
92
- frontmatter: {}
25
+ content,
26
+ frontmatter: data
93
27
  };
28
+ } catch (e) {
29
+ if (outputWarning) __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.warn(`Parse frontmatter error in ${__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].relative(root, filepath)}: \n`, e);
94
30
  }
95
- const castArray = (value)=>Array.isArray(value) ? value : [
96
- value
97
- ];
98
- const mergeDocConfig = async (...configs)=>{
99
- const { mergeWith } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "lodash-es"));
100
- return mergeWith({}, ...configs, (target, source)=>{
101
- const pair = [
102
- target,
103
- source
104
- ];
105
- if (pair.some((item)=>void 0 === item)) return;
106
- if (pair.some((item)=>Array.isArray(item))) return [
107
- ...castArray(target),
108
- ...castArray(source)
109
- ];
110
- });
31
+ return {
32
+ content: '',
33
+ frontmatter: {}
111
34
  };
112
- })();
113
- exports.extractTextAndId = __webpack_exports__.extractTextAndId;
114
- exports.getNodeAttribute = __webpack_exports__.getNodeAttribute;
115
- exports.loadFrontMatter = __webpack_exports__.loadFrontMatter;
116
- exports.mergeDocConfig = __webpack_exports__.mergeDocConfig;
117
- for(var __webpack_i__ in __webpack_exports__)if (-1 === [
118
- "extractTextAndId",
119
- "getNodeAttribute",
120
- "loadFrontMatter",
121
- "mergeDocConfig"
122
- ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
123
- Object.defineProperty(exports, '__esModule', {
124
- value: true
125
- });
35
+ }
36
+ const castArray = (value)=>Array.isArray(value) ? value : [
37
+ value
38
+ ];
39
+ const mergeDocConfig = async (...configs)=>{
40
+ const { mergeWith } = await import("lodash-es");
41
+ return mergeWith({}, ...configs, (target, source)=>{
42
+ const pair = [
43
+ target,
44
+ source
45
+ ];
46
+ if (pair.some((item)=>void 0 === item)) return;
47
+ if (pair.some((item)=>Array.isArray(item))) return [
48
+ ...castArray(target),
49
+ ...castArray(source)
50
+ ];
51
+ });
52
+ };
53
+ export { extractTextAndId, getNodeAttribute, loadFrontMatter, mergeDocConfig };
package/package.json CHANGED
@@ -1,36 +1,32 @@
1
1
  {
2
2
  "name": "@rspress/shared",
3
- "version": "2.0.0-beta.0",
3
+ "version": "2.0.0-beta.2",
4
4
  "repository": {
5
5
  "type": "git",
6
- "url": "https://github.com/web-infra-dev/rspress",
6
+ "url": "git+https://github.com/web-infra-dev/rspress.git",
7
7
  "directory": "packages/shared"
8
8
  },
9
9
  "license": "MIT",
10
+ "type": "module",
10
11
  "exports": {
11
12
  ".": {
12
13
  "types": "./dist/index.d.ts",
13
- "import": "./dist/index.mjs",
14
- "require": "./dist/index.js"
14
+ "default": "./dist/index.js"
15
15
  },
16
16
  "./constants": {
17
17
  "types": "./dist/constants.d.ts",
18
- "import": "./dist/constants.mjs",
19
- "require": "./dist/constants.js"
18
+ "default": "./dist/constants.js"
20
19
  },
21
20
  "./logger": {
22
21
  "types": "./dist/logger.d.ts",
23
- "import": "./dist/logger.mjs",
24
- "require": "./dist/logger.js"
22
+ "default": "./dist/logger.js"
25
23
  },
26
24
  "./node-utils": {
27
25
  "types": "./dist/node-utils.d.ts",
28
- "import": "./dist/node-utils.mjs",
29
- "require": "./dist/node-utils.js"
26
+ "default": "./dist/node-utils.js"
30
27
  }
31
28
  },
32
- "main": "./dist/index.js",
33
- "module": "./dist/index.mjs",
29
+ "module": "./dist/index.js",
34
30
  "types": "./dist/index.d.ts",
35
31
  "files": [
36
32
  "dist"
@@ -50,6 +46,7 @@
50
46
  "mdast-util-mdx-jsx": "^3.2.0",
51
47
  "medium-zoom": "1.1.0",
52
48
  "rimraf": "^6.0.1",
49
+ "rsbuild-plugin-publint": "^0.3.0",
53
50
  "typescript": "^5.8.2"
54
51
  },
55
52
  "publishConfig": {
@@ -1,18 +0,0 @@
1
- const DEFAULT_CONFIG_NAME = 'rspress.config';
2
- const DEFAULT_CONFIG_EXTENSIONS = [
3
- '.js',
4
- '.ts',
5
- '.mjs',
6
- '.mts',
7
- '.cjs',
8
- '.cts'
9
- ];
10
- const DEFAULT_PAGE_EXTENSIONS = [
11
- '.js',
12
- '.jsx',
13
- '.ts',
14
- '.tsx',
15
- '.md',
16
- '.mdx'
17
- ];
18
- export { DEFAULT_CONFIG_EXTENSIONS, DEFAULT_CONFIG_NAME, DEFAULT_PAGE_EXTENSIONS };
package/dist/index.mjs DELETED
@@ -1,159 +0,0 @@
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
- if (url.startsWith('#')) return url;
136
- let { url: cleanUrl, hash } = parseUrl(decodeURIComponent(url));
137
- if (cleanUrls) {
138
- if (cleanUrl.endsWith('.html')) cleanUrl = cleanUrl.replace(/\.html$/, '');
139
- if (cleanUrls && cleanUrl.endsWith('/index')) cleanUrl = cleanUrl.replace(/\/index$/, '/');
140
- } else if (!cleanUrl.endsWith('.html')) if (cleanUrl.endsWith('/')) cleanUrl += 'index.html';
141
- else cleanUrl += '.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 };
package/dist/logger.mjs DELETED
@@ -1,3 +0,0 @@
1
- import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__ from "@rsbuild/core";
2
- var __webpack_exports__logger = __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger;
3
- export { __webpack_exports__logger as logger };
@@ -1,53 +0,0 @@
1
- import * as __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__ from "node:path";
2
- import * as __WEBPACK_EXTERNAL_MODULE_gray_matter_90c6cd0b__ from "gray-matter";
3
- import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__ from "@rsbuild/core";
4
- const extractTextAndId = (title)=>{
5
- if (!title) return [
6
- '',
7
- ''
8
- ];
9
- const customIdReg = /\\?{#.*}/;
10
- const text = title.replace(customIdReg, '').trimEnd();
11
- const customId = title.match(customIdReg)?.[0]?.slice(2, -1) || '';
12
- return [
13
- text,
14
- customId
15
- ];
16
- };
17
- function getNodeAttribute(node, attrName, attribute) {
18
- const found = node.attributes.find((attr)=>'name' in attr && attr.name === attrName);
19
- return attribute ? found : found?.value;
20
- }
21
- function loadFrontMatter(source, filepath, root, outputWarning = false) {
22
- try {
23
- const { content, data } = (0, __WEBPACK_EXTERNAL_MODULE_gray_matter_90c6cd0b__["default"])(source);
24
- return {
25
- content,
26
- frontmatter: data
27
- };
28
- } catch (e) {
29
- if (outputWarning) __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.warn(`Parse frontmatter error in ${__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].relative(root, filepath)}: \n`, e);
30
- }
31
- return {
32
- content: '',
33
- frontmatter: {}
34
- };
35
- }
36
- const castArray = (value)=>Array.isArray(value) ? value : [
37
- value
38
- ];
39
- const mergeDocConfig = async (...configs)=>{
40
- const { mergeWith } = await import("lodash-es");
41
- return mergeWith({}, ...configs, (target, source)=>{
42
- const pair = [
43
- target,
44
- source
45
- ];
46
- if (pair.some((item)=>void 0 === item)) return;
47
- if (pair.some((item)=>Array.isArray(item))) return [
48
- ...castArray(target),
49
- ...castArray(source)
50
- ];
51
- });
52
- };
53
- export { extractTextAndId, getNodeAttribute, loadFrontMatter, mergeDocConfig };