@rspress/shared 1.44.0 → 1.45.0
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 +1 -1
- package/dist/node-utils.d.ts +14 -1
- package/dist/node-utils.js +20 -5
- package/dist/node-utils.mjs +15 -3
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/node-utils.d.ts
CHANGED
@@ -207,6 +207,18 @@ declare interface FrontMatterMeta {
|
|
207
207
|
[key: string]: unknown;
|
208
208
|
}
|
209
209
|
|
210
|
+
/**
|
211
|
+
* Transform `config.icon` into final url path in the web app
|
212
|
+
*
|
213
|
+
* @param icon original icon in config
|
214
|
+
* @returns final url path in the web app
|
215
|
+
*/
|
216
|
+
export declare function getIconUrlPath(icon: '' | undefined): undefined;
|
217
|
+
|
218
|
+
export declare function getIconUrlPath(icon: string | URL): string;
|
219
|
+
|
220
|
+
export declare function getIconUrlPath(icon: string | URL | undefined): string | undefined;
|
221
|
+
|
210
222
|
export declare function getNodeAttribute(node: MdxJsxFlowElement | MdxJsxTextElement, attrName: string, attribute?: false): string | MdxJsxAttributeValueExpression | null | undefined;
|
211
223
|
|
212
224
|
export declare function getNodeAttribute(node: MdxJsxFlowElement | MdxJsxTextElement, attrName: string, attribute: true): MdxJsxAttribute | MdxJsxExpressionAttribute | undefined;
|
@@ -245,6 +257,7 @@ declare interface Hero {
|
|
245
257
|
export declare function loadFrontMatter<TFrontmatter extends Record<string, unknown> = FrontMatterMeta>(source: string, filepath: string, root: string, outputWarning?: boolean): {
|
246
258
|
frontmatter: TFrontmatter;
|
247
259
|
content: string;
|
260
|
+
emptyLinesSource: string;
|
248
261
|
};
|
249
262
|
|
250
263
|
declare interface Locale {
|
@@ -600,7 +613,7 @@ declare interface UserConfig<ThemeConfig = Config> {
|
|
600
613
|
/**
|
601
614
|
* Path to html icon file.
|
602
615
|
*/
|
603
|
-
icon?: string;
|
616
|
+
icon?: string | URL;
|
604
617
|
/**
|
605
618
|
* Default language of the site.
|
606
619
|
*/
|
package/dist/node-utils.js
CHANGED
@@ -53,7 +53,8 @@ var __webpack_exports__ = {};
|
|
53
53
|
extractTextAndId: ()=>extractTextAndId,
|
54
54
|
loadFrontMatter: ()=>loadFrontMatter,
|
55
55
|
mergeDocConfig: ()=>mergeDocConfig,
|
56
|
-
getNodeAttribute: ()=>getNodeAttribute
|
56
|
+
getNodeAttribute: ()=>getNodeAttribute,
|
57
|
+
getIconUrlPath: ()=>getIconUrlPath
|
57
58
|
});
|
58
59
|
const extractTextAndId = (title)=>{
|
59
60
|
if (!title) return [
|
@@ -68,28 +69,40 @@ var __webpack_exports__ = {};
|
|
68
69
|
customId
|
69
70
|
];
|
70
71
|
};
|
72
|
+
const external_node_path_namespaceObject = require("node:path");
|
73
|
+
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
74
|
+
const external_node_url_namespaceObject = require("node:url");
|
75
|
+
function getIconUrlPath(icon) {
|
76
|
+
if (!icon) return;
|
77
|
+
icon = icon.toString();
|
78
|
+
if (icon.startsWith('file://')) icon = (0, external_node_url_namespaceObject.fileURLToPath)(icon);
|
79
|
+
if (!external_node_path_default().isAbsolute(icon)) return icon;
|
80
|
+
return `/${external_node_path_default().basename(icon)}`;
|
81
|
+
}
|
71
82
|
function getNodeAttribute(node, attrName, attribute) {
|
72
83
|
const found = node.attributes.find((attr)=>'name' in attr && attr.name === attrName);
|
73
84
|
return attribute ? found : found?.value;
|
74
85
|
}
|
75
|
-
const external_node_path_namespaceObject = require("node:path");
|
76
|
-
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
77
86
|
const external_gray_matter_namespaceObject = require("gray-matter");
|
78
87
|
var external_gray_matter_default = /*#__PURE__*/ __webpack_require__.n(external_gray_matter_namespaceObject);
|
79
88
|
const core_namespaceObject = require("@rsbuild/core");
|
80
89
|
function loadFrontMatter(source, filepath, root, outputWarning = false) {
|
81
90
|
try {
|
82
91
|
const { content, data } = external_gray_matter_default()(source);
|
92
|
+
const rawFrontMatter = source.slice(0, source.length - content.length);
|
93
|
+
const emptyLinesSource = rawFrontMatter.length ? `${rawFrontMatter.replace(/[^\n]/g, '')}${content}` : content;
|
83
94
|
return {
|
84
95
|
content,
|
85
|
-
frontmatter: data
|
96
|
+
frontmatter: data,
|
97
|
+
emptyLinesSource
|
86
98
|
};
|
87
99
|
} catch (e) {
|
88
100
|
if (outputWarning) core_namespaceObject.logger.warn(`Parse frontmatter error in ${external_node_path_default().relative(root, filepath)}: \n`, e);
|
89
101
|
}
|
90
102
|
return {
|
91
103
|
content: '',
|
92
|
-
frontmatter: {}
|
104
|
+
frontmatter: {},
|
105
|
+
emptyLinesSource: source
|
93
106
|
};
|
94
107
|
}
|
95
108
|
const castArray = (value)=>Array.isArray(value) ? value : [
|
@@ -111,11 +124,13 @@ var __webpack_exports__ = {};
|
|
111
124
|
};
|
112
125
|
})();
|
113
126
|
exports.extractTextAndId = __webpack_exports__.extractTextAndId;
|
127
|
+
exports.getIconUrlPath = __webpack_exports__.getIconUrlPath;
|
114
128
|
exports.getNodeAttribute = __webpack_exports__.getNodeAttribute;
|
115
129
|
exports.loadFrontMatter = __webpack_exports__.loadFrontMatter;
|
116
130
|
exports.mergeDocConfig = __webpack_exports__.mergeDocConfig;
|
117
131
|
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
118
132
|
"extractTextAndId",
|
133
|
+
"getIconUrlPath",
|
119
134
|
"getNodeAttribute",
|
120
135
|
"loadFrontMatter",
|
121
136
|
"mergeDocConfig"
|
package/dist/node-utils.mjs
CHANGED
@@ -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 };
|