@rspress/shared 1.41.3 → 1.42.1-canary-20240226

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { loadConfig } from '@rsbuild/core';
1
2
  import type { PluggableList } from 'unified';
2
3
  import type { RsbuildConfig } from '@rsbuild/core';
3
4
  import type { RsbuildPlugin } from '@rsbuild/core';
@@ -17,13 +18,15 @@ export declare function addLeadingSlash(url: string): string;
17
18
 
18
19
  export declare function addTrailingSlash(url: string): string;
19
20
 
21
+ export declare type AnyFunction = (...args: any[]) => any;
22
+
20
23
  export declare const APPEARANCE_KEY = "rspress-theme-appearance";
21
24
 
22
25
  export declare type BaseRuntimePageInfo = Omit<RemoveUnderscoreProps<PageIndexInfo>, 'id' | 'content' | 'domain'>;
23
26
 
24
27
  export declare const cleanUrl: (url: string) => string;
25
28
 
26
- export declare type Config = UserConfig | Promise<UserConfig> | ((env: any) => UserConfig | Promise<UserConfig>);
29
+ export declare type Config = UserConfig | Promise<UserConfig> | ((...args: Parameters<typeof loadConfig>) => UserConfig | Promise<UserConfig>);
27
30
 
28
31
  export declare const DEFAULT_HIGHLIGHT_LANGUAGES: string[][];
29
32
 
@@ -203,7 +206,7 @@ export declare interface FrontMatterMeta {
203
206
  sidebar?: boolean;
204
207
  outline?: boolean;
205
208
  lineNumbers?: boolean;
206
- overviewHeaders?: number;
209
+ overviewHeaders?: number[];
207
210
  titleSuffix?: string;
208
211
  head?: [string, Record<string, string>][];
209
212
  context?: string;
@@ -440,20 +443,20 @@ export declare interface PageData {
440
443
  * "_foo" is the private field that won't be written to search-index.json file
441
444
  * and should not be used in the runtime (usePageData).
442
445
  */
443
- export declare type PageIndexInfo = {
446
+ export declare interface PageIndexInfo {
444
447
  id: number;
445
448
  title: string;
446
449
  routePath: string;
447
450
  toc: Header[];
448
451
  content: string;
449
452
  _html: string;
450
- frontmatter: Record<string, unknown>;
453
+ frontmatter: FrontMatterMeta;
451
454
  lang: string;
452
455
  version: string;
453
456
  domain: string;
454
457
  _filepath: string;
455
458
  _relativePath: string;
456
- };
459
+ }
457
460
 
458
461
  export declare interface PageModule<T extends React.ComponentType<unknown>> {
459
462
  default: T;
@@ -608,9 +611,7 @@ declare interface RspressPlugin {
608
611
  /**
609
612
  * Extend every page's data
610
613
  */
611
- extendPageData?: (pageData: PageIndexInfo & {
612
- [key: string]: unknown;
613
- }, isProd: boolean) => void | Promise<void>;
614
+ extendPageData?: (pageData: PageIndexInfo, isProd: boolean) => void | Promise<void>;
614
615
  /**
615
616
  * Add custom route
616
617
  */
@@ -871,15 +872,15 @@ export declare interface UserConfig<ThemeConfig = DefaultThemeConfig> {
871
872
  /**
872
873
  * Whether to enable language parity checking
873
874
  */
874
- enabled: boolean;
875
+ enabled?: boolean;
875
876
  /**
876
877
  * Directories to include in the parity check
877
878
  */
878
- include: string[];
879
+ include?: string[];
879
880
  /**
880
881
  * Directories to exclude from the parity check
881
882
  */
882
- exclude: string[];
883
+ exclude?: string[];
883
884
  };
884
885
  }
885
886
 
@@ -1,3 +1,6 @@
1
+ import { MdxJsxAttributeValueExpression } from 'mdast-util-mdx-jsx';
2
+ import type { MdxJsxFlowElement } from 'mdast-util-mdx-jsx';
3
+ import type { MdxJsxTextElement } from 'mdast-util-mdx-jsx';
1
4
  import type { PluggableList } from 'unified';
2
5
  import type { RsbuildConfig } from '@rsbuild/core';
3
6
  import type { RsbuildPlugin } from '@rsbuild/core';
@@ -158,6 +161,19 @@ declare interface EditLink {
158
161
  text?: string;
159
162
  }
160
163
 
164
+ /**
165
+ * hello world {#custom-id} -> { text: 'hello world', id: 'custom-id' }
166
+ */
167
+ export declare const extractTextAndId: (title?: string) => [text: string, customId: string];
168
+
169
+ declare interface Feature {
170
+ icon: string;
171
+ title: string;
172
+ details: string;
173
+ span?: number;
174
+ link?: string;
175
+ }
176
+
161
177
  /**
162
178
  * The config of filter component
163
179
  */
@@ -171,6 +187,25 @@ declare interface Footer {
171
187
  message?: string;
172
188
  }
173
189
 
190
+ declare interface FrontMatterMeta {
191
+ title?: string;
192
+ description?: string;
193
+ overview?: boolean;
194
+ pageType?: PageType;
195
+ features?: Feature[];
196
+ hero?: Hero;
197
+ sidebar?: boolean;
198
+ outline?: boolean;
199
+ lineNumbers?: boolean;
200
+ overviewHeaders?: number[];
201
+ titleSuffix?: string;
202
+ head?: [string, Record<string, string>][];
203
+ context?: string;
204
+ [key: string]: unknown;
205
+ }
206
+
207
+ export declare const getNodeAttribute: (node: MdxJsxFlowElement | MdxJsxTextElement, attrName: string) => string | MdxJsxAttributeValueExpression | null | undefined;
208
+
174
209
  declare interface Header {
175
210
  id: string;
176
211
  text: string;
@@ -178,7 +213,31 @@ declare interface Header {
178
213
  charIndex: number;
179
214
  }
180
215
 
181
- export declare function loadFrontMatter<TFrontmatter extends Record<string, unknown> = Record<string, string>>(source: string, filepath: string, root: string, outputWarning?: boolean): {
216
+ declare interface Hero {
217
+ name: string;
218
+ text: string;
219
+ tagline: string;
220
+ image?: {
221
+ src: string | {
222
+ dark: string;
223
+ light: string;
224
+ };
225
+ alt: string;
226
+ /**
227
+ * `srcset` and `sizes` are attributes of `<img>` tag. Please refer to https://mdn.io/srcset for the usage.
228
+ * When the value is an array, rspress will join array members with commas.
229
+ **/
230
+ sizes?: string | string[];
231
+ srcset?: string | string[];
232
+ };
233
+ actions: {
234
+ text: string;
235
+ link: string;
236
+ theme: 'brand' | 'alt';
237
+ }[];
238
+ }
239
+
240
+ export declare function loadFrontMatter<TFrontmatter extends Record<string, unknown> = FrontMatterMeta>(source: string, filepath: string, root: string, outputWarning?: boolean): {
182
241
  frontmatter: TFrontmatter;
183
242
  content: string;
184
243
  };
@@ -311,20 +370,22 @@ declare interface NavItemWithLinkAndChildren {
311
370
  * "_foo" is the private field that won't be written to search-index.json file
312
371
  * and should not be used in the runtime (usePageData).
313
372
  */
314
- declare type PageIndexInfo = {
373
+ declare interface PageIndexInfo {
315
374
  id: number;
316
375
  title: string;
317
376
  routePath: string;
318
377
  toc: Header[];
319
378
  content: string;
320
379
  _html: string;
321
- frontmatter: Record<string, unknown>;
380
+ frontmatter: FrontMatterMeta;
322
381
  lang: string;
323
382
  version: string;
324
383
  domain: string;
325
384
  _filepath: string;
326
385
  _relativePath: string;
327
- };
386
+ }
387
+
388
+ declare type PageType = 'home' | 'doc' | 'custom' | '404' | 'blank';
328
389
 
329
390
  declare type RemoteSearchIndexInfo = string | {
330
391
  value: string;
@@ -417,9 +478,7 @@ declare interface RspressPlugin {
417
478
  /**
418
479
  * Extend every page's data
419
480
  */
420
- extendPageData?: (pageData: PageIndexInfo & {
421
- [key: string]: unknown;
422
- }, isProd: boolean) => void | Promise<void>;
481
+ extendPageData?: (pageData: PageIndexInfo, isProd: boolean) => void | Promise<void>;
423
482
  /**
424
483
  * Add custom route
425
484
  */
@@ -642,15 +701,15 @@ declare interface UserConfig<ThemeConfig = Config> {
642
701
  /**
643
702
  * Whether to enable language parity checking
644
703
  */
645
- enabled: boolean;
704
+ enabled?: boolean;
646
705
  /**
647
706
  * Directories to include in the parity check
648
707
  */
649
- include: string[];
708
+ include?: string[];
650
709
  /**
651
710
  * Directories to exclude from the parity check
652
711
  */
653
- exclude: string[];
712
+ exclude?: string[];
654
713
  };
655
714
  }
656
715
 
@@ -54,9 +54,25 @@ var __webpack_exports__ = {};
54
54
  (()=>{
55
55
  __webpack_require__.r(__webpack_exports__);
56
56
  __webpack_require__.d(__webpack_exports__, {
57
- mergeDocConfig: ()=>mergeDocConfig,
58
- loadFrontMatter: ()=>loadFrontMatter
57
+ extractTextAndId: ()=>extractTextAndId,
58
+ loadFrontMatter: ()=>loadFrontMatter,
59
+ getNodeAttribute: ()=>getNodeAttribute,
60
+ mergeDocConfig: ()=>mergeDocConfig
59
61
  });
62
+ const extractTextAndId = (title)=>{
63
+ if (!title) return [
64
+ '',
65
+ ''
66
+ ];
67
+ const customIdReg = /\\?{#.*}/;
68
+ const text = title.replace(customIdReg, '').trimEnd();
69
+ const customId = title.match(customIdReg)?.[0]?.slice(2, -1) || '';
70
+ return [
71
+ text,
72
+ customId
73
+ ];
74
+ };
75
+ const getNodeAttribute = (node, attrName)=>node.attributes.find((attr)=>'name' in attr && attr.name === attrName)?.value;
60
76
  const external_node_path_namespaceObject = require("node:path");
61
77
  var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
62
78
  const external_gray_matter_namespaceObject = require("gray-matter");
@@ -1,6 +1,20 @@
1
1
  import * as __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__ from "node:path";
2
2
  import * as __WEBPACK_EXTERNAL_MODULE_gray_matter_90c6cd0b__ from "gray-matter";
3
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
+ const getNodeAttribute = (node, attrName)=>node.attributes.find((attr)=>'name' in attr && attr.name === attrName)?.value;
4
18
  function loadFrontMatter(source, filepath, root, outputWarning = false) {
5
19
  try {
6
20
  const { content, data } = (0, __WEBPACK_EXTERNAL_MODULE_gray_matter_90c6cd0b__["default"])(source);
@@ -33,4 +47,4 @@ const mergeDocConfig = async (...configs)=>{
33
47
  ];
34
48
  });
35
49
  };
36
- export { loadFrontMatter, mergeDocConfig };
50
+ export { extractTextAndId, getNodeAttribute, loadFrontMatter, mergeDocConfig };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspress/shared",
3
- "version": "1.41.3",
3
+ "version": "1.42.1-canary-20240226",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/web-infra-dev/rspress",
@@ -42,12 +42,13 @@
42
42
  "unified": "^10.1.2"
43
43
  },
44
44
  "devDependencies": {
45
- "@rslib/core": "0.4.1",
45
+ "@rslib/core": "0.5.2",
46
46
  "@types/fs-extra": "11.0.4",
47
47
  "@types/jest": "~29.5.14",
48
48
  "@types/lodash-es": "^4.17.12",
49
49
  "@types/node": "^18.11.17",
50
50
  "@types/react": "^18.3.18",
51
+ "mdast-util-mdx-jsx": "^2.1.4",
51
52
  "medium-zoom": "1.1.0",
52
53
  "rimraf": "^3.0.2",
53
54
  "typescript": "^5.5.3"