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

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
@@ -1,5 +1,6 @@
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
5
  import type { RsbuildPlugin } from '@rsbuild/core';
5
6
 
@@ -143,7 +144,7 @@ export declare interface DefaultThemeConfig {
143
144
  * Whether to redirect to the closest locale when the user visits the site
144
145
  * @default 'auto'
145
146
  */
146
- localeRedirect?: 'auto' | 'never';
147
+ localeRedirect?: 'auto' | 'never' | 'only-default-lang';
147
148
  /**
148
149
  * Whether to show the fallback heading title when the heading title is not presented but `frontmatter.title` exists
149
150
  * @default true
@@ -214,6 +215,14 @@ export declare interface FrontMatterMeta {
214
215
  [key: string]: unknown;
215
216
  }
216
217
 
218
+ /**
219
+ * get the sidebar group for the current page
220
+ * @param sidebar const { sidebar } = useLocaleSiteData();
221
+ * @param currentPathname
222
+ * @returns
223
+ */
224
+ export declare const getSidebarDataGroup: (sidebar: NormalizedSidebar, currentPathname: string, base: string) => NormalizedSidebar[string];
225
+
217
226
  export declare const HASH_REGEXP: RegExp;
218
227
 
219
228
  export declare interface Header {
@@ -344,31 +353,21 @@ export declare interface MarkdownOptions {
344
353
  */
345
354
  globalComponents?: string[];
346
355
  /**
347
- * Code highlighter, default is prism for performance reason
348
- */
349
- codeHighlighter?: 'prism' | 'shiki';
350
- /**
351
- * Register prism languages
356
+ * @type import('@shikijs/rehype').RehypeShikiOptions
352
357
  */
353
- 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;
358
+ shiki?: Partial<PluginShikiOptions>;
362
359
  }
363
360
 
364
- export declare const MDX_OR_MD_REGEXP: RegExp;
361
+ export declare const matchNavbar: (item: NavItemWithLink, currentPathname: string, base: string) => boolean;
365
362
 
366
- export declare interface MdxRsOptions {
367
- /**
368
- * Determine whether the file use mdxRs compiler
369
- */
370
- include?: (filepath: string) => boolean;
371
- }
363
+ /**
364
+ * match the sidebar key in user config
365
+ * @param pattern /zh/guide
366
+ * @param currentPathname /base/zh/guide/getting-started
367
+ */
368
+ export declare const matchSidebar: (pattern: string, currentPathname: string, base: string) => boolean;
369
+
370
+ export declare const MDX_OR_MD_REGEXP: RegExp;
372
371
 
373
372
  export declare type Nav = NavItem[] | {
374
373
  [key: string]: NavItem[];
@@ -450,6 +449,7 @@ export declare interface PageIndexInfo {
450
449
  routePath: string;
451
450
  toc: Header[];
452
451
  content: string;
452
+ _flattenContent?: string;
453
453
  _html: string;
454
454
  frontmatter: FrontMatterMeta;
455
455
  lang: string;
@@ -473,6 +473,8 @@ export declare const parseUrl: (url: string) => {
473
473
  hash: string;
474
474
  };
475
475
 
476
+ declare type PluginShikiOptions = RehypeShikiOptions;
477
+
476
478
  export declare const QUERY_REGEXP: RegExp;
477
479
 
478
480
  export declare type RemotePageInfo = PageIndexInfo & {
@@ -625,6 +627,10 @@ declare interface RspressPlugin {
625
627
  * Callback after route generated
626
628
  */
627
629
  routeGenerated?: (routes: RouteMeta[], isProd: boolean) => Promise<void> | void;
630
+ /**
631
+ * Callback after routeService generated
632
+ */
633
+ routeServiceGenerated?: (routeService: any, isProd: boolean) => Promise<void> | void;
628
634
  /**
629
635
  * Add addition ssg routes, for dynamic routes.
630
636
  */
@@ -717,7 +723,7 @@ export declare interface SiteData<ThemeConfig = NormalizedConfig> {
717
723
  markdown: {
718
724
  showLineNumbers: boolean;
719
725
  defaultWrapCode: boolean;
720
- codeHighlighter: 'prism' | 'shiki';
726
+ shiki: Partial<PluginShikiOptions>;
721
727
  };
722
728
  multiVersion: {
723
729
  default: string;
@@ -763,7 +769,7 @@ export declare interface UserConfig<ThemeConfig = DefaultThemeConfig> {
763
769
  /**
764
770
  * Path to html icon file.
765
771
  */
766
- icon?: string;
772
+ icon?: string | URL;
767
773
  /**
768
774
  * Default language of the site.
769
775
  */
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 };
@@ -4,6 +4,7 @@ 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
9
  import type { RsbuildPlugin } from '@rsbuild/core';
9
10
 
@@ -131,7 +132,7 @@ declare interface Config {
131
132
  * Whether to redirect to the closest locale when the user visits the site
132
133
  * @default 'auto'
133
134
  */
134
- localeRedirect?: 'auto' | 'never';
135
+ localeRedirect?: 'auto' | 'never' | 'only-default-lang';
135
136
  /**
136
137
  * Whether to show the fallback heading title when the heading title is not presented but `frontmatter.title` exists
137
138
  * @default true
@@ -207,6 +208,18 @@ declare interface FrontMatterMeta {
207
208
  [key: string]: unknown;
208
209
  }
209
210
 
211
+ /**
212
+ * Transform `config.icon` into final url path in the web app
213
+ *
214
+ * @param icon original icon in config
215
+ * @returns final url path in the web app
216
+ */
217
+ export declare function getIconUrlPath(icon: '' | undefined): undefined;
218
+
219
+ export declare function getIconUrlPath(icon: string | URL): string;
220
+
221
+ export declare function getIconUrlPath(icon: string | URL | undefined): string | undefined;
222
+
210
223
  export declare function getNodeAttribute(node: MdxJsxFlowElement | MdxJsxTextElement, attrName: string, attribute?: false): string | MdxJsxAttributeValueExpression | null | undefined;
211
224
 
212
225
  export declare function getNodeAttribute(node: MdxJsxFlowElement | MdxJsxTextElement, attrName: string, attribute: true): MdxJsxAttribute | MdxJsxExpressionAttribute | undefined;
@@ -245,6 +258,7 @@ declare interface Hero {
245
258
  export declare function loadFrontMatter<TFrontmatter extends Record<string, unknown> = FrontMatterMeta>(source: string, filepath: string, root: string, outputWarning?: boolean): {
246
259
  frontmatter: TFrontmatter;
247
260
  content: string;
261
+ emptyLinesSource: string;
248
262
  };
249
263
 
250
264
  declare interface Locale {
@@ -314,28 +328,9 @@ declare interface MarkdownOptions {
314
328
  */
315
329
  globalComponents?: string[];
316
330
  /**
317
- * Code highlighter, default is prism for performance reason
318
- */
319
- codeHighlighter?: 'prism' | 'shiki';
320
- /**
321
- * Register prism languages
322
- */
323
- highlightLanguages?: (string | [string, string])[];
324
- /**
325
- * Whether to enable mdx-rs, default is true
331
+ * @type import('@shikijs/rehype').RehypeShikiOptions
326
332
  */
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;
333
+ shiki?: Partial<PluginShikiOptions>;
339
334
  }
340
335
 
341
336
  export declare const mergeDocConfig: (...configs: UserConfig[]) => Promise<UserConfig>;
@@ -381,6 +376,7 @@ declare interface PageIndexInfo {
381
376
  routePath: string;
382
377
  toc: Header[];
383
378
  content: string;
379
+ _flattenContent?: string;
384
380
  _html: string;
385
381
  frontmatter: FrontMatterMeta;
386
382
  lang: string;
@@ -392,6 +388,8 @@ declare interface PageIndexInfo {
392
388
 
393
389
  declare type PageType = 'home' | 'doc' | 'custom' | '404' | 'blank';
394
390
 
391
+ declare type PluginShikiOptions = RehypeShikiOptions;
392
+
395
393
  declare type RemoteSearchIndexInfo = string | {
396
394
  value: string;
397
395
  label: string;
@@ -496,6 +494,10 @@ declare interface RspressPlugin {
496
494
  * Callback after route generated
497
495
  */
498
496
  routeGenerated?: (routes: RouteMeta[], isProd: boolean) => Promise<void> | void;
497
+ /**
498
+ * Callback after routeService generated
499
+ */
500
+ routeServiceGenerated?: (routeService: any, isProd: boolean) => Promise<void> | void;
499
501
  /**
500
502
  * Add addition ssg routes, for dynamic routes.
501
503
  */
@@ -596,7 +598,7 @@ declare interface UserConfig<ThemeConfig = Config> {
596
598
  /**
597
599
  * Path to html icon file.
598
600
  */
599
- icon?: string;
601
+ icon?: string | URL;
600
602
  /**
601
603
  * Default language of the site.
602
604
  */
@@ -1,125 +1,65 @@
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_node_url_e96de089__ from "node:url";
3
+ import * as __WEBPACK_EXTERNAL_MODULE_gray_matter_90c6cd0b__ from "gray-matter";
4
+ import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__ from "@rsbuild/core";
5
+ const extractTextAndId = (title)=>{
6
+ if (!title) return [
7
+ '',
8
+ ''
9
+ ];
10
+ const customIdReg = /\\?{#.*}/;
11
+ const text = title.replace(customIdReg, '').trimEnd();
12
+ const customId = title.match(customIdReg)?.[0]?.slice(2, -1) || '';
13
+ return [
14
+ text,
15
+ customId
16
+ ];
8
17
  };
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;
18
+ function getIconUrlPath(icon) {
19
+ if (!icon) return;
20
+ icon = icon.toString();
21
+ if (icon.startsWith('file://')) icon = (0, __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__.fileURLToPath)(icon);
22
+ if (!__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].isAbsolute(icon)) return icon;
23
+ return `/${__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].basename(icon)}`;
18
24
  }
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
- }
25
+ function getNodeAttribute(node, attrName, attribute) {
26
+ const found = node.attributes.find((attr)=>'name' in attr && attr.name === attrName);
27
+ return attribute ? found : found?.value;
28
+ }
29
+ function loadFrontMatter(source, filepath, root, outputWarning = false) {
30
+ try {
31
+ const { content, data } = (0, __WEBPACK_EXTERNAL_MODULE_gray_matter_90c6cd0b__["default"])(source);
32
+ const rawFrontMatter = source.slice(0, source.length - content.length);
33
+ const emptyLinesSource = rawFrontMatter.length ? `${rawFrontMatter.replace(/[^\n]/g, '')}${content}` : content;
90
34
  return {
91
- content: '',
92
- frontmatter: {}
35
+ content,
36
+ frontmatter: data,
37
+ emptyLinesSource
93
38
  };
39
+ } catch (e) {
40
+ 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
41
  }
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
- });
42
+ return {
43
+ content: '',
44
+ frontmatter: {},
45
+ emptyLinesSource: source
111
46
  };
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
- });
47
+ }
48
+ const castArray = (value)=>Array.isArray(value) ? value : [
49
+ value
50
+ ];
51
+ const mergeDocConfig = async (...configs)=>{
52
+ const { mergeWith } = await import("lodash-es");
53
+ return mergeWith({}, ...configs, (target, source)=>{
54
+ const pair = [
55
+ target,
56
+ source
57
+ ];
58
+ if (pair.some((item)=>void 0 === item)) return;
59
+ if (pair.some((item)=>Array.isArray(item))) return [
60
+ ...castArray(target),
61
+ ...castArray(source)
62
+ ];
63
+ });
64
+ };
65
+ export { extractTextAndId, getIconUrlPath, getNodeAttribute, loadFrontMatter, mergeDocConfig };
package/package.json CHANGED
@@ -1,55 +1,53 @@
1
1
  {
2
2
  "name": "@rspress/shared",
3
- "version": "2.0.0-beta.0",
3
+ "version": "2.0.0-beta.10",
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"
37
33
  ],
38
34
  "dependencies": {
39
- "@rsbuild/core": "1.3.9",
35
+ "@rsbuild/core": "~1.3.21",
36
+ "@shikijs/rehype": "^3.4.2",
40
37
  "gray-matter": "4.0.3",
41
38
  "lodash-es": "^4.17.21",
42
39
  "unified": "^11.0.5"
43
40
  },
44
41
  "devDependencies": {
45
- "@rslib/core": "0.6.5",
42
+ "@rslib/core": "0.8.0",
46
43
  "@types/jest": "~29.5.14",
47
44
  "@types/lodash-es": "^4.17.12",
48
- "@types/node": "^18.11.17",
49
- "@types/react": "^18.3.20",
45
+ "@types/node": "^22.8.1",
46
+ "@types/react": "^18.3.22",
50
47
  "mdast-util-mdx-jsx": "^3.2.0",
51
48
  "medium-zoom": "1.1.0",
52
49
  "rimraf": "^6.0.1",
50
+ "rsbuild-plugin-publint": "^0.3.2",
53
51
  "typescript": "^5.8.2"
54
52
  },
55
53
  "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 };