@rspress/core 2.0.0-beta.28 → 2.0.0-beta.29

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/cli.js CHANGED
@@ -6,7 +6,7 @@ import picocolors from "picocolors";
6
6
  import { build, dev, serve } from "./index.js";
7
7
  import node_fs from "node:fs";
8
8
  import { DEFAULT_CONFIG_EXTENSIONS, DEFAULT_CONFIG_NAME } from "@rspress/shared/constants";
9
- var package_namespaceObject = JSON.parse('{"rE":"2.0.0-beta.28"}');
9
+ var package_namespaceObject = JSON.parse('{"rE":"2.0.0-beta.29"}');
10
10
  const findConfig = (basePath)=>DEFAULT_CONFIG_EXTENSIONS.map((ext)=>basePath + ext).find(node_fs.existsSync);
11
11
  async function loadConfigFile(customConfigFile) {
12
12
  const baseDir = process.cwd();
package/dist/index.d.ts CHANGED
@@ -231,7 +231,7 @@ export declare class RouteService {
231
231
  addRoute(routePage: RoutePage): Promise<void>;
232
232
  getRoutes(): RouteMeta[];
233
233
  getRoutePages(): RoutePage[];
234
- isExistRoute(routePath: string): boolean;
234
+ isExistRoute(link: string): boolean;
235
235
  generateRoutesCode(): string;
236
236
  private generateRoutesCodeByRouteMeta;
237
237
  getRoutePathParts(relativePath: string): string[];
package/dist/index.js CHANGED
@@ -150,7 +150,7 @@ function defineConfig(config) {
150
150
  }
151
151
  var external_node_path_ = __webpack_require__("node:path");
152
152
  var external_node_url_ = __webpack_require__("node:url");
153
- var package_namespaceObject = JSON.parse('{"rE":"2.0.0-beta.28"}');
153
+ var package_namespaceObject = JSON.parse('{"rE":"2.0.0-beta.29"}');
154
154
  const RSPRESS_VERSION = package_namespaceObject.rE;
155
155
  const isProduction = ()=>'production' === process.env.NODE_ENV;
156
156
  const importStatementRegex = /import\s+(.*?)\s+from\s+(['"])(.*?)(?:"|');?/gm;
@@ -466,8 +466,13 @@ class RouteService {
466
466
  getRoutePages() {
467
467
  return Array.from(this.routeData.values());
468
468
  }
469
- isExistRoute(routePath) {
470
- return this.routeData.has(routePath);
469
+ isExistRoute(link) {
470
+ function linkToRoutePath(routePath) {
471
+ return decodeURIComponent(routePath.split('#')[0]).replace(/\.html$/, '').replace(/\/index$/, '/');
472
+ }
473
+ const cleanLinkPath = linkToRoutePath(link);
474
+ if (!this.routeData.has((0, shared_.removeTrailingSlash)(cleanLinkPath)) && !this.routeData.has((0, shared_.addTrailingSlash)(cleanLinkPath))) return false;
475
+ return true;
471
476
  }
472
477
  generateRoutesCode() {
473
478
  return this.generateRoutesCodeByRouteMeta(this.getRoutes());
@@ -967,30 +972,6 @@ const i18nVMPlugin = (context)=>{
967
972
  }
968
973
  };
969
974
  };
970
- const routeListVMPlugin = (context)=>{
971
- const { routeService } = context;
972
- return {
973
- ["virtual-routes"]: ()=>routeService.generateRoutesCode()
974
- };
975
- };
976
- const runtimeConfigVMPlugin = (context)=>({
977
- ["virtual-runtime-config"]: ()=>{
978
- const { config } = context;
979
- const { base } = config;
980
- const normalizedBase = (0, shared_.normalizeSlash)(base ?? '/');
981
- return `export const base = ${JSON.stringify(normalizedBase)};`;
982
- }
983
- });
984
- var external_path_ = __webpack_require__("path");
985
- const searchHookVMPlugin = (context)=>({
986
- ["virtual-search-hooks"]: ()=>{
987
- const { config } = context;
988
- let content = 'export const onSearch = () => {};';
989
- const searchHooks = 'object' == typeof config.search && config.search?.searchHooks;
990
- if (searchHooks) content = `export * from ${JSON.stringify(external_path_["default"].posix.normalize(searchHooks))}`;
991
- return content;
992
- }
993
- });
994
975
  var external_node_fs_ = __webpack_require__("node:fs");
995
976
  let flattenMdxContent_resolver;
996
977
  let startFlatten = false;
@@ -1181,6 +1162,128 @@ async function extractPageData(routeService, options) {
1181
1162
  function createHash_createHash(str) {
1182
1163
  return createHash('sha256').update(str).digest('hex').slice(0, 8);
1183
1164
  }
1165
+ function deletePrivateField(obj) {
1166
+ if ('object' != typeof obj || null === obj) return obj;
1167
+ const newObj = {
1168
+ ...obj
1169
+ };
1170
+ for(const key in newObj)if (key.startsWith('_')) delete newObj[key];
1171
+ return newObj;
1172
+ }
1173
+ async function createPageData(context) {
1174
+ const { config, alias, userDocRoot, routeService, pluginDriver } = context;
1175
+ const userConfig = config;
1176
+ const tempSearchObj = Object.assign({}, userConfig.search);
1177
+ if (tempSearchObj) tempSearchObj.searchHooks = void 0;
1178
+ const replaceRules = userConfig?.replaceRules || [];
1179
+ const searchConfig = userConfig?.search || {};
1180
+ const searchCodeBlocks = 'codeBlocks' in searchConfig ? Boolean(searchConfig.codeBlocks) : true;
1181
+ const pages = await extractPageData(routeService, {
1182
+ replaceRules,
1183
+ alias,
1184
+ root: userDocRoot,
1185
+ searchCodeBlocks
1186
+ });
1187
+ await pluginDriver.modifySearchIndexData(pages);
1188
+ const versioned = 'boolean' != typeof userConfig.search && userConfig.search?.versioned;
1189
+ const groupedPages = groupBy(pages, (page)=>{
1190
+ if (page.frontmatter?.pageType === 'home') return 'noindex';
1191
+ const version = versioned ? page.version : '';
1192
+ const lang = page.lang || '';
1193
+ return `${version}###${lang}`;
1194
+ });
1195
+ delete groupedPages.noindex;
1196
+ const indexHashByGroup = {};
1197
+ const searchIndex = {};
1198
+ await Promise.all(Object.keys(groupedPages).map(async (group)=>{
1199
+ const stringifiedIndex = JSON.stringify(groupedPages[group].map(deletePrivateField));
1200
+ const indexHash = createHash_createHash(stringifiedIndex);
1201
+ indexHashByGroup[group] = indexHash;
1202
+ const [version, lang] = group.split('###');
1203
+ const indexVersion = version ? `.${version.replace('.', '_')}` : '';
1204
+ const indexLang = lang ? `.${lang}` : '';
1205
+ const filename = `${shared_.SEARCH_INDEX_NAME}${indexVersion}${indexLang}.${indexHash}.json`;
1206
+ searchIndex[filename] = stringifiedIndex;
1207
+ }));
1208
+ await Promise.all(pages.map(async (pageData)=>pluginDriver.extendPageData(pageData)));
1209
+ const filepaths = [];
1210
+ const pageData = {
1211
+ pages: pages.map((page)=>{
1212
+ const { content: _content, _filepath, _html, _flattenContent, ...rest } = page;
1213
+ filepaths.push(_filepath);
1214
+ return rest;
1215
+ })
1216
+ };
1217
+ return {
1218
+ filepaths,
1219
+ pageData,
1220
+ searchIndex,
1221
+ indexHashByGroup
1222
+ };
1223
+ }
1224
+ const rsbuildPluginDocVM = async ({ config, userDocRoot, routeService, pluginDriver })=>{
1225
+ const ref = {
1226
+ pageData: null,
1227
+ searchIndex: null,
1228
+ indexHashByGroup: null,
1229
+ filepaths: []
1230
+ };
1231
+ const searchIndexRsbuildPlugin = {
1232
+ name: 'rsbuild-plugin-searchIndex',
1233
+ async setup (api) {
1234
+ api.modifyBundlerChain(async (bundlerChain)=>{
1235
+ const alias = bundlerChain.resolve.alias.entries();
1236
+ const { pageData, indexHashByGroup, searchIndex, filepaths } = await createPageData({
1237
+ config,
1238
+ alias: alias,
1239
+ userDocRoot,
1240
+ routeService,
1241
+ pluginDriver
1242
+ });
1243
+ ref.pageData = pageData;
1244
+ ref.searchIndex = searchIndex;
1245
+ ref.indexHashByGroup = indexHashByGroup;
1246
+ ref.filepaths = filepaths;
1247
+ api.processAssets({
1248
+ stage: 'report',
1249
+ environments: [
1250
+ 'web'
1251
+ ]
1252
+ }, ({ compilation, compiler })=>{
1253
+ for (const [filename, stringifiedIndex] of Object.entries(searchIndex))compilation.emitAsset(`static/${filename}`, new compiler.webpack.sources.RawSource(stringifiedIndex));
1254
+ });
1255
+ });
1256
+ }
1257
+ };
1258
+ return [
1259
+ searchIndexRsbuildPlugin,
1260
+ pluginVirtualModule({
1261
+ tempDir: '.rspress',
1262
+ virtualModules: {
1263
+ ["virtual-page-data"]: async ({ addDependency })=>{
1264
+ for (const file of ref.filepaths)addDependency(file);
1265
+ return `export const pageData = ${JSON.stringify(ref.pageData, null, 2)};
1266
+ export const searchIndexHash = ${JSON.stringify(ref.indexHashByGroup, null, 2)};`;
1267
+ }
1268
+ }
1269
+ })
1270
+ ];
1271
+ };
1272
+ const routeListVMPlugin = (context)=>{
1273
+ const { routeService } = context;
1274
+ return {
1275
+ ["virtual-routes"]: ()=>routeService.generateRoutesCode()
1276
+ };
1277
+ };
1278
+ const searchHookVMPlugin = (context)=>({
1279
+ ["virtual-search-hooks"]: ()=>{
1280
+ const { config } = context;
1281
+ let content = 'export const onSearch = () => {};';
1282
+ const searchHooks = 'object' == typeof config.search && config.search?.searchHooks;
1283
+ if (searchHooks) content = `export * from ${JSON.stringify(external_node_path_["default"].posix.normalize(searchHooks))}`;
1284
+ return content;
1285
+ }
1286
+ });
1184
1287
  function normalizeThemeConfig(docConfig) {
1185
1288
  const { locales: siteLocales, lang, replaceRules = [], multiVersion } = docConfig;
1186
1289
  const { versions = [] } = multiVersion || {};
@@ -1198,7 +1301,7 @@ function normalizeThemeConfig(docConfig) {
1198
1301
  const text = i18nTextData[key]?.[currentLang];
1199
1302
  return text || key;
1200
1303
  };
1201
- const cleanUrls = docConfig.route?.cleanUrls ?? false;
1304
+ const cleanUrls = false;
1202
1305
  const transformLink = (link, currentLang)=>(0, shared_.normalizeHref)(normalizeLinkPrefix(link, currentLang), cleanUrls);
1203
1306
  const textReplace = (text, currentLang)=>applyReplaceRules(getI18nText(text, currentLang), replaceRules);
1204
1307
  const normalizeSidebar = (sidebar, currentLang)=>{
@@ -1271,51 +1374,13 @@ function normalizeThemeConfig(docConfig) {
1271
1374
  }
1272
1375
  return themeConfig;
1273
1376
  }
1274
- function deletePrivateField(obj) {
1275
- if ('object' != typeof obj || null === obj) return obj;
1276
- const newObj = {
1277
- ...obj
1278
- };
1279
- for(const key in newObj)if (key.startsWith('_')) delete newObj[key];
1280
- return newObj;
1281
- }
1282
- async function createSiteData(context) {
1283
- const { config, alias, userDocRoot, routeService, pluginDriver } = context;
1284
- const userConfig = config;
1377
+ async function createSiteData(userConfig) {
1285
1378
  const tempSearchObj = Object.assign({}, userConfig.search);
1286
1379
  if (tempSearchObj) tempSearchObj.searchHooks = void 0;
1287
- const replaceRules = userConfig?.replaceRules || [];
1288
- const searchConfig = userConfig?.search || {};
1289
- const searchCodeBlocks = 'codeBlocks' in searchConfig ? Boolean(searchConfig.codeBlocks) : true;
1290
- const pages = await extractPageData(routeService, {
1291
- replaceRules,
1292
- alias,
1293
- root: userDocRoot,
1294
- searchCodeBlocks
1295
- });
1296
- await pluginDriver.modifySearchIndexData(pages);
1297
- const versioned = 'boolean' != typeof userConfig.search && userConfig.search?.versioned;
1298
- const groupedPages = groupBy(pages, (page)=>{
1299
- if (page.frontmatter?.pageType === 'home') return 'noindex';
1300
- const version = versioned ? page.version : '';
1301
- const lang = page.lang || '';
1302
- return `${version}###${lang}`;
1303
- });
1304
- delete groupedPages.noindex;
1305
- const indexHashByGroup = {};
1306
- const searchIndex = {};
1307
- await Promise.all(Object.keys(groupedPages).map(async (group)=>{
1308
- const stringifiedIndex = JSON.stringify(groupedPages[group].map(deletePrivateField));
1309
- const indexHash = createHash_createHash(stringifiedIndex);
1310
- indexHashByGroup[group] = indexHash;
1311
- const [version, lang] = group.split('###');
1312
- const indexVersion = version ? `.${version.replace('.', '_')}` : '';
1313
- const indexLang = lang ? `.${lang}` : '';
1314
- const filename = `${shared_.SEARCH_INDEX_NAME}${indexVersion}${indexLang}.${indexHash}.json`;
1315
- searchIndex[filename] = stringifiedIndex;
1316
- }));
1317
- await Promise.all(pages.map(async (pageData)=>pluginDriver.extendPageData(pageData)));
1380
+ const { base } = userConfig;
1381
+ const normalizedBase = (0, shared_.addTrailingSlash)((0, shared_.addLeadingSlash)(base ?? '/'));
1318
1382
  const siteData = {
1383
+ base: normalizedBase,
1319
1384
  title: userConfig?.title || '',
1320
1385
  description: userConfig?.description || '',
1321
1386
  icon: getIconUrlPath(userConfig?.icon) || '',
@@ -1332,13 +1397,6 @@ async function createSiteData(context) {
1332
1397
  search: tempSearchObj ?? {
1333
1398
  mode: 'local'
1334
1399
  },
1335
- pages: pages.map((page)=>{
1336
- const { content: _content, _filepath, _html, _flattenContent, ...rest } = page;
1337
- return isProduction() ? rest : {
1338
- ...rest,
1339
- _filepath
1340
- };
1341
- }),
1342
1400
  markdown: {
1343
1401
  showLineNumbers: userConfig?.markdown?.showLineNumbers ?? false,
1344
1402
  defaultWrapCode: userConfig?.markdown?.defaultWrapCode ?? false,
@@ -1346,53 +1404,17 @@ async function createSiteData(context) {
1346
1404
  }
1347
1405
  };
1348
1406
  return {
1349
- siteData,
1350
- searchIndex,
1351
- indexHashByGroup
1407
+ siteData
1352
1408
  };
1353
1409
  }
1354
- const rsbuildPluginDocVM = async ({ config, userDocRoot, routeService, pluginDriver })=>{
1355
- const ref = {
1356
- siteData: null,
1357
- searchIndex: null,
1358
- indexHashByGroup: null
1359
- };
1360
- const searchIndexRsbuildPlugin = {
1361
- name: 'rsbuild-plugin-searchIndex',
1362
- async setup (api) {
1363
- api.modifyBundlerChain(async (bundlerChain)=>{
1364
- const alias = bundlerChain.resolve.alias.entries();
1365
- const { siteData, searchIndex, indexHashByGroup } = await createSiteData({
1366
- config,
1367
- alias: alias,
1368
- userDocRoot,
1369
- routeService,
1370
- pluginDriver
1371
- });
1372
- ref.siteData = siteData;
1373
- ref.searchIndex = searchIndex;
1374
- ref.indexHashByGroup = indexHashByGroup;
1375
- api.processAssets({
1376
- stage: 'report',
1377
- environments: [
1378
- 'web'
1379
- ]
1380
- }, ({ compilation, compiler })=>{
1381
- for (const [filename, stringifiedIndex] of Object.entries(searchIndex))compilation.emitAsset(`static/${filename}`, new compiler.webpack.sources.RawSource(stringifiedIndex));
1382
- });
1383
- });
1410
+ const siteDataVMPlugin = (context)=>{
1411
+ const { config } = context;
1412
+ return {
1413
+ ["virtual-site-data"]: async ()=>{
1414
+ const { siteData } = await createSiteData(config);
1415
+ return `export default ${JSON.stringify(siteData, null, 2)}`;
1384
1416
  }
1385
1417
  };
1386
- return [
1387
- searchIndexRsbuildPlugin,
1388
- pluginVirtualModule({
1389
- tempDir: '.rspress',
1390
- virtualModules: {
1391
- ["virtual-site-data"]: ()=>`export default ${JSON.stringify(ref.siteData, null, 2)}`,
1392
- ["virtual-search-index-hash"]: ()=>`export default ${JSON.stringify(ref.indexHashByGroup, null, 2)}`
1393
- }
1394
- })
1395
- ];
1396
1418
  };
1397
1419
  const presetIcons = {
1398
1420
  discord: '<path fill="currentColor" d="M20.317 4.37a19.8 19.8 0 0 0-4.885-1.515a.074.074 0 0 0-.079.037c-.21.375-.444.864-.608 1.25a18.3 18.3 0 0 0-5.487 0a13 13 0 0 0-.617-1.25a.08.08 0 0 0-.079-.037A19.7 19.7 0 0 0 3.677 4.37a.1.1 0 0 0-.032.027C.533 9.046-.32 13.58.099 18.057a.08.08 0 0 0 .031.057a19.9 19.9 0 0 0 5.993 3.03a.08.08 0 0 0 .084-.028a14 14 0 0 0 1.226-1.994a.076.076 0 0 0-.041-.106a13 13 0 0 1-1.872-.892a.077.077 0 0 1-.008-.128a10 10 0 0 0 .372-.292a.07.07 0 0 1 .077-.01c3.928 1.793 8.18 1.793 12.062 0a.07.07 0 0 1 .078.01q.181.149.373.292a.077.077 0 0 1-.006.127a12.3 12.3 0 0 1-1.873.892a.077.077 0 0 0-.041.107c.36.698.772 1.362 1.225 1.993a.08.08 0 0 0 .084.028a19.8 19.8 0 0 0 6.002-3.03a.08.08 0 0 0 .032-.054c.5-5.177-.838-9.674-3.549-13.66a.06.06 0 0 0-.031-.03M8.02 15.33c-1.182 0-2.157-1.085-2.157-2.419c0-1.333.956-2.419 2.157-2.419c1.21 0 2.176 1.096 2.157 2.42c0 1.333-.956 2.418-2.157 2.418m7.975 0c-1.183 0-2.157-1.085-2.157-2.419c0-1.333.955-2.419 2.157-2.419c1.21 0 2.176 1.096 2.157 2.42c0 1.333-.946 2.418-2.157 2.418"/>',
@@ -1962,7 +1984,7 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
1962
1984
  ...searchHookVMPlugin(context),
1963
1985
  ...routeListVMPlugin(context),
1964
1986
  ...await getVirtualModulesFromPlugins(pluginDriver),
1965
- ...runtimeConfigVMPlugin(context)
1987
+ ...siteDataVMPlugin(context)
1966
1988
  }
1967
1989
  }),
1968
1990
  enableSSG ? rsbuildPluginSSG({
@@ -2468,7 +2490,7 @@ Please use below:
2468
2490
  });
2469
2491
  await Promise.all(promiseList);
2470
2492
  };
2471
- function link_checkDeadLinks(checkDeadLinks, internalLinks, filePath, routeService) {
2493
+ function link_checkDeadLinks(checkDeadLinks, internalLinks, filePath) {
2472
2494
  const errorInfos = [];
2473
2495
  const excludes = 'object' == typeof checkDeadLinks ? checkDeadLinks.excludes : void 0;
2474
2496
  const excludesUrl = Array.isArray(excludes) ? new Set(excludes) : void 0;
@@ -2479,10 +2501,8 @@ function link_checkDeadLinks(checkDeadLinks, internalLinks, filePath, routeServi
2479
2501
  ].forEach(([nodeUrl, link])=>{
2480
2502
  if (excludesUrl?.has(nodeUrl)) return;
2481
2503
  if (excludesFn?.(nodeUrl)) return;
2482
- const cleanLinkPath = linkToRoutePath(link);
2483
- if (!cleanLinkPath) return;
2484
2504
  if (!nodeUrl.startsWith('/') && /^\w/.test(nodeUrl)) possibleBreakingChange = true;
2485
- if (!routeService.isExistRoute((0, shared_.removeTrailingSlash)(cleanLinkPath)) && !routeService.isExistRoute((0, shared_.addTrailingSlash)(cleanLinkPath))) errorInfos.push([
2505
+ errorInfos.push([
2486
2506
  nodeUrl,
2487
2507
  link
2488
2508
  ]);
@@ -2511,7 +2531,7 @@ function looseMarkdownLink(url, routeService, filePath) {
2511
2531
  }
2512
2532
  return url;
2513
2533
  }
2514
- function normalizeLink(nodeUrl, routeService, filePath, cleanUrls, autoPrefix, internalLinks, __base) {
2534
+ function normalizeLink(nodeUrl, routeService, filePath, cleanUrls, autoPrefix, deadLinks, __base) {
2515
2535
  if (!nodeUrl) return '';
2516
2536
  if (nodeUrl.startsWith('#')) return nodeUrl;
2517
2537
  let { url, hash } = (0, shared_.parseUrl)(nodeUrl);
@@ -2530,28 +2550,28 @@ function normalizeLink(nodeUrl, routeService, filePath, cleanUrls, autoPrefix, i
2530
2550
  url = (0, shared_.normalizeHref)(url, false);
2531
2551
  url = url.replace(/\.html$/, cleanUrls);
2532
2552
  }
2533
- internalLinks.set(nodeUrl, url);
2553
+ if (!routeService.isExistRoute(url)) {
2554
+ deadLinks.set(nodeUrl, url);
2555
+ return nodeUrl;
2556
+ }
2534
2557
  if (hash) url += `#${hash}`;
2535
2558
  if (__base) url = (0, shared_.withBase)(url, __base);
2536
2559
  return url;
2537
2560
  }
2538
- function linkToRoutePath(routePath) {
2539
- return decodeURIComponent(routePath.split('#')[0]).replace(/\.html$/, '').replace(/\/index$/, '/');
2540
- }
2541
2561
  const remarkLink = ({ cleanUrls, routeService, remarkLinkOptions, __base })=>(tree, file)=>{
2542
2562
  const { checkDeadLinks: shouldCheckDeadLinks = true, autoPrefix = true } = remarkLinkOptions ?? {};
2543
- const internalLinks = new Map();
2563
+ const deadLinks = new Map();
2544
2564
  visit(tree, 'link', (node)=>{
2545
2565
  const { url: nodeUrl } = node;
2546
- const link = normalizeLink(nodeUrl, routeService, file.path, cleanUrls, autoPrefix, internalLinks, __base);
2566
+ const link = normalizeLink(nodeUrl, routeService, file.path, cleanUrls, autoPrefix, deadLinks, __base);
2547
2567
  node.url = link;
2548
2568
  });
2549
2569
  visit(tree, 'definition', (node)=>{
2550
2570
  const { url: nodeUrl } = node;
2551
- const link = normalizeLink(nodeUrl, routeService, file.path, cleanUrls, autoPrefix, internalLinks, __base);
2571
+ const link = normalizeLink(nodeUrl, routeService, file.path, cleanUrls, autoPrefix, deadLinks, __base);
2552
2572
  node.url = link;
2553
2573
  });
2554
- if (shouldCheckDeadLinks && routeService) link_checkDeadLinks(shouldCheckDeadLinks, internalLinks, file.path, routeService);
2574
+ if (shouldCheckDeadLinks && routeService) link_checkDeadLinks(shouldCheckDeadLinks, deadLinks, file.path);
2555
2575
  };
2556
2576
  async function serve(options) {
2557
2577
  const { config, port: userPort, host: userHost, configFilePath } = options;
package/dist/loader.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { AdditionalPage } from '@rspress/shared';
2
2
  import { DefaultThemeConfig } from '@rspress/shared';
3
3
  import type { PageIndexInfo } from '@rspress/shared';
4
- import type { RouteMeta } from '@rspress/shared';
4
+ import { RouteMeta } from '@rspress/shared';
5
5
  import { Rspack as Rspack_2 } from '@rsbuild/core';
6
6
  import type { RspressPlugin } from '@rspress/shared';
7
- import type { UserConfig } from '@rspress/shared';
7
+ import { UserConfig } from '@rspress/shared';
8
8
 
9
9
  declare interface InitOptions {
10
10
  scanDir: string;
@@ -68,7 +68,7 @@ declare class RouteService {
68
68
  addRoute(routePage: RoutePage): Promise<void>;
69
69
  getRoutes(): RouteMeta[];
70
70
  getRoutePages(): RoutePage[];
71
- isExistRoute(routePath: string): boolean;
71
+ isExistRoute(link: string): boolean;
72
72
  generateRoutesCode(): string;
73
73
  private generateRoutesCodeByRouteMeta;
74
74
  getRoutePathParts(relativePath: string): string[];
@@ -1,10 +1,10 @@
1
1
  import { AdditionalPage } from '@rspress/shared';
2
2
  import { DefaultThemeConfig } from '@rspress/shared';
3
3
  import type { PageIndexInfo } from '@rspress/shared';
4
- import type { RouteMeta } from '@rspress/shared';
4
+ import { RouteMeta } from '@rspress/shared';
5
5
  import type { Rspack as Rspack_2 } from '@rsbuild/core';
6
6
  import type { RspressPlugin } from '@rspress/shared';
7
- import type { UserConfig } from '@rspress/shared';
7
+ import { UserConfig } from '@rspress/shared';
8
8
 
9
9
  export declare function compile(options: CompileOptions): Promise<string>;
10
10
 
@@ -71,7 +71,7 @@ declare class RouteService {
71
71
  addRoute(routePage: RoutePage): Promise<void>;
72
72
  getRoutes(): RouteMeta[];
73
73
  getRoutePages(): RoutePage[];
74
- isExistRoute(routePath: string): boolean;
74
+ isExistRoute(link: string): boolean;
75
75
  generateRoutesCode(): string;
76
76
  private generateRoutesCodeByRouteMeta;
77
77
  getRoutePathParts(relativePath: string): string[];
package/dist/processor.js CHANGED
@@ -13,7 +13,7 @@ import { createCssVariablesTheme } from "shiki";
13
13
  import { readFile as promises_readFile } from "node:fs/promises";
14
14
  import { logger as logger_logger } from "@rspress/shared/logger";
15
15
  import picocolors_0 from "picocolors";
16
- import { addLeadingSlash, addTrailingSlash, isExternalUrl, isProduction, normalizeHref, parseUrl, removeTrailingSlash, withBase } from "@rspress/shared";
16
+ import { addLeadingSlash, isExternalUrl, isProduction, normalizeHref, parseUrl, withBase } from "@rspress/shared";
17
17
  import { visitChildren } from "unist-util-visit-children";
18
18
  function applyReplaceRules(code = '', replaceRules = []) {
19
19
  let result = code;
@@ -510,7 +510,7 @@ function hintRelativeMarkdownLink() {
510
510
  isLogged = true;
511
511
  logger_logger.info('[Rspress v2] Markdown links without "./" prefix are now relative links, e.g: [](guide/getting-started) is equal to [](./guide/getting-started). You can rewrite it to [](/guide/getting-started) to always use absolute links, or use [](./getting-started.md)');
512
512
  }
513
- function link_checkDeadLinks(checkDeadLinks, internalLinks, filePath, routeService) {
513
+ function link_checkDeadLinks(checkDeadLinks, internalLinks, filePath) {
514
514
  const errorInfos = [];
515
515
  const excludes = 'object' == typeof checkDeadLinks ? checkDeadLinks.excludes : void 0;
516
516
  const excludesUrl = Array.isArray(excludes) ? new Set(excludes) : void 0;
@@ -521,10 +521,8 @@ function link_checkDeadLinks(checkDeadLinks, internalLinks, filePath, routeServi
521
521
  ].forEach(([nodeUrl, link])=>{
522
522
  if (excludesUrl?.has(nodeUrl)) return;
523
523
  if (excludesFn?.(nodeUrl)) return;
524
- const cleanLinkPath = linkToRoutePath(link);
525
- if (!cleanLinkPath) return;
526
524
  if (!nodeUrl.startsWith('/') && /^\w/.test(nodeUrl)) possibleBreakingChange = true;
527
- if (!routeService.isExistRoute(removeTrailingSlash(cleanLinkPath)) && !routeService.isExistRoute(addTrailingSlash(cleanLinkPath))) errorInfos.push([
525
+ errorInfos.push([
528
526
  nodeUrl,
529
527
  link
530
528
  ]);
@@ -553,7 +551,7 @@ function looseMarkdownLink(url, routeService, filePath) {
553
551
  }
554
552
  return url;
555
553
  }
556
- function normalizeLink(nodeUrl, routeService, filePath, cleanUrls, autoPrefix, internalLinks, __base) {
554
+ function normalizeLink(nodeUrl, routeService, filePath, cleanUrls, autoPrefix, deadLinks, __base) {
557
555
  if (!nodeUrl) return '';
558
556
  if (nodeUrl.startsWith('#')) return nodeUrl;
559
557
  let { url, hash } = parseUrl(nodeUrl);
@@ -572,28 +570,28 @@ function normalizeLink(nodeUrl, routeService, filePath, cleanUrls, autoPrefix, i
572
570
  url = normalizeHref(url, false);
573
571
  url = url.replace(/\.html$/, cleanUrls);
574
572
  }
575
- internalLinks.set(nodeUrl, url);
573
+ if (!routeService.isExistRoute(url)) {
574
+ deadLinks.set(nodeUrl, url);
575
+ return nodeUrl;
576
+ }
576
577
  if (hash) url += `#${hash}`;
577
578
  if (__base) url = withBase(url, __base);
578
579
  return url;
579
580
  }
580
- function linkToRoutePath(routePath) {
581
- return decodeURIComponent(routePath.split('#')[0]).replace(/\.html$/, '').replace(/\/index$/, '/');
582
- }
583
581
  const remarkLink = ({ cleanUrls, routeService, remarkLinkOptions, __base })=>(tree, file)=>{
584
582
  const { checkDeadLinks: shouldCheckDeadLinks = true, autoPrefix = true } = remarkLinkOptions ?? {};
585
- const internalLinks = new Map();
583
+ const deadLinks = new Map();
586
584
  visit(tree, 'link', (node)=>{
587
585
  const { url: nodeUrl } = node;
588
- const link = normalizeLink(nodeUrl, routeService, file.path, cleanUrls, autoPrefix, internalLinks, __base);
586
+ const link = normalizeLink(nodeUrl, routeService, file.path, cleanUrls, autoPrefix, deadLinks, __base);
589
587
  node.url = link;
590
588
  });
591
589
  visit(tree, 'definition', (node)=>{
592
590
  const { url: nodeUrl } = node;
593
- const link = normalizeLink(nodeUrl, routeService, file.path, cleanUrls, autoPrefix, internalLinks, __base);
591
+ const link = normalizeLink(nodeUrl, routeService, file.path, cleanUrls, autoPrefix, deadLinks, __base);
594
592
  node.url = link;
595
593
  });
596
- if (shouldCheckDeadLinks && routeService) link_checkDeadLinks(shouldCheckDeadLinks, internalLinks, file.path, routeService);
594
+ if (shouldCheckDeadLinks && routeService) link_checkDeadLinks(shouldCheckDeadLinks, deadLinks, file.path);
597
595
  };
598
596
  const parseToc = (tree)=>{
599
597
  let title = '';
@@ -646,7 +644,6 @@ async function createMDXOptions(options) {
646
644
  const { docDirectory, config, routeService, filepath, pluginDriver, addDependency } = options;
647
645
  const remarkLinkOptions = config?.markdown?.link;
648
646
  const format = node_path.extname(filepath).slice(1);
649
- const cleanUrls = config?.route?.cleanUrls ?? false;
650
647
  const { remarkPlugins: remarkPluginsFromConfig = [], rehypePlugins: rehypePluginsFromConfig = [], globalComponents: globalComponentsFromConfig = [], showLineNumbers = false, shiki } = config?.markdown || {};
651
648
  const rspressPlugins = pluginDriver?.getPlugins() ?? [];
652
649
  const remarkPluginsFromPlugins = rspressPlugins.flatMap((plugin)=>plugin.markdown?.remarkPlugins || []);
@@ -672,7 +669,7 @@ async function createMDXOptions(options) {
672
669
  [
673
670
  remarkLink,
674
671
  {
675
- cleanUrls,
672
+ cleanUrls: false,
676
673
  root: docDirectory,
677
674
  routeService,
678
675
  remarkLinkOptions
@@ -102,7 +102,7 @@ function hintSSGFailed() {
102
102
  1. Fix code to make it SSR-compatible.
103
103
  2. Set \`ssg: false\` if the code in node_modules may be difficult to fix, but the SSG feature will be lost.`);
104
104
  }
105
- var package_namespaceObject = JSON.parse('{"rE":"2.0.0-beta.28"}');
105
+ var package_namespaceObject = JSON.parse('{"rE":"2.0.0-beta.29"}');
106
106
  const RSPRESS_VERSION = package_namespaceObject.rE;
107
107
  `{
108
108
  const saved = localStorage.getItem('${APPEARANCE_KEY}')
@@ -1,11 +1,11 @@
1
1
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
- import { DataContext, useLocation } from "@rspress/runtime";
2
+ import { PageContext, useLocation } from "@rspress/runtime";
3
3
  import { Layout } from "@theme";
4
4
  import react, { useContext, useLayoutEffect } from "react";
5
5
  import virtual_global_components from "virtual-global-components";
6
6
  import { initPageData } from "./initPageData.js";
7
7
  function App() {
8
- const { setData: setPageData, data } = useContext(DataContext);
8
+ const { setData: setPageData, data } = useContext(PageContext);
9
9
  const { pathname, search } = useLocation();
10
10
  useLayoutEffect(()=>{
11
11
  async function refetchData() {
@@ -22,7 +22,7 @@ function App() {
22
22
  setPageData
23
23
  ]);
24
24
  if (!data) return /*#__PURE__*/ jsx(Fragment, {});
25
- const frontmatter = data.page.frontmatter || {};
25
+ const frontmatter = data.frontmatter || {};
26
26
  const GLOBAL_COMPONENTS_KEY = 'globalUIComponents';
27
27
  const query = new URLSearchParams(search);
28
28
  const hideGlobalUIComponents = false === frontmatter[GLOBAL_COMPONENTS_KEY] || "0" === query.get(GLOBAL_COMPONENTS_KEY);
@@ -1,4 +1,4 @@
1
- import type { PageData } from '@rspress/shared';
1
+ import type { Page } from './initPageData';
2
2
  export declare function ClientApp({ initialPageData, }: {
3
- initialPageData?: PageData;
3
+ initialPageData?: Page;
4
4
  }): import("react/jsx-runtime").JSX.Element;
@@ -1,9 +1,9 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- import { BrowserRouter, DataContext, ThemeContext } from "@rspress/runtime";
2
+ import { BrowserRouter, PageContext, ThemeContext } from "@rspress/runtime";
3
3
  import { useThemeState } from "@theme";
4
4
  import { UnheadProvider, createHead } from "@unhead/react/client";
5
5
  import { useMemo, useState } from "react";
6
- import { base } from "virtual-runtime-config";
6
+ import virtual_site_data from "virtual-site-data";
7
7
  import { App } from "./App.js";
8
8
  const head = createHead();
9
9
  function ClientApp({ initialPageData = null }) {
@@ -17,7 +17,7 @@ function ClientApp({ initialPageData = null }) {
17
17
  theme,
18
18
  setTheme
19
19
  ]),
20
- children: /*#__PURE__*/ jsx(DataContext.Provider, {
20
+ children: /*#__PURE__*/ jsx(PageContext.Provider, {
21
21
  value: useMemo(()=>({
22
22
  data,
23
23
  setData
@@ -30,7 +30,7 @@ function ClientApp({ initialPageData = null }) {
30
30
  v7_relativeSplatPath: true,
31
31
  v7_startTransition: true
32
32
  },
33
- basename: base,
33
+ basename: virtual_site_data.base,
34
34
  children: /*#__PURE__*/ jsx(UnheadProvider, {
35
35
  head: head,
36
36
  children: /*#__PURE__*/ jsx(App, {})
@@ -1,2 +1,3 @@
1
- import { type PageData } from '@rspress/shared';
2
- export declare function initPageData(routePath: string): Promise<PageData>;
1
+ import { type PageDataLegacy } from '@rspress/shared';
2
+ export type Page = PageDataLegacy['page'];
3
+ export declare function initPageData(routePath: string): Promise<Page>;
@@ -1,6 +1,6 @@
1
1
  import { isEqualPath, pathnameToRouteService } from "@rspress/runtime";
2
2
  import { MDX_OR_MD_REGEXP, cleanUrl } from "@rspress/shared";
3
- import { base } from "virtual-runtime-config";
3
+ import { pageData } from "virtual-page-data";
4
4
  import virtual_site_data from "virtual-site-data";
5
5
  async function initPageData(routePath) {
6
6
  const matchedRoute = pathnameToRouteService(routePath);
@@ -8,27 +8,24 @@ async function initPageData(routePath) {
8
8
  const mod = await matchedRoute.preload();
9
9
  const pagePath = cleanUrl(matchedRoute.filePath);
10
10
  const normalize = (p)=>p.replace(/\/$/, '').toLowerCase();
11
- const extractPageInfo = virtual_site_data.pages.find((page)=>isEqualPath(normalize(page.routePath), normalize(matchedRoute.path)));
11
+ const extractPageInfo = pageData.pages.find((page)=>isEqualPath(normalize(page.routePath), normalize(matchedRoute.path)));
12
12
  const encodedPagePath = encodeURIComponent(pagePath);
13
13
  const meta = mod.default.__RSPRESS_PAGE_META?.[encodedPagePath] || {};
14
14
  const { toc = [], title = '', frontmatter = {}, ...rest } = MDX_OR_MD_REGEXP.test(matchedRoute.filePath) ? meta : mod;
15
15
  return {
16
- siteData: virtual_site_data,
17
- page: {
18
- ...rest,
19
- pagePath,
20
- ...extractPageInfo,
21
- pageType: frontmatter?.pageType || 'doc',
22
- title,
23
- frontmatter,
24
- toc
25
- }
16
+ ...rest,
17
+ pagePath,
18
+ ...extractPageInfo,
19
+ pageType: frontmatter?.pageType || 'doc',
20
+ title,
21
+ frontmatter,
22
+ toc
26
23
  };
27
24
  }
28
25
  let lang = virtual_site_data.lang || '';
29
26
  let version = virtual_site_data.multiVersion?.default || '';
30
27
  if (virtual_site_data.lang && 'undefined' != typeof window) {
31
- const path = location.pathname.replace(base, '').split('/').slice(0, 2);
28
+ const path = location.pathname.replace(virtual_site_data.base, '').split('/').slice(0, 2);
32
29
  if (virtual_site_data.locales.length) {
33
30
  const result = virtual_site_data.locales.find(({ lang })=>path.includes(lang));
34
31
  if (result) lang = result.lang;
@@ -39,19 +36,16 @@ async function initPageData(routePath) {
39
36
  }
40
37
  }
41
38
  return {
42
- siteData: virtual_site_data,
43
- page: {
44
- pagePath: '',
45
- pageType: '404',
46
- routePath: '/404',
47
- lang,
48
- frontmatter: {},
49
- title: '404',
50
- toc: [],
51
- version,
52
- _filepath: '',
53
- _relativePath: ''
54
- }
39
+ pagePath: '',
40
+ pageType: '404',
41
+ routePath: '/404',
42
+ lang,
43
+ frontmatter: {},
44
+ title: '404',
45
+ toc: [],
46
+ version,
47
+ _filepath: '',
48
+ _relativePath: ''
55
49
  };
56
50
  }
57
51
  export { initPageData };
@@ -1,7 +1,5 @@
1
- import type { PageData } from '@rspress/shared';
2
1
  import { type Unhead } from '@unhead/react/server';
3
2
  export declare function render(routePath: string, head: Unhead): Promise<{
4
3
  appHtml: string;
5
- pageData: PageData;
6
4
  }>;
7
5
  export { routes } from 'virtual-routes';
@@ -1,11 +1,11 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import { PassThrough } from "node:stream";
3
3
  import { text as consumers_text } from "node:stream/consumers";
4
- import { DataContext, ThemeContext, pathnameToRouteService, withBase } from "@rspress/runtime";
4
+ import { PageContext, ThemeContext, pathnameToRouteService, withBase } from "@rspress/runtime";
5
5
  import { StaticRouter } from "@rspress/runtime/server";
6
6
  import { UnheadProvider } from "@unhead/react/server";
7
7
  import { renderToPipeableStream } from "react-dom/server";
8
- import { base } from "virtual-runtime-config";
8
+ import virtual_site_data from "virtual-site-data";
9
9
  import { App } from "./App.js";
10
10
  import { initPageData } from "./initPageData.js";
11
11
  import { routes } from "virtual-routes";
@@ -35,13 +35,13 @@ async function render(routePath, head) {
35
35
  value: {
36
36
  theme: DEFAULT_THEME
37
37
  },
38
- children: /*#__PURE__*/ jsx(DataContext.Provider, {
38
+ children: /*#__PURE__*/ jsx(PageContext.Provider, {
39
39
  value: {
40
40
  data: initialPageData
41
41
  },
42
42
  children: /*#__PURE__*/ jsx(StaticRouter, {
43
43
  location: withBase(routePath),
44
- basename: base,
44
+ basename: virtual_site_data.base,
45
45
  children: /*#__PURE__*/ jsx(UnheadProvider, {
46
46
  value: head,
47
47
  children: /*#__PURE__*/ jsx(App, {})
@@ -50,8 +50,7 @@ async function render(routePath, head) {
50
50
  })
51
51
  }));
52
52
  return {
53
- appHtml,
54
- pageData: initialPageData
53
+ appHtml
55
54
  };
56
55
  }
57
56
  export { render, routes };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspress/core",
3
- "version": "2.0.0-beta.28",
3
+ "version": "2.0.0-beta.29",
4
4
  "description": "The Rspress Documentation Framework",
5
5
  "bugs": "https://github.com/web-infra-dev/rspress/issues",
6
6
  "repository": {
@@ -53,10 +53,10 @@
53
53
  "dependencies": {
54
54
  "@mdx-js/mdx": "^3.1.0",
55
55
  "@mdx-js/react": "^3.1.0",
56
- "@rsbuild/core": "~1.4.15",
56
+ "@rsbuild/core": "~1.4.16",
57
57
  "@rsbuild/plugin-react": "~1.3.5",
58
58
  "@rspress/mdx-rs": "0.6.6",
59
- "@shikijs/rehype": "^3.9.2",
59
+ "@shikijs/rehype": "^3.11.0",
60
60
  "@types/unist": "^3.0.3",
61
61
  "@unhead/react": "^2.0.14",
62
62
  "cac": "^6.7.14",
@@ -76,31 +76,31 @@
76
76
  "rehype-external-links": "^3.0.0",
77
77
  "rehype-raw": "^7.0.0",
78
78
  "remark-gfm": "^4.0.1",
79
- "shiki": "^3.9.2",
79
+ "shiki": "^3.11.0",
80
80
  "tinyglobby": "^0.2.14",
81
81
  "tinypool": "^1.1.1",
82
82
  "unified": "^11.0.5",
83
83
  "unist-util-visit": "^5.0.0",
84
84
  "unist-util-visit-children": "^3.0.0",
85
- "@rspress/runtime": "2.0.0-beta.28",
86
- "@rspress/shared": "2.0.0-beta.28",
87
- "@rspress/theme-default": "2.0.0-beta.28"
85
+ "@rspress/runtime": "2.0.0-beta.29",
86
+ "@rspress/theme-default": "2.0.0-beta.29",
87
+ "@rspress/shared": "2.0.0-beta.29"
88
88
  },
89
89
  "devDependencies": {
90
- "@microsoft/api-extractor": "^7.52.10",
91
- "@rslib/core": "0.12.1",
90
+ "@microsoft/api-extractor": "^7.52.11",
91
+ "@rslib/core": "0.12.2",
92
92
  "@types/hast": "^3.0.4",
93
93
  "@types/html-to-text": "^9.0.4",
94
94
  "@types/jest": "~29.5.14",
95
95
  "@types/lodash-es": "^4.17.12",
96
96
  "@types/mdast": "^4.0.4",
97
97
  "@types/node": "^22.8.1",
98
- "@types/react": "^19.1.10",
98
+ "@types/react": "^19.1.11",
99
99
  "@types/react-dom": "^19.1.7",
100
100
  "execa": "8.0.1",
101
101
  "mdast-util-directive": "^3.1.0",
102
102
  "mdast-util-mdx-expression": "^2.0.1",
103
- "memfs": "^4.36.0",
103
+ "memfs": "^4.38.1",
104
104
  "p-map": "^7.0.3",
105
105
  "postcss": "8.5.6",
106
106
  "rehype-stringify": "^10.0.1",