@rspress/shared 2.0.0-beta.1 → 2.0.0-beta.11

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,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
@@ -330,7 +331,7 @@ export declare type LocalSearchOptions = SearchHooks & {
330
331
  versioned?: boolean;
331
332
  /**
332
333
  * If enabled, the search index will include code block content, which allows users to search code blocks.
333
- * @default false
334
+ * @default true
334
335
  */
335
336
  codeBlocks?: boolean;
336
337
  };
@@ -352,13 +353,9 @@ export declare interface MarkdownOptions {
352
353
  */
353
354
  globalComponents?: string[];
354
355
  /**
355
- * Code highlighter, default is prism for performance reason
356
+ * @type import('@shikijs/rehype').RehypeShikiOptions
356
357
  */
357
- codeHighlighter?: 'prism' | 'shiki';
358
- /**
359
- * Register prism languages
360
- */
361
- highlightLanguages?: (string | [string, string])[];
358
+ shiki?: Partial<PluginShikiOptions>;
362
359
  }
363
360
 
364
361
  export declare const matchNavbar: (item: NavItemWithLink, currentPathname: string, base: string) => boolean;
@@ -476,6 +473,8 @@ export declare const parseUrl: (url: string) => {
476
473
  hash: string;
477
474
  };
478
475
 
476
+ declare type PluginShikiOptions = RehypeShikiOptions;
477
+
479
478
  export declare const QUERY_REGEXP: RegExp;
480
479
 
481
480
  export declare type RemotePageInfo = PageIndexInfo & {
@@ -724,7 +723,7 @@ export declare interface SiteData<ThemeConfig = NormalizedConfig> {
724
723
  markdown: {
725
724
  showLineNumbers: boolean;
726
725
  defaultWrapCode: boolean;
727
- codeHighlighter: 'prism' | 'shiki';
726
+ shiki: Partial<PluginShikiOptions>;
728
727
  };
729
728
  multiVersion: {
730
729
  default: string;
@@ -770,7 +769,7 @@ export declare interface UserConfig<ThemeConfig = DefaultThemeConfig> {
770
769
  /**
771
770
  * Path to html icon file.
772
771
  */
773
- icon?: string;
772
+ icon?: string | URL;
774
773
  /**
775
774
  * Default language of the site.
776
775
  */
@@ -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 {
@@ -292,7 +306,7 @@ declare type LocalSearchOptions = SearchHooks & {
292
306
  versioned?: boolean;
293
307
  /**
294
308
  * If enabled, the search index will include code block content, which allows users to search code blocks.
295
- * @default false
309
+ * @default true
296
310
  */
297
311
  codeBlocks?: boolean;
298
312
  };
@@ -314,13 +328,9 @@ declare interface MarkdownOptions {
314
328
  */
315
329
  globalComponents?: string[];
316
330
  /**
317
- * Code highlighter, default is prism for performance reason
331
+ * @type import('@shikijs/rehype').RehypeShikiOptions
318
332
  */
319
- codeHighlighter?: 'prism' | 'shiki';
320
- /**
321
- * Register prism languages
322
- */
323
- highlightLanguages?: (string | [string, string])[];
333
+ shiki?: Partial<PluginShikiOptions>;
324
334
  }
325
335
 
326
336
  export declare const mergeDocConfig: (...configs: UserConfig[]) => Promise<UserConfig>;
@@ -378,6 +388,8 @@ declare interface PageIndexInfo {
378
388
 
379
389
  declare type PageType = 'home' | 'doc' | 'custom' | '404' | 'blank';
380
390
 
391
+ declare type PluginShikiOptions = RehypeShikiOptions;
392
+
381
393
  declare type RemoteSearchIndexInfo = string | {
382
394
  value: string;
383
395
  label: string;
@@ -586,7 +598,7 @@ declare interface UserConfig<ThemeConfig = Config> {
586
598
  /**
587
599
  * Path to html icon file.
588
600
  */
589
- icon?: string;
601
+ icon?: string | URL;
590
602
  /**
591
603
  * Default language of the site.
592
604
  */
@@ -1,4 +1,5 @@
1
1
  import * as __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__ from "node:path";
2
+ import * as __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__ from "node:url";
2
3
  import * as __WEBPACK_EXTERNAL_MODULE_gray_matter_90c6cd0b__ from "gray-matter";
3
4
  import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__ from "@rsbuild/core";
4
5
  const extractTextAndId = (title)=>{
@@ -14,6 +15,13 @@ const extractTextAndId = (title)=>{
14
15
  customId
15
16
  ];
16
17
  };
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)}`;
24
+ }
17
25
  function getNodeAttribute(node, attrName, attribute) {
18
26
  const found = node.attributes.find((attr)=>'name' in attr && attr.name === attrName);
19
27
  return attribute ? found : found?.value;
@@ -21,16 +29,20 @@ function getNodeAttribute(node, attrName, attribute) {
21
29
  function loadFrontMatter(source, filepath, root, outputWarning = false) {
22
30
  try {
23
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;
24
34
  return {
25
35
  content,
26
- frontmatter: data
36
+ frontmatter: data,
37
+ emptyLinesSource
27
38
  };
28
39
  } catch (e) {
29
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);
30
41
  }
31
42
  return {
32
43
  content: '',
33
- frontmatter: {}
44
+ frontmatter: {},
45
+ emptyLinesSource: source
34
46
  };
35
47
  }
36
48
  const castArray = (value)=>Array.isArray(value) ? value : [
@@ -50,4 +62,4 @@ const mergeDocConfig = async (...configs)=>{
50
62
  ];
51
63
  });
52
64
  };
53
- export { extractTextAndId, getNodeAttribute, loadFrontMatter, mergeDocConfig };
65
+ export { extractTextAndId, getIconUrlPath, getNodeAttribute, loadFrontMatter, mergeDocConfig };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspress/shared",
3
- "version": "2.0.0-beta.1",
3
+ "version": "2.0.0-beta.11",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/web-infra-dev/rspress.git",
@@ -32,21 +32,22 @@
32
32
  "dist"
33
33
  ],
34
34
  "dependencies": {
35
- "@rsbuild/core": "1.3.9",
35
+ "@rsbuild/core": "~1.3.21",
36
+ "@shikijs/rehype": "^3.4.2",
36
37
  "gray-matter": "4.0.3",
37
38
  "lodash-es": "^4.17.21",
38
39
  "unified": "^11.0.5"
39
40
  },
40
41
  "devDependencies": {
41
- "@rslib/core": "0.6.5",
42
+ "@rslib/core": "0.8.0",
42
43
  "@types/jest": "~29.5.14",
43
44
  "@types/lodash-es": "^4.17.12",
44
- "@types/node": "^18.11.17",
45
- "@types/react": "^18.3.20",
45
+ "@types/node": "^22.8.1",
46
+ "@types/react": "^19.1.6",
46
47
  "mdast-util-mdx-jsx": "^3.2.0",
47
48
  "medium-zoom": "1.1.0",
48
49
  "rimraf": "^6.0.1",
49
- "rsbuild-plugin-publint": "^0.3.0",
50
+ "rsbuild-plugin-publint": "^0.3.2",
50
51
  "typescript": "^5.8.2"
51
52
  },
52
53
  "publishConfig": {