@rspress-theme-anatole/core 0.0.1

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.
@@ -0,0 +1,86 @@
1
+ import { AdditionalPage } from '@rspress-theme-anatole/shared';
2
+ import { DefaultThemeConfig } from '@rspress-theme-anatole/shared';
3
+ import type { FrontMatterMeta } from '@rspress-theme-anatole/shared';
4
+ import type { PageIndexInfo } from '@rspress-theme-anatole/shared';
5
+ import type { RouteMeta } from '@rspress-theme-anatole/shared';
6
+ import type { Rspack as Rspack_2 } from '@rsbuild/core';
7
+ import type { RspressPlugin } from '@rspress-theme-anatole/shared';
8
+ import type { UserConfig } from '@rspress-theme-anatole/shared';
9
+
10
+ export declare function createCheckPageMetaUpdateFn(): (modulePath: string, pageMeta: PageMeta) => void;
11
+
12
+ declare interface LoaderOptions {
13
+ config: UserConfig;
14
+ docDirectory: string;
15
+ checkDeadLinks: boolean;
16
+ routeService: RouteService;
17
+ pluginDriver: PluginDriver;
18
+ }
19
+
20
+ declare function mdxLoader(this: Rspack_2.LoaderContext<LoaderOptions>, source: string): Promise<void>;
21
+ export default mdxLoader;
22
+
23
+ export declare interface PageMeta {
24
+ toc: TocItem[];
25
+ title: string;
26
+ headingTitle: string;
27
+ frontmatter?: FrontMatterMeta;
28
+ }
29
+
30
+ declare class PluginDriver {
31
+ #private;
32
+ constructor(config: UserConfig, isProd: boolean);
33
+ init(): Promise<void>;
34
+ addPlugin(plugin: RspressPlugin): void;
35
+ getPlugins(): RspressPlugin[];
36
+ clearPlugins(): void;
37
+ removePlugin(pluginName: string): void;
38
+ modifyConfig(): Promise<UserConfig<DefaultThemeConfig>>;
39
+ beforeBuild(): Promise<void[]>;
40
+ afterBuild(): Promise<void[]>;
41
+ modifySearchIndexData(pages: PageIndexInfo[]): Promise<void[]>;
42
+ extendPageData(pageData: PageIndexInfo): Promise<void[]>;
43
+ addPages(): Promise<AdditionalPage[]>;
44
+ routeGenerated(routes: RouteMeta[]): Promise<void[]>;
45
+ addRuntimeModules(): Promise<Record<string, string>>;
46
+ addSSGRoutes(): Promise<({
47
+ path: string;
48
+ } | {
49
+ path: string;
50
+ })[]>;
51
+ globalUIComponents(): (string | [string, object])[];
52
+ globalStyles(): string[];
53
+ _runParallelAsyncHook<H extends RspressPluginHookKeys>(hookName: H, ...args: Parameters<Required<RspressPlugin>[H]>): Promise<Awaited<ReturnType<Required<RspressPlugin>[H]>>[]>;
54
+ _runSerialAsyncHook<H extends RspressPluginHookKeys>(hookName: H, ...args: Parameters<Required<RspressPlugin>[H]>): RspressPlugin;
55
+ }
56
+
57
+ declare class RouteService {
58
+ #private;
59
+ routeData: Map<string, RouteMeta>;
60
+ constructor(scanDir: string, userConfig: UserConfig, tempDir: string, pluginDriver: PluginDriver);
61
+ init(): Promise<void>;
62
+ addRoute(routeInfo: RouteMeta): void;
63
+ removeRoute(filePath: string): void;
64
+ getRoutes(): RouteMeta[];
65
+ isExistRoute(routePath: string): boolean;
66
+ isEmpty(): boolean;
67
+ generateRoutesCode(isStaticImport?: boolean): string;
68
+ generateRoutesCodeByRouteMeta(routeMeta: RouteMeta[], isStaticImport: boolean): string;
69
+ normalizeRoutePath(routePath: string): {
70
+ routePath: string;
71
+ lang: string;
72
+ version: string;
73
+ };
74
+ }
75
+
76
+ declare type RspressPluginHookKeys = 'beforeBuild' | 'afterBuild' | 'addPages' | 'addRuntimeModules' | 'routeGenerated' | 'addSSGRoutes' | 'extendPageData' | 'modifySearchIndexData';
77
+
78
+ declare interface TocItem {
79
+ id: string;
80
+ text: string;
81
+ depth: number;
82
+ }
83
+
84
+ export declare function updateSiteDataRuntimeModule(modulePath: string, pageMeta: PageMeta): Promise<void>;
85
+
86
+ export { }
package/dist/loader.js ADDED
@@ -0,0 +1,582 @@
1
+ import __rslib_shim_module__ from 'module';
2
+ /*#__PURE__*/ import.meta.url;
3
+ import * as __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__ from "node:fs/promises";
4
+ import * as __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__ from "node:path";
5
+ import * as __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__ from "node:url";
6
+ import * as __WEBPACK_EXTERNAL_MODULE__mdx_js_mdx_b904bd09__ from "@mdx-js/mdx";
7
+ import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__ from "@rspress-theme-anatole/shared";
8
+ import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__ from "@rspress-theme-anatole/shared/logger";
9
+ import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__ from "@rspress-theme-anatole/shared/node-utils";
10
+ import "rspack-plugin-virtual-module";
11
+ import * as __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__ from "node:fs";
12
+ import * as __WEBPACK_EXTERNAL_MODULE_enhanced_resolve_bf4706da__ from "enhanced-resolve";
13
+ import * as __WEBPACK_EXTERNAL_MODULE_node_os_74b4b876__ from "node:os";
14
+ import * as __WEBPACK_EXTERNAL_MODULE_rehype_external_links_09bed11a__ from "rehype-external-links";
15
+ import * as __WEBPACK_EXTERNAL_MODULE_remark_gfm_073acf21__ from "remark-gfm";
16
+ import * as __WEBPACK_EXTERNAL_MODULE_unist_util_visit_555e002a__ from "unist-util-visit";
17
+ import * as __WEBPACK_EXTERNAL_MODULE_github_slugger_8e9a17cb__ from "github-slugger";
18
+ import * as __WEBPACK_EXTERNAL_MODULE_hast_util_heading_rank_cff646ba__ from "hast-util-heading-rank";
19
+ import * as __WEBPACK_EXTERNAL_MODULE_unist_util_visit_children_71921007__ from "unist-util-visit-children";
20
+ const importStatementRegex = /import\s+(.*?)\s+from\s+(['"])(.*?)(?:"|');?/gm;
21
+ `{
22
+ const saved = localStorage.getItem('${__WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.APPEARANCE_KEY}')
23
+ const preferDark = window.matchMedia('(prefers-color-scheme: dark)').matches
24
+ const isDark = !saved || saved === 'auto' ? preferDark : saved === 'dark'
25
+ document.documentElement.classList.toggle('dark', isDark)
26
+ document.documentElement.style.colorScheme = isDark ? 'dark' : 'light'
27
+ }`.replace(/\n/g, ';').replace(/\s{2,}/g, '');
28
+ const dirname = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].dirname((0, __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__.fileURLToPath)(new URL(import.meta.url)));
29
+ const PACKAGE_ROOT = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(dirname, '..');
30
+ __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(PACKAGE_ROOT, 'dist', 'runtime', 'clientEntry.js');
31
+ __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(PACKAGE_ROOT, 'dist', 'runtime', 'ssrEntry.js');
32
+ const TEMP_DIR = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(process.cwd(), 'node_modules', __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.RSPRESS_TEMP_DIR);
33
+ var runtimeModule_RuntimeModuleID = /*#__PURE__*/ function(RuntimeModuleID) {
34
+ RuntimeModuleID["GlobalStyles"] = "virtual-global-styles";
35
+ RuntimeModuleID["GlobalComponents"] = "virtual-global-components";
36
+ RuntimeModuleID["RouteForClient"] = "virtual-routes";
37
+ RuntimeModuleID["RouteForSSR"] = "virtual-routes-ssr";
38
+ RuntimeModuleID["SiteData"] = "virtual-site-data";
39
+ RuntimeModuleID["SearchIndexHash"] = "virtual-search-index-hash";
40
+ RuntimeModuleID["I18nText"] = "virtual-i18n-text";
41
+ RuntimeModuleID["SearchHooks"] = "virtual-search-hooks";
42
+ RuntimeModuleID["PrismLanguages"] = "virtual-prism-languages";
43
+ return RuntimeModuleID;
44
+ }({});
45
+ let resolver;
46
+ let startFlatten = false;
47
+ const processor = (0, __WEBPACK_EXTERNAL_MODULE__mdx_js_mdx_b904bd09__.createProcessor)();
48
+ const { CachedInputFileSystem, ResolverFactory } = __WEBPACK_EXTERNAL_MODULE_enhanced_resolve_bf4706da__["default"];
49
+ const fileSystem = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"];
50
+ async function resolveDepPath(importPath, importer, alias) {
51
+ if (!resolver) resolver = ResolverFactory.createResolver({
52
+ fileSystem: new CachedInputFileSystem(fileSystem, 0),
53
+ extensions: [
54
+ '.mdx',
55
+ '.md'
56
+ ],
57
+ alias
58
+ });
59
+ const resolveResult = await new Promise((resolve, reject)=>{
60
+ resolver.resolve({
61
+ importer
62
+ }, importer, importPath, {}, (err, filePath)=>{
63
+ if (err) return reject(err);
64
+ if (!filePath) return reject(new Error(`Empty result when resolving ${importPath} from ${importer}`));
65
+ return resolve(filePath);
66
+ });
67
+ });
68
+ return resolveResult;
69
+ }
70
+ async function flattenMdxContent(content, basePath, alias) {
71
+ const deps = [];
72
+ const regex = new RegExp(importStatementRegex);
73
+ if (!regex.test(content)) return {
74
+ flattenContent: content,
75
+ deps
76
+ };
77
+ if (!startFlatten) {
78
+ resolver = ResolverFactory.createResolver({
79
+ fileSystem: new CachedInputFileSystem(fileSystem, 0),
80
+ extensions: [
81
+ '.mdx',
82
+ '.md',
83
+ '.js'
84
+ ],
85
+ alias
86
+ });
87
+ startFlatten = true;
88
+ }
89
+ let ast;
90
+ let result = content;
91
+ try {
92
+ ast = processor.parse(content);
93
+ } catch (e) {
94
+ __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.debug('flattenMdxContent parse failed: \n', e);
95
+ return {
96
+ flattenContent: content,
97
+ deps
98
+ };
99
+ }
100
+ const importNodes = ast.children.filter((node)=>'mdxjsEsm' === node.type).flatMap((node)=>{
101
+ var _node_data_estree, _node_data;
102
+ return (null === (_node_data = node.data) || void 0 === _node_data ? void 0 : null === (_node_data_estree = _node_data.estree) || void 0 === _node_data_estree ? void 0 : _node_data_estree.body) || [];
103
+ }).filter((node)=>'ImportDeclaration' === node.type);
104
+ for (const importNode of importNodes){
105
+ const id = importNode.specifiers[0].local.name;
106
+ const importPath = importNode.source.value;
107
+ let absoluteImportPath;
108
+ try {
109
+ absoluteImportPath = await resolveDepPath(importPath, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].dirname(basePath), alias);
110
+ } catch (_e) {
111
+ continue;
112
+ }
113
+ if (__WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.MDX_OR_MD_REGEXP.test(absoluteImportPath)) {
114
+ const importedContent = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].readFileSync(absoluteImportPath, 'utf-8');
115
+ const { flattenContent: replacedValue, deps: subDeps } = await flattenMdxContent(importedContent, absoluteImportPath, alias);
116
+ result = result.replace(new RegExp(`import\\s+${id}\\s+from\\s+['"](${importPath})['"];?`), '').replace(new RegExp(`<${id}\\s*/>`, 'g'), ()=>replacedValue);
117
+ deps.push(...subDeps, absoluteImportPath);
118
+ }
119
+ }
120
+ return {
121
+ flattenContent: result,
122
+ deps
123
+ };
124
+ }
125
+ function applyReplaceRules(code = '', replaceRules = []) {
126
+ let result = code;
127
+ for (const rule of replaceRules)result = result.replace(rule.search, rule.replace);
128
+ return result;
129
+ }
130
+ function escapeMarkdownHeadingIds(content) {
131
+ const markdownHeadingRegexp = /(?:^|\n)#{1,6}(?!#).*/g;
132
+ return content.replace(markdownHeadingRegexp, (substring)=>substring.replace('{#', '\\{#').replace('\\\\{#', '\\{#'));
133
+ }
134
+ const isWindows = 'win32' === __WEBPACK_EXTERNAL_MODULE_node_os_74b4b876__["default"].platform();
135
+ function slash(p) {
136
+ return p.replace(/\\/g, '/');
137
+ }
138
+ function normalizePath(id) {
139
+ return __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].posix.normalize(isWindows ? slash(id) : id);
140
+ }
141
+ const rehypePluginCodeMeta = ()=>(tree)=>{
142
+ (0, __WEBPACK_EXTERNAL_MODULE_unist_util_visit_555e002a__.visit)(tree, 'element', (node)=>{
143
+ var _node_children_;
144
+ if ('pre' === node.tagName && (null === (_node_children_ = node.children[0]) || void 0 === _node_children_ ? void 0 : _node_children_.type) === 'element' && 'code' === node.children[0].tagName) {
145
+ var _codeNode_data;
146
+ const codeNode = node.children[0];
147
+ codeNode.properties ??= {};
148
+ codeNode.properties.meta = null === (_codeNode_data = codeNode.data) || void 0 === _codeNode_data ? void 0 : _codeNode_data.meta;
149
+ }
150
+ });
151
+ };
152
+ const rehypeHeaderAnchor = ()=>{
153
+ const slugger = new __WEBPACK_EXTERNAL_MODULE_github_slugger_8e9a17cb__["default"]();
154
+ return (tree)=>{
155
+ (0, __WEBPACK_EXTERNAL_MODULE_unist_util_visit_555e002a__.visit)(tree, 'element', (node)=>{
156
+ var _node_properties;
157
+ if (!(0, __WEBPACK_EXTERNAL_MODULE_hast_util_heading_rank_cff646ba__.headingRank)(node)) return;
158
+ if (!(null === (_node_properties = node.properties) || void 0 === _node_properties ? void 0 : _node_properties.id)) {
159
+ const [text, customId] = collectHeaderText(node);
160
+ node.properties ??= {};
161
+ node.properties.id = customId || slugger.slug(text);
162
+ }
163
+ node.children.unshift(create(node));
164
+ });
165
+ };
166
+ };
167
+ const collectHeaderText = (node)=>{
168
+ let text = '';
169
+ let id = '';
170
+ node.children.forEach((child)=>{
171
+ if ('text' === child.type) {
172
+ const [textPart, idPart] = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__.extractTextAndId)(child.value);
173
+ child.value = textPart;
174
+ text += textPart;
175
+ id = idPart;
176
+ }
177
+ if ('element' === child.type) child.children.forEach((c)=>{
178
+ if ('text' === c.type) text += c.value;
179
+ });
180
+ });
181
+ return [
182
+ text,
183
+ id
184
+ ];
185
+ };
186
+ function create(node) {
187
+ return {
188
+ type: 'element',
189
+ tagName: 'a',
190
+ properties: {
191
+ class: 'header-anchor',
192
+ ariaHidden: 'true',
193
+ href: `#${node.properties.id}`
194
+ },
195
+ children: [
196
+ {
197
+ type: 'text',
198
+ value: '#'
199
+ }
200
+ ]
201
+ };
202
+ }
203
+ const getASTNodeImport = (name, from)=>({
204
+ type: 'mdxjsEsm',
205
+ value: `import ${name} from ${JSON.stringify(from)}`,
206
+ data: {
207
+ estree: {
208
+ type: 'Program',
209
+ sourceType: 'module',
210
+ body: [
211
+ {
212
+ type: 'ImportDeclaration',
213
+ specifiers: [
214
+ {
215
+ type: 'ImportDefaultSpecifier',
216
+ local: {
217
+ type: 'Identifier',
218
+ name
219
+ }
220
+ }
221
+ ],
222
+ source: {
223
+ type: 'Literal',
224
+ value: from,
225
+ raw: `${JSON.stringify(from)}`
226
+ }
227
+ }
228
+ ]
229
+ }
230
+ }
231
+ });
232
+ const remarkBuiltin = ({ globalComponents })=>(tree)=>{
233
+ const demos = globalComponents.map((componentPath)=>{
234
+ const filename = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].parse(componentPath).name;
235
+ const componentName = filename[0].toUpperCase() + filename.slice(1);
236
+ return getASTNodeImport(componentName, componentPath);
237
+ });
238
+ tree.children.unshift(...demos);
239
+ };
240
+ const IGNORE_REGEXP = /^(https?|mailto|tel|#)/;
241
+ function checkLinks(links, filepath, root, routeService) {
242
+ const errorInfos = [];
243
+ links.filter((link)=>!IGNORE_REGEXP.test(link)).map((link)=>normalizePath(link)).forEach((link)=>{
244
+ const relativePath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].relative(root, filepath);
245
+ if (!routeService.isExistRoute((0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.cleanUrl)(link))) errorInfos.push(`Internal link to "${link}" is dead, check it in "${relativePath}"`);
246
+ });
247
+ if (errorInfos.length > 0) {
248
+ null == errorInfos || errorInfos.forEach((err)=>{
249
+ __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error(err);
250
+ });
251
+ if ((0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.isProduction)()) throw new Error('Dead link found');
252
+ }
253
+ }
254
+ const remarkCheckDeadLinks = (checkLink)=>{
255
+ const { root, routeService } = checkLink;
256
+ return (tree, vfile)=>{
257
+ const internalLinks = new Set();
258
+ (0, __WEBPACK_EXTERNAL_MODULE_unist_util_visit_555e002a__.visit)(tree, 'link', ({ url })=>{
259
+ if (!url) return;
260
+ if (internalLinks.has(url)) return;
261
+ if (!url.startsWith('http') && !url.startsWith('https')) {
262
+ var _url_split_join;
263
+ const { routePath: normalizeUrl } = routeService.normalizeRoutePath(null === (_url_split_join = url.split(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].sep).join('/')) || void 0 === _url_split_join ? void 0 : _url_split_join.split('#')[0]);
264
+ internalLinks.add(normalizeUrl);
265
+ }
266
+ });
267
+ checkLinks(Array.from(internalLinks), vfile.path, root, routeService);
268
+ };
269
+ };
270
+ const remarkPluginNormalizeLink = ({ root, cleanUrls })=>(tree, file)=>{
271
+ const images = [];
272
+ (0, __WEBPACK_EXTERNAL_MODULE_unist_util_visit_555e002a__.visit)(tree, 'link', (node)=>{
273
+ if (!node.url) return;
274
+ if (node.url.startsWith('#')) {
275
+ node.url = `#${node.url.slice(1)}`;
276
+ return;
277
+ }
278
+ let { url, hash } = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.parseUrl)(node.url);
279
+ if ((0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.isExternalUrl)(url)) {
280
+ node.url = url + (hash ? `#${hash}` : '');
281
+ return;
282
+ }
283
+ const extname = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].extname(url);
284
+ if ('.md' === extname || '.mdx' === extname) url = url.replace(extname, '');
285
+ const relativePath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].relative(root, file.path);
286
+ if (url.startsWith('.')) url = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].posix.join((0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.slash)(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].dirname(relativePath)), url);
287
+ url = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.normalizeHref)(url, cleanUrls);
288
+ if (hash) url += `#${hash}`;
289
+ node.url = url;
290
+ });
291
+ const normalizeImageUrl = (imageUrl)=>{
292
+ if ((0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.isExternalUrl)(imageUrl) || imageUrl.startsWith('/')) return '';
293
+ return imageUrl;
294
+ };
295
+ const getMdxSrcAttribute = (tempVar)=>({
296
+ type: 'mdxJsxAttribute',
297
+ name: 'src',
298
+ value: {
299
+ type: 'mdxJsxAttributeValueExpression',
300
+ value: tempVar,
301
+ data: {
302
+ estree: {
303
+ type: 'Program',
304
+ sourceType: 'module',
305
+ body: [
306
+ {
307
+ type: 'ExpressionStatement',
308
+ expression: {
309
+ type: 'Identifier',
310
+ name: tempVar
311
+ }
312
+ }
313
+ ]
314
+ }
315
+ }
316
+ }
317
+ });
318
+ (0, __WEBPACK_EXTERNAL_MODULE_unist_util_visit_555e002a__.visit)(tree, 'image', (node)=>{
319
+ const { alt, url } = node;
320
+ if (!url) return;
321
+ const imagePath = normalizeImageUrl(url);
322
+ if (!imagePath) return;
323
+ const tempVariableName = `image${images.length}`;
324
+ Object.assign(node, {
325
+ type: 'mdxJsxFlowElement',
326
+ name: 'img',
327
+ children: [],
328
+ attributes: [
329
+ alt && {
330
+ type: 'mdxJsxAttribute',
331
+ name: 'alt',
332
+ value: alt
333
+ },
334
+ getMdxSrcAttribute(tempVariableName)
335
+ ].filter(Boolean)
336
+ });
337
+ images.push(getASTNodeImport(tempVariableName, imagePath));
338
+ });
339
+ (0, __WEBPACK_EXTERNAL_MODULE_unist_util_visit_555e002a__.visit)(tree, (node)=>{
340
+ if ('mdxJsxFlowElement' !== node.type && 'mdxJsxTextElement' !== node.type || 'img' !== node.name) return;
341
+ const srcAttr = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__.getNodeAttribute)(node, 'src', true);
342
+ if ('string' != typeof (null == srcAttr ? void 0 : srcAttr.value)) return;
343
+ const imagePath = normalizeImageUrl(srcAttr.value);
344
+ if (!imagePath) return;
345
+ const tempVariableName = `image${images.length}`;
346
+ Object.assign(srcAttr, getMdxSrcAttribute(tempVariableName));
347
+ images.push(getASTNodeImport(tempVariableName, imagePath));
348
+ });
349
+ tree.children.unshift(...images);
350
+ };
351
+ const parseToc = (tree)=>{
352
+ let title = '';
353
+ const toc = [];
354
+ const slugger = new __WEBPACK_EXTERNAL_MODULE_github_slugger_8e9a17cb__["default"]();
355
+ (0, __WEBPACK_EXTERNAL_MODULE_unist_util_visit_children_71921007__.visitChildren)((node)=>{
356
+ if ('heading' !== node.type || !node.depth || !node.children) return;
357
+ if (node.depth >= 1 && node.depth < 5) {
358
+ let customId = '';
359
+ const text = node.children.map((child)=>{
360
+ if ('link' === child.type) {
361
+ var _child_children;
362
+ return null === (_child_children = child.children) || void 0 === _child_children ? void 0 : _child_children.map((item)=>item.value).join('');
363
+ }
364
+ if ('strong' === child.type) {
365
+ var _child_children1;
366
+ return `**${null === (_child_children1 = child.children) || void 0 === _child_children1 ? void 0 : _child_children1.map((item)=>item.value).join('')}**`;
367
+ }
368
+ if ('emphasis' === child.type) {
369
+ var _child_children2;
370
+ return `*${null === (_child_children2 = child.children) || void 0 === _child_children2 ? void 0 : _child_children2.map((item)=>item.value).join('')}*`;
371
+ }
372
+ if ('delete' === child.type) {
373
+ var _child_children3;
374
+ return `~~${null === (_child_children3 = child.children) || void 0 === _child_children3 ? void 0 : _child_children3.map((item)=>item.value).join('')}~~`;
375
+ }
376
+ if ('text' === child.type) {
377
+ const [textPart, idPart] = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__.extractTextAndId)(child.value);
378
+ customId = idPart;
379
+ return textPart;
380
+ }
381
+ if ('inlineCode' === child.type) return `\`${child.value}\``;
382
+ return '';
383
+ }).join('');
384
+ if (1 === node.depth) {
385
+ if (!title) title = text;
386
+ } else {
387
+ const id = customId ? customId : slugger.slug(text);
388
+ const { depth } = node;
389
+ toc.push({
390
+ id,
391
+ text,
392
+ depth
393
+ });
394
+ }
395
+ }
396
+ })(tree);
397
+ return {
398
+ title,
399
+ toc
400
+ };
401
+ };
402
+ const remarkPluginToc = function() {
403
+ const data = this.data();
404
+ return (tree)=>{
405
+ const { toc, title } = parseToc(tree);
406
+ data.pageMeta.toc = toc;
407
+ if (title) data.pageMeta.title = title;
408
+ };
409
+ };
410
+ async function createMDXOptions(docDirectory, config, checkDeadLinks, routeService, filepath, pluginDriver) {
411
+ var _config_route;
412
+ const cleanUrls = (null == config ? void 0 : null === (_config_route = config.route) || void 0 === _config_route ? void 0 : _config_route.cleanUrls) ?? false;
413
+ const { remarkPlugins: remarkPluginsFromConfig = [], rehypePlugins: rehypePluginsFromConfig = [], globalComponents: globalComponentsFromConfig = [] } = (null == config ? void 0 : config.markdown) || {};
414
+ const rspressPlugins = pluginDriver.getPlugins();
415
+ const remarkPluginsFromPlugins = rspressPlugins.flatMap((plugin)=>{
416
+ var _plugin_markdown;
417
+ return (null === (_plugin_markdown = plugin.markdown) || void 0 === _plugin_markdown ? void 0 : _plugin_markdown.remarkPlugins) || [];
418
+ });
419
+ const rehypePluginsFromPlugins = rspressPlugins.flatMap((plugin)=>{
420
+ var _plugin_markdown;
421
+ return (null === (_plugin_markdown = plugin.markdown) || void 0 === _plugin_markdown ? void 0 : _plugin_markdown.rehypePlugins) || [];
422
+ });
423
+ const globalComponents = [
424
+ ...rspressPlugins.flatMap((plugin)=>{
425
+ var _plugin_markdown;
426
+ return (null === (_plugin_markdown = plugin.markdown) || void 0 === _plugin_markdown ? void 0 : _plugin_markdown.globalComponents) || [];
427
+ }),
428
+ ...globalComponentsFromConfig
429
+ ];
430
+ return {
431
+ providerImportSource: '@mdx-js/react',
432
+ format: __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].extname(filepath).slice(1),
433
+ remarkPlugins: [
434
+ __WEBPACK_EXTERNAL_MODULE_remark_gfm_073acf21__["default"],
435
+ remarkPluginToc,
436
+ [
437
+ remarkPluginNormalizeLink,
438
+ {
439
+ cleanUrls,
440
+ root: docDirectory
441
+ }
442
+ ],
443
+ checkDeadLinks && [
444
+ remarkCheckDeadLinks,
445
+ {
446
+ root: docDirectory,
447
+ base: (null == config ? void 0 : config.base) || '',
448
+ routeService
449
+ }
450
+ ],
451
+ globalComponents.length && [
452
+ remarkBuiltin,
453
+ {
454
+ globalComponents
455
+ }
456
+ ],
457
+ ...remarkPluginsFromConfig,
458
+ ...remarkPluginsFromPlugins
459
+ ].filter(Boolean),
460
+ rehypePlugins: [
461
+ rehypeHeaderAnchor,
462
+ rehypePluginCodeMeta,
463
+ [
464
+ __WEBPACK_EXTERNAL_MODULE_rehype_external_links_09bed11a__["default"],
465
+ {
466
+ target: '_blank',
467
+ rel: 'noopener noreferrer'
468
+ }
469
+ ],
470
+ ...rehypePluginsFromConfig,
471
+ ...rehypePluginsFromPlugins
472
+ ]
473
+ };
474
+ }
475
+ async function updateSiteDataRuntimeModule(modulePath, pageMeta) {
476
+ const siteDataModulePath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(TEMP_DIR, 'runtime', `${runtimeModule_RuntimeModuleID.SiteData}.mjs`);
477
+ const { default: siteData } = await import((0, __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__.pathToFileURL)(siteDataModulePath).href);
478
+ await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].writeFile(siteDataModulePath, `export default ${JSON.stringify({
479
+ ...siteData,
480
+ timestamp: Date.now().toString(),
481
+ pages: siteData.pages.map((page)=>page._filepath === modulePath ? {
482
+ ...page,
483
+ ...pageMeta
484
+ } : page)
485
+ }, null, 2)}`);
486
+ }
487
+ function createCheckPageMetaUpdateFn() {
488
+ const pageMetaMap = new Map();
489
+ return (modulePath, pageMeta)=>{
490
+ const prevMeta = pageMetaMap.get(modulePath);
491
+ const deserializedMeta = JSON.stringify(pageMeta);
492
+ pageMetaMap.set(modulePath, deserializedMeta);
493
+ if (!prevMeta) return;
494
+ if (prevMeta !== deserializedMeta) setTimeout(async ()=>{
495
+ __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.info('Page metadata changed, page reloading...');
496
+ await updateSiteDataRuntimeModule(modulePath, pageMeta);
497
+ });
498
+ };
499
+ }
500
+ const checkPageMetaUpdate = createCheckPageMetaUpdateFn();
501
+ async function mdxLoader(source) {
502
+ var _config_markdown;
503
+ this.cacheable(true);
504
+ const callback = this.async();
505
+ const options = this.getOptions();
506
+ const filepath = this.resourcePath;
507
+ const { alias } = this._compiler.options.resolve;
508
+ const { config, docDirectory, checkDeadLinks, routeService, pluginDriver } = options;
509
+ const { frontmatter, content } = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__.loadFrontMatter)(source, filepath, docDirectory, true);
510
+ const { flattenContent, deps } = await flattenMdxContent(content, filepath, alias);
511
+ deps.forEach((dep)=>this.addDependency(dep));
512
+ const replacedContent = applyReplaceRules(flattenContent, config.replaceRules);
513
+ const preprocessedContent = escapeMarkdownHeadingIds(replacedContent);
514
+ let enableMdxRs;
515
+ const mdxRs = (null == config ? void 0 : null === (_config_markdown = config.markdown) || void 0 === _config_markdown ? void 0 : _config_markdown.mdxRs) ?? true;
516
+ enableMdxRs = 'object' == typeof mdxRs ? 'function' == typeof (null == mdxRs ? void 0 : mdxRs.include) ? mdxRs.include(filepath) : true : mdxRs;
517
+ try {
518
+ let compileResult;
519
+ let pageMeta = {
520
+ title: '',
521
+ toc: [],
522
+ headingTitle: ''
523
+ };
524
+ const frontmatterTitle = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__.extractTextAndId)(frontmatter.title)[0];
525
+ if (enableMdxRs) {
526
+ const { compile } = await import("@rspress/mdx-rs");
527
+ const { toc, links, title, code } = await compile({
528
+ value: preprocessedContent,
529
+ filepath,
530
+ root: docDirectory,
531
+ development: 'production' !== process.env.NODE_ENV
532
+ });
533
+ compileResult = code;
534
+ const headingTitle = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__.extractTextAndId)(title)[0];
535
+ pageMeta = {
536
+ toc,
537
+ title: frontmatterTitle || headingTitle,
538
+ headingTitle,
539
+ frontmatter
540
+ };
541
+ if (checkDeadLinks) checkLinks(links, filepath, docDirectory, routeService);
542
+ } else {
543
+ const mdxOptions = await createMDXOptions(docDirectory, config, checkDeadLinks, routeService, filepath, pluginDriver);
544
+ const compiler = (0, __WEBPACK_EXTERNAL_MODULE__mdx_js_mdx_b904bd09__.createProcessor)(mdxOptions);
545
+ compiler.data('pageMeta', {
546
+ toc: [],
547
+ title: ''
548
+ });
549
+ const vFile = await compiler.process({
550
+ value: preprocessedContent,
551
+ path: filepath
552
+ });
553
+ compileResult = String(vFile);
554
+ const compilationMeta = compiler.data('pageMeta');
555
+ const headingTitle = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__.extractTextAndId)(compilationMeta.title)[0];
556
+ pageMeta = {
557
+ ...compilationMeta,
558
+ title: frontmatterTitle || headingTitle,
559
+ headingTitle,
560
+ frontmatter
561
+ };
562
+ }
563
+ if (!(0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.isProduction)()) checkPageMetaUpdate(filepath, pageMeta);
564
+ const result = `const frontmatter = ${JSON.stringify(frontmatter)};
565
+ ${compileResult}
566
+ MDXContent.__RSPRESS_PAGE_META = {};
567
+
568
+ MDXContent.__RSPRESS_PAGE_META["${encodeURIComponent(normalizePath(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].relative(docDirectory, filepath)))}"] = ${JSON.stringify(pageMeta)};
569
+ `;
570
+ callback(null, result);
571
+ } catch (e) {
572
+ if (e instanceof Error) {
573
+ __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error(`MDX compile error: ${e.message} in ${filepath}`);
574
+ __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.debug(e);
575
+ callback({
576
+ message: e.message,
577
+ name: `${filepath} compile error`
578
+ });
579
+ }
580
+ }
581
+ }
582
+ export { createCheckPageMetaUpdateFn, mdxLoader as default, updateSiteDataRuntimeModule };
@@ -0,0 +1,10 @@
1
+ import { type PageData } from '@rspress-theme-anatole/shared';
2
+ import 'virtual-global-styles';
3
+ export declare enum QueryStatus {
4
+ Show = "1",
5
+ Hide = "0"
6
+ }
7
+ export declare function initPageData(routePath: string): Promise<PageData>;
8
+ export declare function App({ helmetContext }: {
9
+ helmetContext?: object;
10
+ }): import("react/jsx-runtime").JSX.Element;