@rspress/shared 2.0.0-beta.5 → 2.0.0-beta.7

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
@@ -769,7 +769,7 @@ export declare interface UserConfig<ThemeConfig = DefaultThemeConfig> {
769
769
  /**
770
770
  * Path to html icon file.
771
771
  */
772
- icon?: string;
772
+ icon?: string | URL;
773
773
  /**
774
774
  * Default language of the site.
775
775
  */
@@ -208,6 +208,18 @@ declare interface FrontMatterMeta {
208
208
  [key: string]: unknown;
209
209
  }
210
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
+
211
223
  export declare function getNodeAttribute(node: MdxJsxFlowElement | MdxJsxTextElement, attrName: string, attribute?: false): string | MdxJsxAttributeValueExpression | null | undefined;
212
224
 
213
225
  export declare function getNodeAttribute(node: MdxJsxFlowElement | MdxJsxTextElement, attrName: string, attribute: true): MdxJsxAttribute | MdxJsxExpressionAttribute | undefined;
@@ -246,6 +258,7 @@ declare interface Hero {
246
258
  export declare function loadFrontMatter<TFrontmatter extends Record<string, unknown> = FrontMatterMeta>(source: string, filepath: string, root: string, outputWarning?: boolean): {
247
259
  frontmatter: TFrontmatter;
248
260
  content: string;
261
+ emptyLinesSource: string;
249
262
  };
250
263
 
251
264
  declare interface Locale {
@@ -585,7 +598,7 @@ declare interface UserConfig<ThemeConfig = Config> {
585
598
  /**
586
599
  * Path to html icon file.
587
600
  */
588
- icon?: string;
601
+ icon?: string | URL;
589
602
  /**
590
603
  * Default language of the site.
591
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.5",
3
+ "version": "2.0.0-beta.7",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/web-infra-dev/rspress.git",
@@ -32,22 +32,22 @@
32
32
  "dist"
33
33
  ],
34
34
  "dependencies": {
35
- "@rsbuild/core": "1.3.17",
36
- "@shikijs/rehype": "^3.2.2",
35
+ "@rsbuild/core": "~1.3.21",
36
+ "@shikijs/rehype": "^3.4.2",
37
37
  "gray-matter": "4.0.3",
38
38
  "lodash-es": "^4.17.21",
39
39
  "unified": "^11.0.5"
40
40
  },
41
41
  "devDependencies": {
42
- "@rslib/core": "0.6.8",
42
+ "@rslib/core": "0.8.0",
43
43
  "@types/jest": "~29.5.14",
44
44
  "@types/lodash-es": "^4.17.12",
45
- "@types/node": "^18.11.17",
46
- "@types/react": "^18.3.21",
45
+ "@types/node": "^22.8.1",
46
+ "@types/react": "^18.3.22",
47
47
  "mdast-util-mdx-jsx": "^3.2.0",
48
48
  "medium-zoom": "1.1.0",
49
49
  "rimraf": "^6.0.1",
50
- "rsbuild-plugin-publint": "^0.3.1",
50
+ "rsbuild-plugin-publint": "^0.3.2",
51
51
  "typescript": "^5.8.2"
52
52
  },
53
53
  "publishConfig": {