@rspress/core 2.0.0-alpha.9 → 2.0.0-beta.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.
package/dist/loader.d.ts CHANGED
@@ -42,6 +42,7 @@ declare class PluginDriver {
42
42
  extendPageData(pageData: PageIndexInfo): Promise<void[]>;
43
43
  addPages(): Promise<AdditionalPage[]>;
44
44
  routeGenerated(routes: RouteMeta[]): Promise<void[]>;
45
+ routeServiceGenerated(routeService: RouteService): Promise<void[]>;
45
46
  addRuntimeModules(): Promise<Record<string, string>>;
46
47
  addSSGRoutes(): Promise<({
47
48
  path: string;
@@ -75,7 +76,7 @@ declare class RouteService {
75
76
  };
76
77
  }
77
78
 
78
- declare type RspressPluginHookKeys = 'beforeBuild' | 'afterBuild' | 'addPages' | 'addRuntimeModules' | 'routeGenerated' | 'addSSGRoutes' | 'extendPageData' | 'modifySearchIndexData';
79
+ declare type RspressPluginHookKeys = 'beforeBuild' | 'afterBuild' | 'addPages' | 'addRuntimeModules' | 'routeGenerated' | 'routeServiceGenerated' | 'addSSGRoutes' | 'extendPageData' | 'modifySearchIndexData';
79
80
 
80
81
  declare interface TocItem {
81
82
  id: string;
package/dist/loader.js CHANGED
@@ -7,7 +7,6 @@ import * as __WEBPACK_EXTERNAL_MODULE__mdx_js_mdx_b904bd09__ from "@mdx-js/mdx";
7
7
  import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__ from "@rspress/shared";
8
8
  import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__ from "@rspress/shared/logger";
9
9
  import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__ from "@rspress/shared/node-utils";
10
- import "rspack-plugin-virtual-module";
11
10
  import * as __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__ from "node:fs";
12
11
  import * as __WEBPACK_EXTERNAL_MODULE_enhanced_resolve_bf4706da__ from "enhanced-resolve";
13
12
  import * as __WEBPACK_EXTERNAL_MODULE_node_os_74b4b876__ from "node:os";
@@ -29,10 +28,12 @@ const importStatementRegex = /import\s+(.*?)\s+from\s+(['"])(.*?)(?:"|');?/gm;
29
28
  }`.replace(/\n/g, ';').replace(/\s{2,}/g, '');
30
29
  const dirname = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].dirname((0, __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__.fileURLToPath)(new URL(import.meta.url)));
31
30
  const PACKAGE_ROOT = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(dirname, '..');
32
- __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(PACKAGE_ROOT, 'dist', 'runtime', 'clientEntry.js');
33
- __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(PACKAGE_ROOT, 'dist', 'runtime', 'ssrEntry.js');
31
+ __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(PACKAGE_ROOT, 'index.html');
32
+ __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(PACKAGE_ROOT, 'dist', 'runtime', 'csrClientEntry.js');
33
+ __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(PACKAGE_ROOT, 'dist', 'runtime', 'ssrClientEntry.js');
34
+ __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(PACKAGE_ROOT, 'dist', 'runtime', 'ssrServerEntry.js');
34
35
  const TEMP_DIR = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(process.cwd(), 'node_modules', __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.RSPRESS_TEMP_DIR);
35
- var runtimeModule_RuntimeModuleID = /*#__PURE__*/ function(RuntimeModuleID) {
36
+ var types_RuntimeModuleID = /*#__PURE__*/ function(RuntimeModuleID) {
36
37
  RuntimeModuleID["GlobalStyles"] = "virtual-global-styles";
37
38
  RuntimeModuleID["GlobalComponents"] = "virtual-global-components";
38
39
  RuntimeModuleID["RouteForClient"] = "virtual-routes";
@@ -99,10 +100,7 @@ async function flattenMdxContent(content, basePath, alias) {
99
100
  deps
100
101
  };
101
102
  }
102
- const importNodes = ast.children.filter((node)=>'mdxjsEsm' === node.type).flatMap((node)=>{
103
- var _node_data_estree, _node_data;
104
- 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) || [];
105
- }).filter((node)=>'ImportDeclaration' === node.type);
103
+ const importNodes = ast.children.filter((node)=>'mdxjsEsm' === node.type).flatMap((node)=>node.data?.estree?.body || []).filter((node)=>'ImportDeclaration' === node.type);
106
104
  for (const importNode of importNodes){
107
105
  const id = importNode.specifiers[0].local.name;
108
106
  const importPath = importNode.source.value;
@@ -142,12 +140,10 @@ function normalizePath(id) {
142
140
  }
143
141
  const rehypePluginCodeMeta = ()=>(tree)=>{
144
142
  (0, __WEBPACK_EXTERNAL_MODULE_unist_util_visit_555e002a__.visit)(tree, 'element', (node)=>{
145
- var _node_children_;
146
- 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) {
147
- var _codeNode_data;
143
+ if ('pre' === node.tagName && node.children[0]?.type === 'element' && 'code' === node.children[0].tagName) {
148
144
  const codeNode = node.children[0];
149
145
  codeNode.properties ??= {};
150
- codeNode.properties.meta = null === (_codeNode_data = codeNode.data) || void 0 === _codeNode_data ? void 0 : _codeNode_data.meta;
146
+ codeNode.properties.meta = codeNode.data?.meta;
151
147
  }
152
148
  });
153
149
  };
@@ -155,9 +151,8 @@ const rehypeHeaderAnchor = ()=>{
155
151
  const slugger = new __WEBPACK_EXTERNAL_MODULE_github_slugger_8e9a17cb__["default"]();
156
152
  return (tree)=>{
157
153
  (0, __WEBPACK_EXTERNAL_MODULE_unist_util_visit_555e002a__.visit)(tree, 'element', (node)=>{
158
- var _node_properties;
159
154
  if (!(0, __WEBPACK_EXTERNAL_MODULE_hast_util_heading_rank_cff646ba__.headingRank)(node)) return;
160
- if (!(null === (_node_properties = node.properties) || void 0 === _node_properties ? void 0 : _node_properties.id)) {
155
+ if (!node.properties?.id) {
161
156
  const [text, customId] = collectHeaderText(node);
162
157
  node.properties ??= {};
163
158
  node.properties.id = customId || slugger.slug(text);
@@ -246,7 +241,7 @@ function checkLinks(links, filepath, root, routeService) {
246
241
  if (!routeService.isExistRoute((0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.cleanUrl)(link))) errorInfos.push(`Internal link to "${link}" is dead, check it in "${relativePath}"`);
247
242
  });
248
243
  if (errorInfos.length > 0) {
249
- null == errorInfos || errorInfos.forEach((err)=>{
244
+ errorInfos?.forEach((err)=>{
250
245
  __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error(err);
251
246
  });
252
247
  if ((0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.isProduction)()) throw new Error('Dead link found');
@@ -260,46 +255,47 @@ const remarkCheckDeadLinks = (checkLink)=>{
260
255
  if (!url) return;
261
256
  if (internalLinks.has(url)) return;
262
257
  if (!url.startsWith('http://') && !url.startsWith('https://')) {
263
- var _url_split_join;
264
- 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]);
258
+ const { routePath: normalizeUrl } = routeService.normalizeRoutePath(url.split(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].sep).join('/')?.split('#')[0]);
265
259
  internalLinks.add(normalizeUrl);
266
260
  }
267
261
  });
268
262
  checkLinks(Array.from(internalLinks), vfile.path, root, routeService);
269
263
  };
270
264
  };
265
+ function normalizeLink(nodeUrl, routeService, relativePath, cleanUrls) {
266
+ if (!nodeUrl) return '';
267
+ if (nodeUrl.startsWith('#')) return `#${nodeUrl.slice(1)}`;
268
+ let { url, hash } = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.parseUrl)(nodeUrl);
269
+ if ((0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.isExternalUrl)(url)) return url + (hash ? `#${hash}` : '');
270
+ const extname = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].extname(url);
271
+ if ((routeService?.extensions ?? __WEBPACK_EXTERNAL_MODULE__rspress_shared_constants_70084e62__.DEFAULT_PAGE_EXTENSIONS).includes(extname)) url = url.replace(new RegExp(`\\${extname}$`), '');
272
+ 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);
273
+ else if (routeService) {
274
+ const [pathVersion, pathLang] = routeService.getRoutePathParts((0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.slash)(relativePath));
275
+ const [urlVersion, urlLang, urlPath] = routeService.getRoutePathParts(url);
276
+ url = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.addLeadingSlash)(urlPath);
277
+ if (pathLang && urlLang !== pathLang) url = `/${pathLang}${url}`;
278
+ if (pathVersion && urlVersion !== pathVersion) url = `/${pathVersion}${url}`;
279
+ }
280
+ if ('boolean' == typeof cleanUrls) url = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.normalizeHref)(url, cleanUrls);
281
+ else {
282
+ url = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.normalizeHref)(url, false);
283
+ url = url.replace(/\.html$/, cleanUrls);
284
+ }
285
+ if (hash) url += `#${hash}`;
286
+ return url;
287
+ }
288
+ const normalizeImageUrl = (imageUrl)=>{
289
+ if ((0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.isExternalUrl)(imageUrl) || imageUrl.startsWith('/')) return '';
290
+ return imageUrl;
291
+ };
271
292
  const remarkPluginNormalizeLink = ({ root, cleanUrls, routeService })=>(tree, file)=>{
272
293
  const images = [];
273
294
  (0, __WEBPACK_EXTERNAL_MODULE_unist_util_visit_555e002a__.visit)(tree, 'link', (node)=>{
274
- if (!node.url) return;
275
- if (node.url.startsWith('#')) {
276
- node.url = `#${node.url.slice(1)}`;
277
- return;
278
- }
279
- let { url, hash } = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.parseUrl)(node.url);
280
- if ((0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.isExternalUrl)(url)) {
281
- node.url = url + (hash ? `#${hash}` : '');
282
- return;
283
- }
284
- const extname = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].extname(url);
285
- if (((null == routeService ? void 0 : routeService.extensions) ?? __WEBPACK_EXTERNAL_MODULE__rspress_shared_constants_70084e62__.DEFAULT_PAGE_EXTENSIONS).includes(extname)) url = url.replace(new RegExp(`\\${extname}$`), '');
295
+ const { url: nodeUrl } = node;
286
296
  const relativePath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].relative(root, file.path);
287
- 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);
288
- else if (routeService) {
289
- const [pathVersion, pathLang] = routeService.getRoutePathParts((0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.slash)(relativePath));
290
- const [urlVersion, urlLang, urlPath] = routeService.getRoutePathParts(url);
291
- url = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.addLeadingSlash)(urlPath);
292
- if (pathLang && urlLang !== pathLang) url = `/${pathLang}${url}`;
293
- if (pathVersion && urlVersion !== pathVersion) url = `/${pathVersion}${url}`;
294
- }
295
- url = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.normalizeHref)(url, cleanUrls);
296
- if (hash) url += `#${hash}`;
297
- node.url = url;
297
+ node.url = normalizeLink(nodeUrl, routeService, relativePath, cleanUrls);
298
298
  });
299
- const normalizeImageUrl = (imageUrl)=>{
300
- if ((0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.isExternalUrl)(imageUrl) || imageUrl.startsWith('/')) return '';
301
- return imageUrl;
302
- };
303
299
  const getMdxSrcAttribute = (tempVar)=>({
304
300
  type: 'mdxJsxAttribute',
305
301
  name: 'src',
@@ -347,7 +343,7 @@ const remarkPluginNormalizeLink = ({ root, cleanUrls, routeService })=>(tree, fi
347
343
  (0, __WEBPACK_EXTERNAL_MODULE_unist_util_visit_555e002a__.visit)(tree, (node)=>{
348
344
  if ('mdxJsxFlowElement' !== node.type && 'mdxJsxTextElement' !== node.type || 'img' !== node.name) return;
349
345
  const srcAttr = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__.getNodeAttribute)(node, 'src', true);
350
- if ('string' != typeof (null == srcAttr ? void 0 : srcAttr.value)) return;
346
+ if ('string' != typeof srcAttr?.value) return;
351
347
  const imagePath = normalizeImageUrl(srcAttr.value);
352
348
  if (!imagePath) return;
353
349
  const tempVariableName = `image${images.length}`;
@@ -365,22 +361,10 @@ const parseToc = (tree)=>{
365
361
  if (node.depth >= 1 && node.depth < 5) {
366
362
  let customId = '';
367
363
  const text = node.children.map((child)=>{
368
- if ('link' === child.type) {
369
- var _child_children;
370
- return null === (_child_children = child.children) || void 0 === _child_children ? void 0 : _child_children.map((item)=>item.value).join('');
371
- }
372
- if ('strong' === child.type) {
373
- var _child_children1;
374
- return `**${null === (_child_children1 = child.children) || void 0 === _child_children1 ? void 0 : _child_children1.map((item)=>item.value).join('')}**`;
375
- }
376
- if ('emphasis' === child.type) {
377
- var _child_children2;
378
- return `*${null === (_child_children2 = child.children) || void 0 === _child_children2 ? void 0 : _child_children2.map((item)=>item.value).join('')}*`;
379
- }
380
- if ('delete' === child.type) {
381
- var _child_children3;
382
- return `~~${null === (_child_children3 = child.children) || void 0 === _child_children3 ? void 0 : _child_children3.map((item)=>item.value).join('')}~~`;
383
- }
364
+ if ('link' === child.type) return child.children?.map((item)=>item.value).join('');
365
+ if ('strong' === child.type) return `**${child.children?.map((item)=>item.value).join('')}**`;
366
+ if ('emphasis' === child.type) return `*${child.children?.map((item)=>item.value).join('')}*`;
367
+ if ('delete' === child.type) return `~~${child.children?.map((item)=>item.value).join('')}~~`;
384
368
  if ('text' === child.type) {
385
369
  const [textPart, idPart] = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__.extractTextAndId)(child.value);
386
370
  customId = idPart;
@@ -416,23 +400,13 @@ const remarkPluginToc = function() {
416
400
  };
417
401
  };
418
402
  async function createMDXOptions(docDirectory, config, checkDeadLinks, routeService, filepath, pluginDriver) {
419
- var _config_route;
420
- const cleanUrls = (null == config ? void 0 : null === (_config_route = config.route) || void 0 === _config_route ? void 0 : _config_route.cleanUrls) ?? false;
421
- const { remarkPlugins: remarkPluginsFromConfig = [], rehypePlugins: rehypePluginsFromConfig = [], globalComponents: globalComponentsFromConfig = [] } = (null == config ? void 0 : config.markdown) || {};
403
+ const cleanUrls = config?.route?.cleanUrls ?? false;
404
+ const { remarkPlugins: remarkPluginsFromConfig = [], rehypePlugins: rehypePluginsFromConfig = [], globalComponents: globalComponentsFromConfig = [] } = config?.markdown || {};
422
405
  const rspressPlugins = pluginDriver.getPlugins();
423
- const remarkPluginsFromPlugins = rspressPlugins.flatMap((plugin)=>{
424
- var _plugin_markdown;
425
- return (null === (_plugin_markdown = plugin.markdown) || void 0 === _plugin_markdown ? void 0 : _plugin_markdown.remarkPlugins) || [];
426
- });
427
- const rehypePluginsFromPlugins = rspressPlugins.flatMap((plugin)=>{
428
- var _plugin_markdown;
429
- return (null === (_plugin_markdown = plugin.markdown) || void 0 === _plugin_markdown ? void 0 : _plugin_markdown.rehypePlugins) || [];
430
- });
406
+ const remarkPluginsFromPlugins = rspressPlugins.flatMap((plugin)=>plugin.markdown?.remarkPlugins || []);
407
+ const rehypePluginsFromPlugins = rspressPlugins.flatMap((plugin)=>plugin.markdown?.rehypePlugins || []);
431
408
  const globalComponents = [
432
- ...rspressPlugins.flatMap((plugin)=>{
433
- var _plugin_markdown;
434
- return (null === (_plugin_markdown = plugin.markdown) || void 0 === _plugin_markdown ? void 0 : _plugin_markdown.globalComponents) || [];
435
- }),
409
+ ...rspressPlugins.flatMap((plugin)=>plugin.markdown?.globalComponents || []),
436
410
  ...globalComponentsFromConfig
437
411
  ];
438
412
  return {
@@ -453,7 +427,7 @@ async function createMDXOptions(docDirectory, config, checkDeadLinks, routeServi
453
427
  remarkCheckDeadLinks,
454
428
  {
455
429
  root: docDirectory,
456
- base: (null == config ? void 0 : config.base) || '',
430
+ base: config?.base || '',
457
431
  routeService
458
432
  }
459
433
  ],
@@ -482,7 +456,7 @@ async function createMDXOptions(docDirectory, config, checkDeadLinks, routeServi
482
456
  };
483
457
  }
484
458
  async function updateSiteDataRuntimeModule(modulePath, pageMeta) {
485
- const siteDataModulePath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(TEMP_DIR, 'runtime', `${runtimeModule_RuntimeModuleID.SiteData}.mjs`);
459
+ const siteDataModulePath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(TEMP_DIR, 'runtime', `${types_RuntimeModuleID.SiteData}.mjs`);
486
460
  const { default: siteData } = await import((0, __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__.pathToFileURL)(siteDataModulePath).href);
487
461
  await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].writeFile(siteDataModulePath, `export default ${JSON.stringify({
488
462
  ...siteData,
@@ -508,7 +482,6 @@ function createCheckPageMetaUpdateFn() {
508
482
  }
509
483
  const checkPageMetaUpdate = createCheckPageMetaUpdateFn();
510
484
  async function mdxLoader(source) {
511
- var _config_markdown;
512
485
  this.cacheable(true);
513
486
  const callback = this.async();
514
487
  const options = this.getOptions();
@@ -520,55 +493,32 @@ async function mdxLoader(source) {
520
493
  deps.forEach((dep)=>this.addDependency(dep));
521
494
  const replacedContent = applyReplaceRules(flattenContent, config.replaceRules);
522
495
  const preprocessedContent = escapeMarkdownHeadingIds(replacedContent);
523
- let enableMdxRs;
524
- const mdxRs = (null == config ? void 0 : null === (_config_markdown = config.markdown) || void 0 === _config_markdown ? void 0 : _config_markdown.mdxRs) ?? true;
525
- enableMdxRs = 'object' == typeof mdxRs ? 'function' == typeof (null == mdxRs ? void 0 : mdxRs.include) ? mdxRs.include(filepath) : true : mdxRs;
526
496
  try {
527
- let compileResult;
528
497
  let pageMeta = {
529
498
  title: '',
530
499
  toc: [],
531
500
  headingTitle: ''
532
501
  };
533
502
  const frontmatterTitle = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__.extractTextAndId)(frontmatter.title)[0];
534
- if (enableMdxRs) {
535
- const { compile } = await import("@rspress/mdx-rs");
536
- const { toc, links, title, code } = await compile({
537
- value: preprocessedContent,
538
- filepath,
539
- root: docDirectory,
540
- development: 'production' !== process.env.NODE_ENV
541
- });
542
- compileResult = code;
543
- const headingTitle = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__.extractTextAndId)(title)[0];
544
- pageMeta = {
545
- toc,
546
- title: frontmatterTitle || headingTitle,
547
- headingTitle,
548
- frontmatter
549
- };
550
- if (checkDeadLinks) checkLinks(links, filepath, docDirectory, routeService);
551
- } else {
552
- const mdxOptions = await createMDXOptions(docDirectory, config, checkDeadLinks, routeService, filepath, pluginDriver);
553
- const compiler = (0, __WEBPACK_EXTERNAL_MODULE__mdx_js_mdx_b904bd09__.createProcessor)(mdxOptions);
554
- compiler.data('pageMeta', {
555
- toc: [],
556
- title: ''
557
- });
558
- const vFile = await compiler.process({
559
- value: preprocessedContent,
560
- path: filepath
561
- });
562
- compileResult = String(vFile);
563
- const compilationMeta = compiler.data('pageMeta');
564
- const headingTitle = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__.extractTextAndId)(compilationMeta.title)[0];
565
- pageMeta = {
566
- ...compilationMeta,
567
- title: frontmatterTitle || headingTitle,
568
- headingTitle,
569
- frontmatter
570
- };
571
- }
503
+ const mdxOptions = await createMDXOptions(docDirectory, config, checkDeadLinks, routeService, filepath, pluginDriver);
504
+ const compiler = (0, __WEBPACK_EXTERNAL_MODULE__mdx_js_mdx_b904bd09__.createProcessor)(mdxOptions);
505
+ compiler.data('pageMeta', {
506
+ toc: [],
507
+ title: ''
508
+ });
509
+ const vFile = await compiler.process({
510
+ value: preprocessedContent,
511
+ path: filepath
512
+ });
513
+ const compileResult = String(vFile);
514
+ const compilationMeta = compiler.data('pageMeta');
515
+ const headingTitle = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__.extractTextAndId)(compilationMeta.title)[0];
516
+ pageMeta = {
517
+ ...compilationMeta,
518
+ title: frontmatterTitle || headingTitle,
519
+ headingTitle,
520
+ frontmatter
521
+ };
572
522
  if (!(0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.isProduction)()) checkPageMetaUpdate(filepath, pageMeta);
573
523
  const result = `const frontmatter = ${JSON.stringify(frontmatter)};
574
524
  ${compileResult}
@@ -8,16 +8,12 @@ import "virtual-global-styles";
8
8
  import * as __WEBPACK_EXTERNAL_MODULE__initPageData_js_731596b5__ from "./initPageData.js";
9
9
  function App({ helmetContext }) {
10
10
  const { setData: setPageData, data } = (0, __WEBPACK_EXTERNAL_MODULE_react__.useContext)(__WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.DataContext);
11
- const frontmatter = data.page.frontmatter || {};
12
11
  const { pathname, search } = (0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.useLocation)();
13
- const query = new URLSearchParams(search);
14
- const GLOBAL_COMPONENTS_KEY = 'globalUIComponents';
15
- const hideGlobalUIComponents = false === frontmatter[GLOBAL_COMPONENTS_KEY] || "0" === query.get(GLOBAL_COMPONENTS_KEY);
16
12
  (0, __WEBPACK_EXTERNAL_MODULE_react__.useLayoutEffect)(()=>{
17
13
  async function refetchData() {
18
14
  try {
19
15
  const pageData = await (0, __WEBPACK_EXTERNAL_MODULE__initPageData_js_731596b5__.initPageData)(pathname);
20
- null == setPageData || setPageData(pageData);
16
+ setPageData?.(pageData);
21
17
  } catch (e) {
22
18
  console.log(e);
23
19
  }
@@ -27,6 +23,11 @@ function App({ helmetContext }) {
27
23
  pathname,
28
24
  setPageData
29
25
  ]);
26
+ if (!data) return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.Fragment, {});
27
+ const frontmatter = data.page.frontmatter || {};
28
+ const GLOBAL_COMPONENTS_KEY = 'globalUIComponents';
29
+ const query = new URLSearchParams(search);
30
+ const hideGlobalUIComponents = false === frontmatter[GLOBAL_COMPONENTS_KEY] || "0" === query.get(GLOBAL_COMPONENTS_KEY);
30
31
  return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)(__WEBPACK_EXTERNAL_MODULE_react_helmet_async_048d06c6__.HelmetProvider, {
31
32
  context: helmetContext,
32
33
  children: [
@@ -1 +1,4 @@
1
- export declare function ClientApp(): import("react/jsx-runtime").JSX.Element;
1
+ import type { PageData } from '@rspress/shared';
2
+ export declare function ClientApp({ initialPageData, }: {
3
+ initialPageData?: PageData;
4
+ }): import("react/jsx-runtime").JSX.Element;
@@ -3,34 +3,25 @@ import * as __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__ from "@rspress
3
3
  import * as __WEBPACK_EXTERNAL_MODULE__theme_75e53063__ from "@theme";
4
4
  import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
5
5
  import * as __WEBPACK_EXTERNAL_MODULE__App_js_3638e61b__ from "./App.js";
6
- import * as __WEBPACK_EXTERNAL_MODULE__initPageData_js_731596b5__ from "./initPageData.js";
7
- function ClientApp() {
8
- const [data, setData] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(null);
6
+ function ClientApp({ initialPageData = null }) {
7
+ const [data, setData] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(initialPageData);
9
8
  const [theme, setTheme] = (0, __WEBPACK_EXTERNAL_MODULE__theme_75e53063__.useThemeState)();
10
- (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
11
- (0, __WEBPACK_EXTERNAL_MODULE__initPageData_js_731596b5__.initPageData)(window.location.pathname).then((pageData)=>{
12
- setData(pageData);
13
- });
14
- }, []);
15
- const themeValue = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>({
9
+ return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.ThemeContext.Provider, {
10
+ value: (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>({
11
+ theme,
12
+ setTheme
13
+ }), [
16
14
  theme,
17
15
  setTheme
18
- }), [
19
- theme,
20
- setTheme
21
- ]);
22
- const dataValue = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>({
23
- data,
24
- setData
25
- }), [
26
- data,
27
- setData
28
- ]);
29
- if (!data) return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.Fragment, {});
30
- return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.ThemeContext.Provider, {
31
- value: themeValue,
16
+ ]),
32
17
  children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.DataContext.Provider, {
33
- value: dataValue,
18
+ value: (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>({
19
+ data,
20
+ setData
21
+ }), [
22
+ data,
23
+ setData
24
+ ]),
34
25
  children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.BrowserRouter, {
35
26
  children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__App_js_3638e61b__.App, {})
36
27
  })
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,13 @@
1
+ import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__ from "react/jsx-runtime";
2
+ import * as __WEBPACK_EXTERNAL_MODULE__ClientApp_js_4935dbba__ from "./ClientApp.js";
3
+ async function renderInBrowser() {
4
+ const container = document.getElementById('root');
5
+ if (process.env.__REACT_GTE_18__) {
6
+ const { createRoot } = await import("react-dom/client");
7
+ createRoot(container).render(/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__ClientApp_js_4935dbba__.ClientApp, {}));
8
+ } else {
9
+ const ReactDOM = await import("react-dom");
10
+ ReactDOM.render(/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__ClientApp_js_4935dbba__.ClientApp, {}), container);
11
+ }
12
+ }
13
+ renderInBrowser();
@@ -3,16 +3,14 @@ import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__ from "@rspress/
3
3
  import "virtual-global-styles";
4
4
  import * as __WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__ from "virtual-site-data";
5
5
  async function initPageData(routePath) {
6
- var _siteData_multiVersion;
7
6
  const matchedRoute = (0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.pathnameToRouteService)(routePath);
8
7
  if (matchedRoute) {
9
- var _mod_default___RSPRESS_PAGE_META;
10
8
  const mod = await matchedRoute.preload();
11
9
  const pagePath = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.cleanUrl)(matchedRoute.filePath);
12
10
  const normalize = (p)=>p.replace(/\/$/, '').toLowerCase();
13
11
  const extractPageInfo = __WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__["default"].pages.find((page)=>(0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.isEqualPath)(normalize(page.routePath), normalize(matchedRoute.path)));
14
12
  const encodedPagePath = encodeURIComponent(pagePath);
15
- const meta = (null === (_mod_default___RSPRESS_PAGE_META = mod.default.__RSPRESS_PAGE_META) || void 0 === _mod_default___RSPRESS_PAGE_META ? void 0 : _mod_default___RSPRESS_PAGE_META[encodedPagePath]) || {};
13
+ const meta = mod.default.__RSPRESS_PAGE_META?.[encodedPagePath] || {};
16
14
  const { toc = [], title = '', frontmatter = {}, ...rest } = __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.MDX_OR_MD_REGEXP.test(matchedRoute.filePath) ? meta : mod;
17
15
  return {
18
16
  siteData: __WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__["default"],
@@ -20,7 +18,7 @@ async function initPageData(routePath) {
20
18
  ...rest,
21
19
  pagePath,
22
20
  ...extractPageInfo,
23
- pageType: (null == frontmatter ? void 0 : frontmatter.pageType) || 'doc',
21
+ pageType: frontmatter?.pageType || 'doc',
24
22
  title,
25
23
  frontmatter,
26
24
  toc
@@ -28,7 +26,7 @@ async function initPageData(routePath) {
28
26
  };
29
27
  }
30
28
  let lang = __WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__["default"].lang || '';
31
- let version = (null === (_siteData_multiVersion = __WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__["default"].multiVersion) || void 0 === _siteData_multiVersion ? void 0 : _siteData_multiVersion.default) || '';
29
+ let version = __WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__["default"].multiVersion?.default || '';
32
30
  if (__WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__["default"].lang && 'undefined' != typeof window) {
33
31
  const path = location.pathname.replace(__WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__["default"].base, '').split('/').slice(0, 2);
34
32
  if (__WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__["default"].locales.length) {
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,19 @@
1
+ import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__ from "react/jsx-runtime";
2
+ import * as __WEBPACK_EXTERNAL_MODULE__ClientApp_js_4935dbba__ from "./ClientApp.js";
3
+ import * as __WEBPACK_EXTERNAL_MODULE__initPageData_js_731596b5__ from "./initPageData.js";
4
+ async function renderInBrowser() {
5
+ const container = document.getElementById('root');
6
+ const initialPageData = await (0, __WEBPACK_EXTERNAL_MODULE__initPageData_js_731596b5__.initPageData)(window.location.pathname);
7
+ if (process.env.__REACT_GTE_18__) {
8
+ const { hydrateRoot } = await import("react-dom/client");
9
+ hydrateRoot(container, /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__ClientApp_js_4935dbba__.ClientApp, {
10
+ initialPageData: initialPageData
11
+ }));
12
+ } else {
13
+ const ReactDOM = await import("react-dom");
14
+ ReactDOM.hydrate(/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__ClientApp_js_4935dbba__.ClientApp, {
15
+ initialPageData: initialPageData
16
+ }), container);
17
+ }
18
+ }
19
+ renderInBrowser();
@@ -1,4 +1,4 @@
1
- var tsconfig_rslib_entry_namespaceObject = JSON.parse('{"compilerOptions":{"rootDir":".","baseUrl":".","skipLibCheck":true,"jsx":"react-jsx","esModuleInterop":true},"include":["./**/*"]}');
2
- var __webpack_exports__compilerOptions = tsconfig_rslib_entry_namespaceObject.compilerOptions;
3
- var __webpack_exports__include = tsconfig_rslib_entry_namespaceObject.include;
1
+ var tsconfig_namespaceObject = JSON.parse('{"compilerOptions":{"rootDir":".","baseUrl":".","skipLibCheck":true,"jsx":"react-jsx","esModuleInterop":true},"include":["./**/*"]}');
2
+ var __webpack_exports__compilerOptions = tsconfig_namespaceObject.compilerOptions;
3
+ var __webpack_exports__include = tsconfig_namespaceObject.include;
4
4
  export { __webpack_exports__compilerOptions as compilerOptions, __webpack_exports__include as include };
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@rspress/core",
3
- "version": "2.0.0-alpha.9",
3
+ "version": "2.0.0-beta.1",
4
4
  "description": "The Rspress Documentation Framework",
5
5
  "bugs": "https://github.com/web-infra-dev/rspress/issues",
6
6
  "repository": {
7
7
  "type": "git",
8
- "url": "https://github.com/web-infra-dev/rspress",
8
+ "url": "git+https://github.com/web-infra-dev/rspress.git",
9
9
  "directory": "packages/cli/core"
10
10
  },
11
11
  "license": "MIT",
@@ -45,7 +45,7 @@
45
45
  "@mdx-js/loader": "^3.1.0",
46
46
  "@mdx-js/mdx": "^3.1.0",
47
47
  "@mdx-js/react": "^3.1.0",
48
- "@rsbuild/core": "1.3.4",
48
+ "@rsbuild/core": "1.3.9",
49
49
  "@rsbuild/plugin-react": "~1.1.1",
50
50
  "@rspress/mdx-rs": "0.6.6",
51
51
  "enhanced-resolve": "5.18.1",
@@ -53,34 +53,34 @@
53
53
  "hast-util-from-html": "^2.0.3",
54
54
  "hast-util-heading-rank": "^3.0.0",
55
55
  "html-to-text": "^9.0.5",
56
- "htmr": "^1.0.2",
57
56
  "lodash-es": "^4.17.21",
58
57
  "mdast-util-mdxjs-esm": "^2.0.1",
59
58
  "picocolors": "^1.1.1",
60
- "react": "^18.3.1",
61
- "react-dom": "^18.3.1",
59
+ "react": "^19.1.0",
60
+ "react-dom": "^19.1.0",
62
61
  "react-helmet-async": "^2.0.5",
63
62
  "react-lazy-with-preload": "^2.2.1",
63
+ "react-router-dom": "^6.29.0",
64
64
  "react-syntax-highlighter": "^15.6.1",
65
65
  "rehype-external-links": "^3.0.0",
66
66
  "remark": "^15.0.1",
67
67
  "remark-gfm": "^4.0.1",
68
68
  "rspack-plugin-virtual-module": "0.1.13",
69
- "tinyglobby": "^0.2.12",
69
+ "tinyglobby": "^0.2.13",
70
70
  "unified": "^11.0.5",
71
71
  "unist-util-visit": "^5.0.0",
72
72
  "unist-util-visit-children": "^3.0.0",
73
- "@rspress/plugin-auto-nav-sidebar": "2.0.0-alpha.9",
74
- "@rspress/plugin-container-syntax": "2.0.0-alpha.9",
75
- "@rspress/plugin-last-updated": "2.0.0-alpha.9",
76
- "@rspress/runtime": "2.0.0-alpha.9",
77
- "@rspress/plugin-medium-zoom": "2.0.0-alpha.9",
78
- "@rspress/shared": "2.0.0-alpha.9",
79
- "@rspress/theme-default": "2.0.0-alpha.9"
73
+ "@rspress/plugin-auto-nav-sidebar": "2.0.0-beta.1",
74
+ "@rspress/plugin-container-syntax": "2.0.0-beta.1",
75
+ "@rspress/plugin-last-updated": "2.0.0-beta.1",
76
+ "@rspress/plugin-medium-zoom": "2.0.0-beta.1",
77
+ "@rspress/theme-default": "2.0.0-beta.1",
78
+ "@rspress/shared": "2.0.0-beta.1",
79
+ "@rspress/runtime": "2.0.0-beta.1"
80
80
  },
81
81
  "devDependencies": {
82
- "@microsoft/api-extractor": "^7.52.3",
83
- "@rslib/core": "0.6.1",
82
+ "@microsoft/api-extractor": "^7.52.4",
83
+ "@rslib/core": "0.6.5",
84
84
  "@rspress-dev/plugin-preview": "link:../plugin-preview",
85
85
  "@types/hast": "^3.0.4",
86
86
  "@types/html-to-text": "^9.0.4",
@@ -98,14 +98,15 @@
98
98
  "remark-rehype": "^11.1.2",
99
99
  "remark-stringify": "^11.0.0",
100
100
  "rimraf": "^6.0.1",
101
+ "rsbuild-plugin-publint": "^0.3.0",
101
102
  "rsbuild-plugin-virtual-module": "0.1.1",
102
103
  "tailwindcss": "^3.4.17",
103
104
  "typescript": "^5.8.2",
104
- "vfile": "^5.3.7",
105
+ "vfile": "^6.0.3",
105
106
  "@rspress/config": "1.0.0"
106
107
  },
107
108
  "engines": {
108
- "node": ">=14.17.6"
109
+ "node": ">=18.0.0"
109
110
  },
110
111
  "publishConfig": {
111
112
  "access": "public",
@@ -1 +0,0 @@
1
- export declare function renderInBrowser(): Promise<void>;