@rspress/core 2.0.0-beta.15 → 2.0.0-beta.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -167,6 +167,8 @@ declare class RoutePage {
167
167
  export declare class RouteService {
168
168
  #private;
169
169
  routeData: Map<string, RoutePage>;
170
+ static __instance__: RouteService | null;
171
+ static getInstance(): RouteService;
170
172
  static create(options: InitOptions): Promise<RouteService>;
171
173
  constructor(scanDir: string, userConfig: UserConfig, tempDir: string, pluginDriver: PluginDriver);
172
174
  get extensions(): readonly string[];
@@ -177,7 +179,7 @@ export declare class RouteService {
177
179
  isExistRoute(routePath: string): boolean;
178
180
  generateRoutesCode(): string;
179
181
  generateRoutesCodeByRouteMeta(routeMeta: RouteMeta[]): string;
180
- getRoutePathParts(routePath: string): readonly [string, string, string];
182
+ getRoutePathParts(routePath: string): readonly [string, string, string, string];
181
183
  normalizeRoutePath(routePath: string): {
182
184
  routePath: string;
183
185
  lang: string;
@@ -186,7 +188,7 @@ export declare class RouteService {
186
188
  getRoutePageByRoutePath(routePath: string): RoutePage | undefined;
187
189
  }
188
190
 
189
- declare type RspressPluginHookKeys = 'beforeBuild' | 'afterBuild' | 'addPages' | 'addRuntimeModules' | 'routeGenerated' | 'routeServiceGenerated' | 'addSSGRoutes' | 'extendPageData' | 'modifySearchIndexData';
191
+ declare type RspressPluginHookKeys = 'beforeBuild' | 'config' | 'afterBuild' | 'addPages' | 'addRuntimeModules' | 'routeGenerated' | 'routeServiceGenerated' | 'addSSGRoutes' | 'extendPageData' | 'modifySearchIndexData';
190
192
 
191
193
  export declare function serve(options: ServeOptions): Promise<ReturnType<RsbuildInstance['preview']>>;
192
194
 
package/dist/index.js CHANGED
@@ -1,18 +1,18 @@
1
1
  import __rslib_shim_module__ from 'module';
2
2
  const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(import.meta.url);
3
3
  import { pluginContainerSyntax } from "@rspress/plugin-container-syntax";
4
- import node_fs_promises, { mkdir, readFile, rm, writeFile } from "node:fs/promises";
5
- import node_path, { extname as external_node_path_extname, join } from "node:path";
4
+ import node_fs_promises, { mkdir, readFile, readdir, rm, stat as promises_stat, writeFile } from "node:fs/promises";
5
+ import node_path, { dirname, extname as external_node_path_extname, join, relative } from "node:path";
6
6
  import { fileURLToPath, pathToFileURL } from "node:url";
7
7
  import { PLUGIN_REACT_NAME, pluginReact } from "@rsbuild/plugin-react";
8
8
  import { APPEARANCE_KEY, MDX_OR_MD_REGEXP, RSPRESS_TEMP_DIR, SEARCH_INDEX_NAME, addLeadingSlash, addTrailingSlash, isDebugMode, isExternalUrl, isSCM, normalizeHref, normalizeSlash, parseUrl, removeLeadingSlash, removeTrailingSlash, slash, withBase, withoutBase } from "@rspress/shared";
9
+ import { DEFAULT_PAGE_EXTENSIONS } from "@rspress/shared/constants";
9
10
  import { logger } from "@rspress/shared/logger";
10
11
  import picocolors from "picocolors";
11
- import { DEFAULT_PAGE_EXTENSIONS } from "@rspress/shared/constants";
12
- import { glob } from "tinyglobby";
13
12
  import node_os from "node:os";
13
+ import { glob } from "tinyglobby";
14
+ import { extractTextAndId, getIconUrlPath, getNodeAttribute, loadFrontMatter, mergeDocConfig } from "@rspress/shared/node-utils";
14
15
  import { RspackVirtualModulePlugin } from "rspack-plugin-virtual-module";
15
- import { getIconUrlPath, getNodeAttribute, loadFrontMatter, mergeDocConfig } from "@rspress/shared/node-utils";
16
16
  import { groupBy } from "lodash-es";
17
17
  import { compile } from "@rspress/mdx-rs";
18
18
  import { htmlToText } from "html-to-text";
@@ -39,7 +39,6 @@ class PluginDriver {
39
39
  const themeConfig = config?.themeConfig || {};
40
40
  const enableLastUpdated = themeConfig?.lastUpdated || themeConfig?.locales?.some((locale)=>locale.lastUpdated);
41
41
  const mediumZoomConfig = config?.mediumZoom ?? true;
42
- const haveNavSidebarConfig = themeConfig.nav || themeConfig.sidebar || themeConfig.locales?.[0]?.nav || themeConfig.locales?.[0]?.sidebar;
43
42
  if (enableLastUpdated) {
44
43
  const { pluginLastUpdated } = await import("@rspress/plugin-last-updated");
45
44
  this.addPlugin(pluginLastUpdated());
@@ -52,10 +51,6 @@ class PluginDriver {
52
51
  (config.plugins || []).forEach((plugin)=>{
53
52
  this.addPlugin(plugin);
54
53
  });
55
- if (!haveNavSidebarConfig) {
56
- const { pluginAutoNavSidebar } = await import("@rspress/plugin-auto-nav-sidebar");
57
- this.addPlugin(pluginAutoNavSidebar());
58
- }
59
54
  }
60
55
  addPlugin(plugin) {
61
56
  const existedIndex = this.#plugins.findIndex((item)=>item.name === plugin.name);
@@ -163,10 +158,13 @@ const pluginVirtualModule = (pluginOptions = {})=>({
163
158
  ];
164
159
  });
165
160
  api.onBeforeCreateCompiler(async ()=>{
166
- await mkdir(TEMP_DIR, {
167
- recursive: true
168
- });
169
- await Promise.all(virtualFileAbsolutePaths.map(([_, absolutePath])=>writeFile(absolutePath, '', 'utf-8')));
161
+ await Promise.all(virtualFileAbsolutePaths.map(async ([_, absolutePath])=>{
162
+ const dir = dirname(absolutePath);
163
+ await mkdir(dir, {
164
+ recursive: true
165
+ });
166
+ return writeFile(absolutePath, '', 'utf-8');
167
+ }));
170
168
  });
171
169
  api.modifyBundlerChain((chain)=>{
172
170
  chain.resolve.alias.merge(Object.fromEntries(virtualFileAbsolutePaths));
@@ -179,31 +177,6 @@ const pluginVirtualModule = (pluginOptions = {})=>({
179
177
  }
180
178
  }
181
179
  });
182
- var package_namespaceObject = JSON.parse('{"i8":"2.0.0-beta.15"}');
183
- const RSPRESS_VERSION = package_namespaceObject.i8;
184
- const isProduction = ()=>'production' === process.env.NODE_ENV;
185
- const importStatementRegex = /import\s+(.*?)\s+from\s+(['"])(.*?)(?:"|');?/gm;
186
- const inlineThemeScript = `{
187
- const saved = localStorage.getItem('${APPEARANCE_KEY}')
188
- const preferDark = window.matchMedia('(prefers-color-scheme: dark)').matches
189
- const isDark = !saved || saved === 'auto' ? preferDark : saved === 'dark'
190
- document.documentElement.classList.toggle('dark', isDark)
191
- document.documentElement.classList.toggle('rp-dark', isDark)
192
- document.documentElement.style.colorScheme = isDark ? 'dark' : 'light'
193
- }`.replace(/\n/g, ';').replace(/\s{2,}/g, '');
194
- const dirname = node_path.dirname(fileURLToPath(new URL(import.meta.url)));
195
- const PACKAGE_ROOT = node_path.join(dirname, '..');
196
- const TEMPLATE_PATH = node_path.join(PACKAGE_ROOT, 'index.html');
197
- const CSR_CLIENT_ENTRY = node_path.join(PACKAGE_ROOT, 'dist', 'runtime', 'csrClientEntry.js');
198
- const SSR_CLIENT_ENTRY = node_path.join(PACKAGE_ROOT, 'dist', 'runtime', 'ssrClientEntry.js');
199
- const SSR_SERVER_ENTRY = node_path.join(PACKAGE_ROOT, 'dist', 'runtime', 'ssrServerEntry.js');
200
- const OUTPUT_DIR = 'doc_build';
201
- const APP_HTML_MARKER = '<!--<?- DOC_CONTENT ?>-->';
202
- const HEAD_MARKER = '<!--<?- HEAD ?>-->';
203
- const META_GENERATOR = '<!--<?- GENERATOR ?>-->';
204
- const DEFAULT_TITLE = 'Rspress';
205
- const PUBLIC_DIR = 'public';
206
- const constants_TEMP_DIR = node_path.join(process.cwd(), 'node_modules', RSPRESS_TEMP_DIR);
207
180
  async function pathExists(path) {
208
181
  try {
209
182
  await node_fs_promises.access(path);
@@ -259,13 +232,42 @@ function hintSSGFalse() {
259
232
  function hintReactVersion() {
260
233
  logger.info('[Rspress v2] Rspress support React 18 and 19, please confirm that both react and react-dom are installed in package.json with the same version. ');
261
234
  }
262
- const isWindows = 'win32' === node_os.platform();
263
- function normalizePath_slash(p) {
264
- return p.replace(/\\/g, '/');
265
- }
266
- function normalizePath(id) {
267
- return node_path.posix.normalize(isWindows ? normalizePath_slash(id) : id);
235
+ function hintNavJsonChangeThenPanic(metaJson, metaJsonDir, docsDir) {
236
+ if (metaJson.some((i)=>'object' == typeof i && ('activeMatch' in i || 'text' in i || 'link' in i || 'items' in i || 'icon' in i || 'ariaLabel' in i || 'target' in i))) {
237
+ const error = new Error('[Rspress v2] Detected that you are still using top level `_meta.json` to configure the nav, but it has been changed to `_nav.json` in Rspress v2. Please rename the top level `_meta.json` to `_nav.json` accordingly.');
238
+ logger.error(error);
239
+ const dir = relative(docsDir, metaJsonDir);
240
+ logger.info(`Please rename "${picocolors.greenBright(join(dir, '_meta.json'))}" to "${picocolors.greenBright(join(dir, '_nav.json'))}".`);
241
+ process.exit(1);
242
+ }
268
243
  }
244
+ var package_namespaceObject = JSON.parse('{"i8":"2.0.0-beta.17"}');
245
+ const RSPRESS_VERSION = package_namespaceObject.i8;
246
+ const isProduction = ()=>'production' === process.env.NODE_ENV;
247
+ const importStatementRegex = /import\s+(.*?)\s+from\s+(['"])(.*?)(?:"|');?/gm;
248
+ const inlineThemeScript = `{
249
+ const saved = localStorage.getItem('${APPEARANCE_KEY}')
250
+ const preferDark = window.matchMedia('(prefers-color-scheme: dark)').matches
251
+ const isDark = !saved || saved === 'auto' ? preferDark : saved === 'dark'
252
+ document.documentElement.classList.toggle('dark', isDark)
253
+ document.documentElement.classList.toggle('rp-dark', isDark)
254
+ document.documentElement.style.colorScheme = isDark ? 'dark' : 'light'
255
+ }`.replace(/\n/g, ';').replace(/\s{2,}/g, '');
256
+ const constants_dirname = node_path.dirname(fileURLToPath(new URL(import.meta.url)));
257
+ const PACKAGE_ROOT = node_path.join(constants_dirname, '..');
258
+ const TEMPLATE_PATH = node_path.join(PACKAGE_ROOT, 'index.html');
259
+ const CSR_CLIENT_ENTRY = node_path.join(PACKAGE_ROOT, 'dist', 'runtime', 'csrClientEntry.js');
260
+ const SSR_CLIENT_ENTRY = node_path.join(PACKAGE_ROOT, 'dist', 'runtime', 'ssrClientEntry.js');
261
+ const SSR_SERVER_ENTRY = node_path.join(PACKAGE_ROOT, 'dist', 'runtime', 'ssrServerEntry.js');
262
+ const OUTPUT_DIR = 'doc_build';
263
+ const APP_HTML_MARKER = '<!--<?- DOC_CONTENT ?>-->';
264
+ const HEAD_MARKER = '<!--<?- HEAD ?>-->';
265
+ const META_GENERATOR = '<!--<?- GENERATOR ?>-->';
266
+ const DEFAULT_TITLE = 'Rspress';
267
+ const PUBLIC_DIR = 'public';
268
+ const constants_TEMP_DIR = node_path.join(process.cwd(), 'node_modules', RSPRESS_TEMP_DIR);
269
+ const NODE_SSG_BUNDLE_FOLDER = '__ssg__';
270
+ const NODE_SSG_BUNDLE_NAME = 'rspress-ssg-entry.cjs';
269
271
  function getPageKey(route) {
270
272
  const cleanRoute = removeLeadingSlash(route);
271
273
  return cleanRoute.replace(/\//g, '_').replace(/\.[^.]+$/, '') || 'index';
@@ -279,7 +281,7 @@ class RoutePage {
279
281
  this.routeMeta = routeMeta;
280
282
  }
281
283
  }
282
- const getRoutePathParts = (routePath, lang, version, langs, versions)=>{
284
+ const getRoutePathParts = (routePath, base, lang, version, langs, versions)=>{
283
285
  const hasTrailSlash = routePath.endsWith('/');
284
286
  let versionPart = '';
285
287
  let langPart = '';
@@ -301,13 +303,14 @@ const getRoutePathParts = (routePath, lang, version, langs, versions)=>{
301
303
  }
302
304
  purePathPart = parts.join('/');
303
305
  return [
306
+ base,
304
307
  versionPart,
305
308
  langPart,
306
309
  hasTrailSlash ? addTrailingSlash(purePathPart) : purePathPart
307
310
  ];
308
311
  };
309
312
  const normalizeRoutePath = (routePath, base, lang, version, langs, versions, extensions = DEFAULT_PAGE_EXTENSIONS)=>{
310
- const [versionPart, langPart, purePathPart] = getRoutePathParts(routePath, lang, version, langs, versions);
313
+ const [_, versionPart, langPart, purePathPart] = getRoutePathParts(routePath, base, lang, version, langs, versions);
311
314
  const extensionsWithoutDot = extensions.map((i)=>i.slice(1));
312
315
  const cleanExtensionPattern = new RegExp(`\\.(${extensionsWithoutDot.join('|')})$`, 'i');
313
316
  const normalizedRoutePath = addLeadingSlash([
@@ -333,11 +336,16 @@ class RouteService {
333
336
  #base = '';
334
337
  #tempDir = '';
335
338
  #pluginDriver;
339
+ static __instance__ = null;
340
+ static getInstance() {
341
+ return RouteService.__instance__;
342
+ }
336
343
  static async create(options) {
337
344
  const { scanDir, config, runtimeTempDir, pluginDriver } = options;
338
345
  const routeService = new RouteService(scanDir, config, runtimeTempDir, pluginDriver);
339
346
  await routeService.#init();
340
347
  await pluginDriver.routeServiceGenerated(routeService);
348
+ RouteService.__instance__ = routeService;
341
349
  return routeService;
342
350
  }
343
351
  constructor(scanDir, userConfig, tempDir, pluginDriver){
@@ -448,7 +456,7 @@ ${routeMeta.map((route, index)=>{
448
456
  `;
449
457
  }
450
458
  getRoutePathParts(routePath) {
451
- return getRoutePathParts(routePath, this.#defaultLang, this.#defaultVersion, this.#langs, this.#versions);
459
+ return getRoutePathParts(routePath, this.#base, this.#defaultLang, this.#defaultVersion, this.#langs, this.#versions);
452
460
  }
453
461
  normalizeRoutePath(routePath) {
454
462
  return normalizeRoutePath(routePath, this.#base, this.#defaultLang, this.#defaultVersion, this.#langs, this.#versions, this.#extensions);
@@ -473,6 +481,334 @@ ${routeMeta.map((route, index)=>{
473
481
  return this.routeData.get(routePath);
474
482
  }
475
483
  }
484
+ const isWindows = 'win32' === node_os.platform();
485
+ function normalizePath_slash(p) {
486
+ return p.replace(/\\/g, '/');
487
+ }
488
+ function normalizePath(id) {
489
+ return node_path.posix.normalize(isWindows ? normalizePath_slash(id) : id);
490
+ }
491
+ function absolutePathToLink(absolutePath, docsDir) {
492
+ const relativePath = normalizePath_slash(node_path.relative(docsDir, absolutePath.replace(node_path.extname(absolutePath), '')));
493
+ const routeService = RouteService.getInstance();
494
+ return routeService.normalizeRoutePath(relativePath).routePath;
495
+ }
496
+ function absolutePathToRoutePrefix(absolutePath, docsDir) {
497
+ const relativePath = normalizePath_slash(node_path.relative(docsDir, absolutePath.replace(node_path.extname(absolutePath), '')));
498
+ const routeService = RouteService.getInstance();
499
+ const [basePrefix, versionPrefix, langPrefix] = routeService.getRoutePathParts(relativePath);
500
+ return `${basePrefix}${versionPrefix ? `/${versionPrefix}` : ''}${langPrefix ? `/${langPrefix}` : ''}`;
501
+ }
502
+ function addRoutePrefix(workDir, docsDir, link) {
503
+ const routePrefix = absolutePathToRoutePrefix(workDir, docsDir);
504
+ return `${routePrefix.replace(/\/$/, '')}/${link.replace(/^\//, '')}`;
505
+ }
506
+ async function utils_pathExists(path) {
507
+ try {
508
+ await node_fs_promises.access(path);
509
+ return true;
510
+ } catch {
511
+ return false;
512
+ }
513
+ }
514
+ async function utils_readJson(path) {
515
+ const raw = await node_fs_promises.readFile(path, 'utf8');
516
+ return JSON.parse(raw);
517
+ }
518
+ async function extractInfoFromFrontmatterWithAbsolutePath(absolutePath, rootDir) {
519
+ const content = await node_fs_promises.readFile(absolutePath, 'utf-8');
520
+ const fileNameWithoutExt = node_path.basename(absolutePath, node_path.extname(absolutePath));
521
+ const h1RegExp = /^#\s+(.*)$/m;
522
+ const match = content.match(h1RegExp);
523
+ const { frontmatter } = loadFrontMatter(content, absolutePath, rootDir);
524
+ return {
525
+ title: extractTextAndId(frontmatter.title || match?.[1] || fileNameWithoutExt)[0],
526
+ overviewHeaders: frontmatter.overviewHeaders,
527
+ context: frontmatter.context
528
+ };
529
+ }
530
+ function getHmrFileKey(realPath, docsDir) {
531
+ return realPath ? slash(relative(docsDir, realPath).replace(external_node_path_extname(realPath), '')) : '';
532
+ }
533
+ async function fsDirToMetaItems(workDir, extensions) {
534
+ let subItems = await readdir(workDir);
535
+ subItems = subItems.filter((item)=>{
536
+ const hasExtension = extensions.some((ext)=>item.endsWith(ext));
537
+ const hasSameBaseName = subItems.some((elem)=>{
538
+ const baseName = elem.replace(/\.[^/.]+$/, '');
539
+ return baseName === item.replace(/\.[^/.]+$/, '') && elem !== item;
540
+ });
541
+ return !(hasExtension && hasSameBaseName);
542
+ });
543
+ const sideMeta = (await Promise.all(subItems.map(async (item)=>{
544
+ if ('_meta.json' === item) return null;
545
+ const stat = await promises_stat(join(workDir, item));
546
+ if (stat.isDirectory()) return {
547
+ type: 'dir',
548
+ name: item
549
+ };
550
+ return extensions.some((ext)=>item.endsWith(ext)) ? item : null;
551
+ }))).filter(Boolean);
552
+ return sideMeta;
553
+ }
554
+ async function metaItemToSidebarItem(metaItem, workDir, docsDir, extensions, isFirstDir = false) {
555
+ if ('string' == typeof metaItem) return metaFileItemToSidebarItem(metaItem, workDir, docsDir, extensions);
556
+ const { type } = metaItem;
557
+ if ('file' === type) return metaFileItemToSidebarItem(metaItem, workDir, docsDir, extensions);
558
+ if ('dir' === type) {
559
+ const { name, label, collapsible, collapsed, tag: metaJsonTag, context: metaJsonContext, overviewHeaders: metaJsonOverviewHeaders } = metaItem;
560
+ const dirAbsolutePath = join(workDir, name);
561
+ const dirMetaJsonPath = join(dirAbsolutePath, '_meta.json');
562
+ const isMetaJsonExist = await utils_pathExists(dirMetaJsonPath);
563
+ let dirMetaJson = [];
564
+ dirMetaJson = isMetaJsonExist ? await utils_readJson(dirMetaJsonPath) : await fsDirToMetaItems(dirAbsolutePath, extensions);
565
+ async function getItems(withoutIndex = false) {
566
+ const items = await Promise.all((withoutIndex ? dirMetaJson.filter((i)=>{
567
+ let name;
568
+ if ('object' == typeof i && 'type' in i && 'file' === i.type) name = i.name;
569
+ else {
570
+ if ('string' != typeof i) return true;
571
+ name = i;
572
+ }
573
+ return 'index.md' !== name && 'index.mdx' !== i && 'index' !== i;
574
+ }) : dirMetaJson).map((item)=>metaItemToSidebarItem(item, dirAbsolutePath, docsDir, extensions)));
575
+ return items;
576
+ }
577
+ try {
578
+ const sameNameFile = await metaFileItemToSidebarItem(name, workDir, docsDir, extensions);
579
+ const { link, text, _fileKey, context, overviewHeaders, tag } = sameNameFile;
580
+ return {
581
+ text: label || text || name,
582
+ collapsible,
583
+ collapsed,
584
+ items: await getItems(),
585
+ link,
586
+ tag: metaJsonTag || tag,
587
+ overviewHeaders: metaJsonOverviewHeaders || overviewHeaders,
588
+ context: metaJsonContext || context,
589
+ _fileKey
590
+ };
591
+ } catch (e) {
592
+ logger.debug(e);
593
+ const isIndexInMetaJsonIndex = dirMetaJson.find((i)=>{
594
+ if ('string' == typeof i) return 'index' === i.replace(external_node_path_extname(i), '');
595
+ return false;
596
+ });
597
+ const isIndexFileExists = await utils_pathExists(join(dirAbsolutePath, 'index.mdx')) || await utils_pathExists(join(dirAbsolutePath, 'index.md'));
598
+ if (isMetaJsonExist && isIndexInMetaJsonIndex || !isIndexFileExists) return {
599
+ text: label || name,
600
+ collapsible,
601
+ collapsed,
602
+ items: await getItems(),
603
+ link: void 0,
604
+ tag: metaJsonTag,
605
+ overviewHeaders: metaJsonOverviewHeaders,
606
+ context: metaJsonContext,
607
+ _fileKey: getHmrFileKey(dirAbsolutePath, docsDir)
608
+ };
609
+ {
610
+ const indexFile = await metaFileItemToSidebarItem('index', dirAbsolutePath, docsDir, extensions);
611
+ const { link, text, _fileKey, context, overviewHeaders, tag } = indexFile;
612
+ return {
613
+ text: label || text || name,
614
+ collapsible,
615
+ collapsed,
616
+ items: await getItems(!isFirstDir),
617
+ link,
618
+ tag: metaJsonTag || tag,
619
+ overviewHeaders: metaJsonOverviewHeaders || overviewHeaders,
620
+ context: metaJsonContext || context,
621
+ _fileKey
622
+ };
623
+ }
624
+ }
625
+ }
626
+ if ('custom-link' === type) return metaCustomLinkItemToSidebarItem(metaItem, workDir, docsDir);
627
+ if ('divider' === type || 'section-header' === type) return metaDividerToSidebarItem(metaItem);
628
+ throw new Error(`Unknown meta item type: ${metaItem.type}, please check it in "${join(workDir, '_meta.json')}".`);
629
+ }
630
+ async function detectFilePath(absolutePath, extensions) {
631
+ const ext = external_node_path_extname(absolutePath);
632
+ if (ext && extensions.includes(ext)) return absolutePath;
633
+ for (const extension of extensions){
634
+ const realPath = absolutePath + extension;
635
+ if (await utils_pathExists(realPath)) return realPath;
636
+ }
637
+ throw new Error(`The file extension "${ext}" is not supported, please use one of the following extensions: ${extensions.join(', ')}`);
638
+ }
639
+ async function metaFileItemToSidebarItem(metaItemRaw, workDir, docsDir, extensions) {
640
+ let metaItem = null;
641
+ metaItem = 'string' == typeof metaItemRaw ? {
642
+ name: metaItemRaw,
643
+ type: 'file'
644
+ } : metaItemRaw;
645
+ const { name, context, label, overviewHeaders, tag } = metaItem;
646
+ if ('string' != typeof name) throw new Error(`The file name "${name}" is not a string, please check it in "${join(workDir, '_meta.json')}".`);
647
+ const absolutePath = join(workDir, name);
648
+ let absolutePathWithExt;
649
+ try {
650
+ absolutePathWithExt = await detectFilePath(absolutePath, extensions);
651
+ } catch {
652
+ throw new Error(`The file "${absolutePath}" does not exist, please check it in "${join(workDir, '_meta.json')}".`);
653
+ }
654
+ const link = absolutePathToLink(absolutePathWithExt, docsDir);
655
+ const info = await extractInfoFromFrontmatterWithAbsolutePath(absolutePathWithExt, docsDir);
656
+ const title = label || info.title;
657
+ return {
658
+ text: title,
659
+ link,
660
+ tag,
661
+ overviewHeaders: info.overviewHeaders || overviewHeaders,
662
+ context: info.context || context,
663
+ _fileKey: getHmrFileKey(absolutePathWithExt, docsDir)
664
+ };
665
+ }
666
+ function metaCustomLinkItemToSidebarItem(metaItem, workDir, docsDir) {
667
+ const { label, link, context, tag } = metaItem;
668
+ if (void 0 === link) throw new Error(`The custom link "${label}" does not have a link, please check it in "${join(workDir, '_meta.json')}".`);
669
+ if (isExternalUrl(link)) return {
670
+ text: label ?? link,
671
+ link,
672
+ tag,
673
+ context
674
+ };
675
+ return {
676
+ text: label ?? link,
677
+ link: addRoutePrefix(workDir, docsDir, link),
678
+ tag,
679
+ context
680
+ };
681
+ }
682
+ function metaDividerToSidebarItem(metaItem) {
683
+ const { type } = metaItem;
684
+ if ('divider' === type) {
685
+ const { dashed } = metaItem;
686
+ return {
687
+ dividerType: dashed ? 'dashed' : 'solid'
688
+ };
689
+ }
690
+ const { label, tag } = metaItem;
691
+ return {
692
+ sectionHeaderText: label ?? '',
693
+ tag
694
+ };
695
+ }
696
+ async function scanSideMeta(workDir, docsDir, extensions) {
697
+ const dir = await metaItemToSidebarItem({
698
+ type: 'dir',
699
+ name: ''
700
+ }, workDir, docsDir, extensions, true);
701
+ return dir.items;
702
+ }
703
+ async function scanNav(workDir, docsDir) {
704
+ let navConfig;
705
+ const rootNavJson = node_path.resolve(workDir, '_nav.json');
706
+ try {
707
+ navConfig = await utils_readJson(rootNavJson);
708
+ } catch (e) {
709
+ logger.error('[auto-nav-sidebar]', `Generate nav meta error: ${rootNavJson} failed`);
710
+ navConfig = [];
711
+ }
712
+ navConfig.forEach((navItem)=>{
713
+ if ('items' in navItem) navItem.items.forEach((item)=>{
714
+ if ('link' in item && !isExternalUrl(item.link)) item.link = addRoutePrefix(workDir, docsDir, item.link);
715
+ });
716
+ if ('link' in navItem && !isExternalUrl(navItem.link)) navItem.link = addRoutePrefix(workDir, docsDir, navItem.link);
717
+ });
718
+ return navConfig;
719
+ }
720
+ async function walk(workDir, docsDir, extensions) {
721
+ const rootNavJson = node_path.resolve(workDir, '_nav.json');
722
+ const rootMetaJson = node_path.resolve(workDir, '_meta.json');
723
+ const isRootNavJsonExist = await pathExists(rootNavJson);
724
+ const isRootMetaJsonExist = await pathExists(rootMetaJson);
725
+ if (isRootMetaJsonExist) {
726
+ const metaConfig = await utils_readJson(rootMetaJson);
727
+ hintNavJsonChangeThenPanic(metaConfig, workDir, docsDir);
728
+ }
729
+ if (isRootNavJsonExist) {
730
+ const navConfig = await scanNav(workDir, docsDir);
731
+ const subDirs = (await Promise.all((await node_fs_promises.readdir(workDir)).map((v)=>node_fs_promises.stat(node_path.join(workDir, v)).then((s)=>{
732
+ if (s.isDirectory() && 'node_modules' !== v) return v;
733
+ return false;
734
+ })))).filter(Boolean);
735
+ const sidebarConfig = {};
736
+ await Promise.all(subDirs.map(async (subDir)=>{
737
+ const sidebarGroupKey = addRoutePrefix(workDir, docsDir, subDir);
738
+ sidebarConfig[sidebarGroupKey] = await scanSideMeta(node_path.join(workDir, subDir), docsDir, extensions);
739
+ }));
740
+ if (isRootMetaJsonExist) {
741
+ const rootMetaConfig = await scanSideMeta(workDir, docsDir, extensions);
742
+ sidebarConfig['/'] = rootMetaConfig;
743
+ }
744
+ return {
745
+ nav: navConfig,
746
+ sidebar: sidebarConfig
747
+ };
748
+ }
749
+ return {
750
+ nav: [],
751
+ sidebar: {
752
+ '/': await scanSideMeta(workDir, docsDir, extensions)
753
+ }
754
+ };
755
+ }
756
+ function combineWalkResult(walks, versions) {
757
+ return walks.reduce((acc, cur, curIndex)=>({
758
+ nav: {
759
+ ...acc.nav,
760
+ [versions[curIndex] || 'default']: cur.nav
761
+ },
762
+ sidebar: {
763
+ ...acc.sidebar,
764
+ ...cur.sidebar
765
+ }
766
+ }), {
767
+ nav: {},
768
+ sidebar: {}
769
+ });
770
+ }
771
+ function processLocales(langs, versions, root, extensions) {
772
+ return Promise.all(langs.map(async (lang)=>{
773
+ const walks = versions.length ? await Promise.all(versions.map((version)=>walk(node_path.join(root, version, lang), root, extensions))) : [
774
+ await walk(node_path.join(root, lang), root, extensions)
775
+ ];
776
+ return combineWalkResult(walks, versions);
777
+ }));
778
+ }
779
+ async function modifyConfigWithAutoNavSide(config) {
780
+ const themeConfig = config.themeConfig || {};
781
+ const haveNavSidebarConfig = themeConfig.nav || themeConfig.sidebar || themeConfig.locales?.[0]?.nav || themeConfig.locales?.[0]?.sidebar;
782
+ if (haveNavSidebarConfig) return config;
783
+ config.themeConfig = config.themeConfig || {};
784
+ config.themeConfig.locales = config.themeConfig.locales || config.locales || [];
785
+ const langs = config.themeConfig.locales.map((locale)=>locale.lang);
786
+ const hasLocales = langs.length > 0;
787
+ const hasLang = Boolean(config.lang);
788
+ const versions = config.multiVersion?.versions || [];
789
+ const { extensions = DEFAULT_PAGE_EXTENSIONS } = config?.route || {};
790
+ if (hasLocales) {
791
+ const metaInfo = await processLocales(langs, versions, config.root, extensions);
792
+ config.themeConfig.locales = config.themeConfig.locales.map((item, index)=>({
793
+ ...item,
794
+ ...metaInfo[index]
795
+ }));
796
+ } else {
797
+ if (hasLang) {
798
+ logger.error("`lang` is configured but `locales` not, thus `auto-nav-sidebar` can not auto generate navbar level config correctly!\nplease check your config file");
799
+ return config;
800
+ }
801
+ const walks = versions.length ? await Promise.all(versions.map((version)=>walk(node_path.join(config.root, version), config.root, extensions))) : [
802
+ await walk(config.root, config.root, extensions)
803
+ ];
804
+ const combined = combineWalkResult(walks, versions);
805
+ config.themeConfig = {
806
+ ...config.themeConfig,
807
+ ...combined
808
+ };
809
+ }
810
+ return config;
811
+ }
476
812
  let flattenMdxContent_resolver;
477
813
  let startFlatten = false;
478
814
  const processor = createProcessor();
@@ -696,7 +1032,7 @@ const i18nVMPlugin = (context)=>{
696
1032
  }
697
1033
  };
698
1034
  };
699
- function normalizeThemeConfig(docConfig, pages = []) {
1035
+ function normalizeThemeConfig(docConfig) {
700
1036
  const { locales: siteLocales, base = '', lang, replaceRules = [], multiVersion } = docConfig;
701
1037
  const { versions = [] } = multiVersion || {};
702
1038
  const hasMultiVersion = versions.length > 0;
@@ -731,15 +1067,6 @@ function normalizeThemeConfig(docConfig, pages = []) {
731
1067
  tag: item.tag,
732
1068
  items: item.items.map((subItem)=>normalizeSidebarItem(subItem))
733
1069
  };
734
- if ('string' == typeof item) {
735
- const normalizedItem = normalizeLinkPrefix(item, currentLang);
736
- const page = pages.find((page)=>page.routePath === withBase(normalizedItem, base));
737
- return {
738
- text: applyReplaceRules(page?.title || '', replaceRules),
739
- link: normalizedItem,
740
- _fileKey: page?._relativePath.replace(node_path.extname(page._relativePath), '')
741
- };
742
- }
743
1070
  return {
744
1071
  ...item,
745
1072
  text: applyReplaceRules(getI18nText(item.text, currentLang), replaceRules),
@@ -850,7 +1177,7 @@ async function siteDataVMPlugin(context) {
850
1177
  description: userConfig?.description || '',
851
1178
  icon: getIconUrlPath(userConfig?.icon) || '',
852
1179
  route: userConfig?.route || {},
853
- themeConfig: normalizeThemeConfig(userConfig, pages),
1180
+ themeConfig: normalizeThemeConfig(userConfig),
854
1181
  base: userConfig?.base || '/',
855
1182
  lang: userConfig?.lang || '',
856
1183
  locales: userConfig?.locales || userConfig.themeConfig?.locales || [],
@@ -1193,7 +1520,6 @@ async function renderPages(routeService, config, pluginDriver, ssrBundlePath, ht
1193
1520
  throw e;
1194
1521
  }
1195
1522
  }
1196
- const NODE_SSR_BUNDLE_NAME = 'rspress-ssg-entry.cjs';
1197
1523
  const rsbuildPluginSSG = ({ routeService, config, pluginDriver })=>({
1198
1524
  name: 'rspress-inner-rsbuild-plugin-ssg',
1199
1525
  async setup (api) {
@@ -1205,7 +1531,8 @@ const rsbuildPluginSSG = ({ routeService, config, pluginDriver })=>({
1205
1531
  targets: [
1206
1532
  'web'
1207
1533
  ]
1208
- }, ({ assets, compilation })=>{
1534
+ }, ({ assets, compilation, environment })=>{
1535
+ if ('web' !== environment.name) return;
1209
1536
  for (const [assetName, assetSource] of Object.entries(assets))if ('index.html' === assetName) {
1210
1537
  htmlTemplate = assetSource.source().toString();
1211
1538
  compilation.deleteAsset(assetName);
@@ -1226,23 +1553,28 @@ const rsbuildPluginSSG = ({ routeService, config, pluginDriver })=>({
1226
1553
  'node'
1227
1554
  ]
1228
1555
  }, async ({ assets, compilation, environment, compiler })=>{
1556
+ if ('node' !== environment.name) return;
1229
1557
  const distPath = environment.distPath;
1230
- await mkdir(distPath, {
1558
+ const ssgFolderPath = join(distPath, NODE_SSG_BUNDLE_FOLDER);
1559
+ const mainCjsAbsolutePath = join(ssgFolderPath, NODE_SSG_BUNDLE_NAME);
1560
+ await mkdir(ssgFolderPath, {
1231
1561
  recursive: true
1232
1562
  });
1233
- let mainCjsAbsolutePath = '';
1234
- for (const [assetName, assetSource] of Object.entries(assets))if (assetName.includes(NODE_SSR_BUNDLE_NAME)) {
1235
- mainCjsAbsolutePath = join(distPath, assetName);
1236
- await writeFile(mainCjsAbsolutePath, assetSource.source().toString());
1237
- compilation.deleteAsset(assetName);
1238
- break;
1239
- }
1563
+ await Promise.all(Object.entries(assets).map(async ([assetName, assetSource])=>{
1564
+ if (assetName.startsWith(`${NODE_SSG_BUNDLE_FOLDER}/`)) {
1565
+ const fileAbsolutePath = join(distPath, assetName);
1566
+ await writeFile(fileAbsolutePath, assetSource.source().toString());
1567
+ compilation.deleteAsset(assetName);
1568
+ }
1569
+ }));
1240
1570
  const emitAsset = (assetName, content)=>{
1241
1571
  compilation.emitAsset(assetName, new compiler.webpack.sources.RawSource(content));
1242
1572
  };
1243
1573
  await indexHtmlEmittedInWeb;
1244
1574
  await renderPages(routeService, config, pluginDriver, mainCjsAbsolutePath, htmlTemplate, emitAsset);
1245
- if (!isDebugMode()) await rm(mainCjsAbsolutePath);
1575
+ if (!isDebugMode()) await rm(ssgFolderPath, {
1576
+ recursive: true
1577
+ });
1246
1578
  });
1247
1579
  });
1248
1580
  }
@@ -1435,19 +1767,18 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
1435
1767
  ],
1436
1768
  server: {
1437
1769
  port: !isProduction() && process.env.PORT ? Number(process.env.PORT) : void 0,
1438
- printUrls: ({ urls })=>urls.map((url)=>`${url}/${removeLeadingSlash(base)}`),
1439
1770
  publicDir: {
1440
1771
  name: node_path.join(userDocRoot, PUBLIC_DIR)
1441
- }
1772
+ },
1773
+ ...base.length > 0 ? {
1774
+ base: removeTrailingSlash(base)
1775
+ } : {}
1442
1776
  },
1443
1777
  dev: {
1444
1778
  lazyCompilation: 'false' !== process.env.RSPRESS_LAZY_COMPILATION,
1445
- progressBar: false,
1446
- setupMiddlewares: [
1447
- (middlewares)=>{
1448
- middlewares.unshift(serveSearchIndexMiddleware(config));
1449
- }
1450
- ],
1779
+ setupMiddlewares: (middlewares)=>{
1780
+ middlewares.unshift(serveSearchIndexMiddleware(config));
1781
+ },
1451
1782
  cliShortcuts: {
1452
1783
  custom: (shortcuts)=>shortcuts.filter(({ key })=>'r' !== key)
1453
1784
  }
@@ -1536,7 +1867,11 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
1536
1867
  chain.module.rule('css-virtual-module').test(/\.rspress[\\/]runtime[\\/]virtual-global-styles/).merge({
1537
1868
  sideEffects: true
1538
1869
  });
1539
- if (isServer) chain.output.filename(NODE_SSR_BUNDLE_NAME);
1870
+ if (isServer) {
1871
+ chain.output.filename(`${NODE_SSG_BUNDLE_FOLDER}/${NODE_SSG_BUNDLE_NAME}`);
1872
+ chain.output.chunkFilename(`${NODE_SSG_BUNDLE_FOLDER}/[name].cjs`);
1873
+ chain.target('async-node');
1874
+ }
1540
1875
  }
1541
1876
  },
1542
1877
  environments: {
@@ -1574,13 +1909,6 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
1574
1909
  ...reactRouterDomAlias
1575
1910
  }
1576
1911
  },
1577
- tools: {
1578
- rspack: {
1579
- output: {
1580
- asyncChunks: false
1581
- }
1582
- }
1583
- },
1584
1912
  source: {
1585
1913
  entry: {
1586
1914
  index: SSR_SERVER_ENTRY
@@ -1604,21 +1932,22 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
1604
1932
  }
1605
1933
  };
1606
1934
  }
1607
- async function initRsbuild(rootDir, config, pluginDriver, enableSSG, extraRsbuildConfig) {
1935
+ async function initRsbuild(rootDir, _config, pluginDriver, enableSSG, extraRsbuildConfig) {
1608
1936
  const cwd = process.cwd();
1609
- const userDocRoot = node_path.resolve(rootDir || config?.root || cwd);
1610
- const builderPlugins = config?.builderPlugins ?? [];
1937
+ const userDocRoot = node_path.resolve(rootDir || _config?.root || cwd);
1938
+ const builderPlugins = _config?.builderPlugins ?? [];
1611
1939
  const runtimeTempDir = node_path.join(RSPRESS_TEMP_DIR, 'runtime');
1612
1940
  const runtimeAbsTempDir = node_path.join(cwd, 'node_modules', runtimeTempDir);
1613
1941
  await node_fs_promises.mkdir(runtimeAbsTempDir, {
1614
1942
  recursive: true
1615
1943
  });
1616
1944
  const routeService = await RouteService.create({
1617
- config,
1945
+ config: _config,
1618
1946
  runtimeTempDir: runtimeAbsTempDir,
1619
1947
  scanDir: userDocRoot,
1620
1948
  pluginDriver
1621
1949
  });
1950
+ const config = await modifyConfigWithAutoNavSide(_config);
1622
1951
  const { createRsbuild, mergeRsbuildConfig } = await import("@rsbuild/core");
1623
1952
  const internalRsbuildConfig = await createInternalBuildConfig(userDocRoot, config, enableSSG, routeService, pluginDriver);
1624
1953
  const rsbuild = await createRsbuild({
@@ -1709,8 +2038,8 @@ async function dev(options) {
1709
2038
  await pluginDriver.init();
1710
2039
  const modifiedConfig = await pluginDriver.modifyConfig();
1711
2040
  try {
1712
- await pluginDriver.beforeBuild();
1713
2041
  const rsbuild = await initRsbuild(docDirectory, modifiedConfig, pluginDriver, false, extraBuilderConfig);
2042
+ await pluginDriver.beforeBuild();
1714
2043
  rsbuild.onDevCompileDone(async ()=>{
1715
2044
  await pluginDriver.afterBuild();
1716
2045
  });
@@ -1726,11 +2055,13 @@ async function dev(options) {
1726
2055
  async function bundle(docDirectory, config, pluginDriver, enableSSG) {
1727
2056
  try {
1728
2057
  const rsbuild = await initRsbuild(docDirectory, config, pluginDriver, enableSSG);
2058
+ await pluginDriver.beforeBuild();
1729
2059
  await rsbuild.build();
1730
2060
  } finally{
1731
2061
  await writeSearchIndex(config);
1732
2062
  await checkLanguageParity(config);
1733
2063
  }
2064
+ await pluginDriver.afterBuild();
1734
2065
  }
1735
2066
  function emptyDir(path) {
1736
2067
  return node_fs_promises.rm(path, {
@@ -1743,12 +2074,10 @@ async function build(options) {
1743
2074
  const pluginDriver = new PluginDriver(config, true);
1744
2075
  await pluginDriver.init();
1745
2076
  const modifiedConfig = await pluginDriver.modifyConfig();
1746
- await pluginDriver.beforeBuild();
1747
2077
  const ssgConfig = modifiedConfig.ssg ?? true;
1748
2078
  await emptyDir(constants_TEMP_DIR);
1749
2079
  await bundle(docDirectory, modifiedConfig, pluginDriver, ssgConfig);
1750
2080
  if (!ssgConfig) hintSSGFalse();
1751
- await pluginDriver.afterBuild();
1752
2081
  }
1753
2082
  async function serve(options) {
1754
2083
  const { config, port: userPort, host: userHost } = options;
@@ -1807,8 +2136,8 @@ function normalizeLink(nodeUrl, routeService, relativePath, cleanUrls) {
1807
2136
  if ((routeService?.extensions ?? DEFAULT_PAGE_EXTENSIONS).includes(extname)) url = url.replace(new RegExp(`\\${extname}$`), '');
1808
2137
  if (url.startsWith('.')) url = node_path.posix.join(slash(node_path.dirname(relativePath)), url);
1809
2138
  else if (routeService) {
1810
- const [pathVersion, pathLang] = routeService.getRoutePathParts(slash(relativePath));
1811
- const [urlVersion, urlLang, urlPath] = routeService.getRoutePathParts(url);
2139
+ const [_, pathVersion, pathLang] = routeService.getRoutePathParts(slash(relativePath));
2140
+ const [__, urlVersion, urlLang, urlPath] = routeService.getRoutePathParts(url);
1812
2141
  url = addLeadingSlash(urlPath);
1813
2142
  if (pathLang && urlLang !== pathLang) url = `/${pathLang}${url}`;
1814
2143
  if (pathVersion && urlVersion !== pathVersion) url = `/${pathVersion}${url}`;
package/dist/loader.d.ts CHANGED
@@ -61,6 +61,8 @@ declare class RoutePage {
61
61
  declare class RouteService {
62
62
  #private;
63
63
  routeData: Map<string, RoutePage>;
64
+ static __instance__: RouteService | null;
65
+ static getInstance(): RouteService;
64
66
  static create(options: InitOptions): Promise<RouteService>;
65
67
  constructor(scanDir: string, userConfig: UserConfig, tempDir: string, pluginDriver: PluginDriver);
66
68
  get extensions(): readonly string[];
@@ -71,7 +73,7 @@ declare class RouteService {
71
73
  isExistRoute(routePath: string): boolean;
72
74
  generateRoutesCode(): string;
73
75
  generateRoutesCodeByRouteMeta(routeMeta: RouteMeta[]): string;
74
- getRoutePathParts(routePath: string): readonly [string, string, string];
76
+ getRoutePathParts(routePath: string): readonly [string, string, string, string];
75
77
  normalizeRoutePath(routePath: string): {
76
78
  routePath: string;
77
79
  lang: string;
@@ -80,6 +82,6 @@ declare class RouteService {
80
82
  getRoutePageByRoutePath(routePath: string): RoutePage | undefined;
81
83
  }
82
84
 
83
- declare type RspressPluginHookKeys = 'beforeBuild' | 'afterBuild' | 'addPages' | 'addRuntimeModules' | 'routeGenerated' | 'routeServiceGenerated' | 'addSSGRoutes' | 'extendPageData' | 'modifySearchIndexData';
85
+ declare type RspressPluginHookKeys = 'beforeBuild' | 'config' | 'afterBuild' | 'addPages' | 'addRuntimeModules' | 'routeGenerated' | 'routeServiceGenerated' | 'addSSGRoutes' | 'extendPageData' | 'modifySearchIndexData';
84
86
 
85
87
  export { }
package/dist/loader.js CHANGED
@@ -1,4 +1,4 @@
1
- import __rslib_shim_module__ from 'module';
1
+ import 'module';
2
2
  /*#__PURE__*/ import.meta.url;
3
3
  import { logger } from "@rspress/shared/logger";
4
4
  import { compile, compileWithCrossCompilerCache } from "./processor.js";
@@ -63,6 +63,8 @@ declare class RoutePage {
63
63
  declare class RouteService {
64
64
  #private;
65
65
  routeData: Map<string, RoutePage>;
66
+ static __instance__: RouteService | null;
67
+ static getInstance(): RouteService;
66
68
  static create(options: InitOptions): Promise<RouteService>;
67
69
  constructor(scanDir: string, userConfig: UserConfig, tempDir: string, pluginDriver: PluginDriver);
68
70
  get extensions(): readonly string[];
@@ -73,7 +75,7 @@ declare class RouteService {
73
75
  isExistRoute(routePath: string): boolean;
74
76
  generateRoutesCode(): string;
75
77
  generateRoutesCodeByRouteMeta(routeMeta: RouteMeta[]): string;
76
- getRoutePathParts(routePath: string): readonly [string, string, string];
78
+ getRoutePathParts(routePath: string): readonly [string, string, string, string];
77
79
  normalizeRoutePath(routePath: string): {
78
80
  routePath: string;
79
81
  lang: string;
@@ -82,6 +84,6 @@ declare class RouteService {
82
84
  getRoutePageByRoutePath(routePath: string): RoutePage | undefined;
83
85
  }
84
86
 
85
- declare type RspressPluginHookKeys = 'beforeBuild' | 'afterBuild' | 'addPages' | 'addRuntimeModules' | 'routeGenerated' | 'routeServiceGenerated' | 'addSSGRoutes' | 'extendPageData' | 'modifySearchIndexData';
87
+ declare type RspressPluginHookKeys = 'beforeBuild' | 'config' | 'afterBuild' | 'addPages' | 'addRuntimeModules' | 'routeGenerated' | 'routeServiceGenerated' | 'addSSGRoutes' | 'extendPageData' | 'modifySearchIndexData';
86
88
 
87
89
  export { }
package/dist/processor.js CHANGED
@@ -1,4 +1,4 @@
1
- import __rslib_shim_module__ from 'module';
1
+ import 'module';
2
2
  /*#__PURE__*/ import.meta.url;
3
3
  import node_path from "node:path";
4
4
  import { createProcessor, nodeTypes } from "@mdx-js/mdx";
@@ -40,7 +40,7 @@ const rehypeHeaderAnchor = ()=>{
40
40
  if (!node.properties?.id) {
41
41
  const [text, customId] = collectHeaderText(node);
42
42
  node.properties ??= {};
43
- node.properties.id = customId || slugger.slug(text);
43
+ node.properties.id = customId || slugger.slug(text.trim());
44
44
  }
45
45
  node.children.unshift(create(node));
46
46
  });
@@ -156,8 +156,8 @@ function normalizeLink(nodeUrl, routeService, relativePath, cleanUrls) {
156
156
  if ((routeService?.extensions ?? DEFAULT_PAGE_EXTENSIONS).includes(extname)) url = url.replace(new RegExp(`\\${extname}$`), '');
157
157
  if (url.startsWith('.')) url = node_path.posix.join(shared_slash(node_path.dirname(relativePath)), url);
158
158
  else if (routeService) {
159
- const [pathVersion, pathLang] = routeService.getRoutePathParts(shared_slash(relativePath));
160
- const [urlVersion, urlLang, urlPath] = routeService.getRoutePathParts(url);
159
+ const [_, pathVersion, pathLang] = routeService.getRoutePathParts(shared_slash(relativePath));
160
+ const [__, urlVersion, urlLang, urlPath] = routeService.getRoutePathParts(url);
161
161
  url = addLeadingSlash(urlPath);
162
162
  if (pathLang && urlLang !== pathLang) url = `/${pathLang}${url}`;
163
163
  if (pathVersion && urlVersion !== pathVersion) url = `/${pathVersion}${url}`;
@@ -266,7 +266,7 @@ const parseToc = (tree)=>{
266
266
  if (1 === node.depth) {
267
267
  if (!title) title = text;
268
268
  } else {
269
- const id = customId ? customId : slugger.slug(text);
269
+ const id = customId ? customId : slugger.slug(text.trim());
270
270
  const { depth } = node;
271
271
  toc.push({
272
272
  id,
@@ -25,6 +25,10 @@ function ClientApp({ initialPageData = null }) {
25
25
  setData
26
26
  ]),
27
27
  children: /*#__PURE__*/ jsx(BrowserRouter, {
28
+ future: {
29
+ v7_relativeSplatPath: true,
30
+ v7_startTransition: true
31
+ },
28
32
  children: /*#__PURE__*/ jsx(UnheadProvider, {
29
33
  head: head,
30
34
  children: /*#__PURE__*/ jsx(App, {})
@@ -1,5 +1,5 @@
1
1
  /*! For license information please see shiki-transformers.js.LICENSE.txt */
2
- import __rslib_shim_module__ from 'module';
2
+ import 'module';
3
3
  /*#__PURE__*/ import.meta.url;
4
4
  const SHIKI_TRANSFORMER_LINE_NUMBER = 'shiki-transformer:line-number';
5
5
  function transformerLineNumber(options = {}) {
package/package.json CHANGED
@@ -1,21 +1,19 @@
1
1
  {
2
2
  "name": "@rspress/core",
3
- "version": "2.0.0-beta.15",
3
+ "version": "2.0.0-beta.17",
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
8
  "url": "git+https://github.com/web-infra-dev/rspress.git",
9
- "directory": "packages/cli/core"
9
+ "directory": "packages/core"
10
10
  },
11
11
  "license": "MIT",
12
12
  "sideEffects": [
13
13
  "*.css",
14
14
  "*.less",
15
15
  "*.sass",
16
- "*.scss",
17
- "**/virtual-global-styles.js",
18
- "virtual-global-styles"
16
+ "*.scss"
19
17
  ],
20
18
  "type": "module",
21
19
  "exports": {
@@ -49,7 +47,7 @@
49
47
  "@mdx-js/loader": "^3.1.0",
50
48
  "@mdx-js/mdx": "^3.1.0",
51
49
  "@mdx-js/react": "^3.1.0",
52
- "@rsbuild/core": "~1.3.22",
50
+ "@rsbuild/core": "~1.4.0-rc.0",
53
51
  "@rsbuild/plugin-react": "~1.3.2",
54
52
  "@rspress/mdx-rs": "0.6.6",
55
53
  "@shikijs/rehype": "^3.4.2",
@@ -77,17 +75,16 @@
77
75
  "unified": "^11.0.5",
78
76
  "unist-util-visit": "^5.0.0",
79
77
  "unist-util-visit-children": "^3.0.0",
80
- "@rspress/plugin-auto-nav-sidebar": "2.0.0-beta.15",
81
- "@rspress/plugin-medium-zoom": "2.0.0-beta.15",
82
- "@rspress/plugin-container-syntax": "2.0.0-beta.15",
83
- "@rspress/plugin-last-updated": "2.0.0-beta.15",
84
- "@rspress/runtime": "2.0.0-beta.15",
85
- "@rspress/shared": "2.0.0-beta.15",
86
- "@rspress/theme-default": "2.0.0-beta.15"
78
+ "@rspress/plugin-last-updated": "2.0.0-beta.17",
79
+ "@rspress/plugin-medium-zoom": "2.0.0-beta.17",
80
+ "@rspress/runtime": "2.0.0-beta.17",
81
+ "@rspress/shared": "2.0.0-beta.17",
82
+ "@rspress/theme-default": "2.0.0-beta.17",
83
+ "@rspress/plugin-container-syntax": "2.0.0-beta.17"
87
84
  },
88
85
  "devDependencies": {
89
86
  "@microsoft/api-extractor": "^7.52.8",
90
- "@rslib/core": "0.10.0",
87
+ "@rslib/core": "0.10.2",
91
88
  "@rspress-dev/plugin-preview": "link:../plugin-preview",
92
89
  "@types/hast": "^3.0.4",
93
90
  "@types/html-to-text": "^9.0.4",
@@ -99,7 +96,7 @@
99
96
  "@types/react-dom": "^19.1.6",
100
97
  "memfs": "^4.17.2",
101
98
  "p-map": "^7.0.3",
102
- "postcss": "8.5.5",
99
+ "postcss": "8.5.6",
103
100
  "rehype-stringify": "^10.0.1",
104
101
  "remark-mdx": "^3.1.0",
105
102
  "remark-parse": "^11.0.0",
@@ -107,7 +104,7 @@
107
104
  "remark-stringify": "^11.0.0",
108
105
  "rimraf": "^6.0.1",
109
106
  "rsbuild-plugin-publint": "^0.3.2",
110
- "rsbuild-plugin-virtual-module": "0.2.0",
107
+ "rsbuild-plugin-virtual-module": "0.3.0",
111
108
  "tailwindcss": "^3.4.17",
112
109
  "typescript": "^5.8.2",
113
110
  "vfile": "^6.0.3",