@rspress/core 2.0.0-beta.16 → 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 +4 -2
- package/dist/index.js +403 -78
- package/dist/loader.d.ts +4 -2
- package/dist/loader.js +1 -1
- package/dist/processor.d.ts +4 -2
- package/dist/processor.js +5 -5
- package/dist/runtime/ClientApp.js +4 -0
- package/dist/shiki-transformers.js +1 -1
- package/package.json +11 -12
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
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
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,33 +177,6 @@ const pluginVirtualModule = (pluginOptions = {})=>({
|
|
|
179
177
|
}
|
|
180
178
|
}
|
|
181
179
|
});
|
|
182
|
-
var package_namespaceObject = JSON.parse('{"i8":"2.0.0-beta.16"}');
|
|
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
|
-
const NODE_SSG_BUNDLE_FOLDER = '__ssg__';
|
|
208
|
-
const NODE_SSG_BUNDLE_NAME = 'rspress-ssg-entry.cjs';
|
|
209
180
|
async function pathExists(path) {
|
|
210
181
|
try {
|
|
211
182
|
await node_fs_promises.access(path);
|
|
@@ -261,13 +232,42 @@ function hintSSGFalse() {
|
|
|
261
232
|
function hintReactVersion() {
|
|
262
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. ');
|
|
263
234
|
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
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
|
+
}
|
|
270
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';
|
|
271
271
|
function getPageKey(route) {
|
|
272
272
|
const cleanRoute = removeLeadingSlash(route);
|
|
273
273
|
return cleanRoute.replace(/\//g, '_').replace(/\.[^.]+$/, '') || 'index';
|
|
@@ -281,7 +281,7 @@ class RoutePage {
|
|
|
281
281
|
this.routeMeta = routeMeta;
|
|
282
282
|
}
|
|
283
283
|
}
|
|
284
|
-
const getRoutePathParts = (routePath, lang, version, langs, versions)=>{
|
|
284
|
+
const getRoutePathParts = (routePath, base, lang, version, langs, versions)=>{
|
|
285
285
|
const hasTrailSlash = routePath.endsWith('/');
|
|
286
286
|
let versionPart = '';
|
|
287
287
|
let langPart = '';
|
|
@@ -303,13 +303,14 @@ const getRoutePathParts = (routePath, lang, version, langs, versions)=>{
|
|
|
303
303
|
}
|
|
304
304
|
purePathPart = parts.join('/');
|
|
305
305
|
return [
|
|
306
|
+
base,
|
|
306
307
|
versionPart,
|
|
307
308
|
langPart,
|
|
308
309
|
hasTrailSlash ? addTrailingSlash(purePathPart) : purePathPart
|
|
309
310
|
];
|
|
310
311
|
};
|
|
311
312
|
const normalizeRoutePath = (routePath, base, lang, version, langs, versions, extensions = DEFAULT_PAGE_EXTENSIONS)=>{
|
|
312
|
-
const [versionPart, langPart, purePathPart] = getRoutePathParts(routePath, lang, version, langs, versions);
|
|
313
|
+
const [_, versionPart, langPart, purePathPart] = getRoutePathParts(routePath, base, lang, version, langs, versions);
|
|
313
314
|
const extensionsWithoutDot = extensions.map((i)=>i.slice(1));
|
|
314
315
|
const cleanExtensionPattern = new RegExp(`\\.(${extensionsWithoutDot.join('|')})$`, 'i');
|
|
315
316
|
const normalizedRoutePath = addLeadingSlash([
|
|
@@ -335,11 +336,16 @@ class RouteService {
|
|
|
335
336
|
#base = '';
|
|
336
337
|
#tempDir = '';
|
|
337
338
|
#pluginDriver;
|
|
339
|
+
static __instance__ = null;
|
|
340
|
+
static getInstance() {
|
|
341
|
+
return RouteService.__instance__;
|
|
342
|
+
}
|
|
338
343
|
static async create(options) {
|
|
339
344
|
const { scanDir, config, runtimeTempDir, pluginDriver } = options;
|
|
340
345
|
const routeService = new RouteService(scanDir, config, runtimeTempDir, pluginDriver);
|
|
341
346
|
await routeService.#init();
|
|
342
347
|
await pluginDriver.routeServiceGenerated(routeService);
|
|
348
|
+
RouteService.__instance__ = routeService;
|
|
343
349
|
return routeService;
|
|
344
350
|
}
|
|
345
351
|
constructor(scanDir, userConfig, tempDir, pluginDriver){
|
|
@@ -450,7 +456,7 @@ ${routeMeta.map((route, index)=>{
|
|
|
450
456
|
`;
|
|
451
457
|
}
|
|
452
458
|
getRoutePathParts(routePath) {
|
|
453
|
-
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);
|
|
454
460
|
}
|
|
455
461
|
normalizeRoutePath(routePath) {
|
|
456
462
|
return normalizeRoutePath(routePath, this.#base, this.#defaultLang, this.#defaultVersion, this.#langs, this.#versions, this.#extensions);
|
|
@@ -475,6 +481,334 @@ ${routeMeta.map((route, index)=>{
|
|
|
475
481
|
return this.routeData.get(routePath);
|
|
476
482
|
}
|
|
477
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
|
+
}
|
|
478
812
|
let flattenMdxContent_resolver;
|
|
479
813
|
let startFlatten = false;
|
|
480
814
|
const processor = createProcessor();
|
|
@@ -698,7 +1032,7 @@ const i18nVMPlugin = (context)=>{
|
|
|
698
1032
|
}
|
|
699
1033
|
};
|
|
700
1034
|
};
|
|
701
|
-
function normalizeThemeConfig(docConfig
|
|
1035
|
+
function normalizeThemeConfig(docConfig) {
|
|
702
1036
|
const { locales: siteLocales, base = '', lang, replaceRules = [], multiVersion } = docConfig;
|
|
703
1037
|
const { versions = [] } = multiVersion || {};
|
|
704
1038
|
const hasMultiVersion = versions.length > 0;
|
|
@@ -733,15 +1067,6 @@ function normalizeThemeConfig(docConfig, pages = []) {
|
|
|
733
1067
|
tag: item.tag,
|
|
734
1068
|
items: item.items.map((subItem)=>normalizeSidebarItem(subItem))
|
|
735
1069
|
};
|
|
736
|
-
if ('string' == typeof item) {
|
|
737
|
-
const normalizedItem = normalizeLinkPrefix(item, currentLang);
|
|
738
|
-
const page = pages.find((page)=>page.routePath === withBase(normalizedItem, base));
|
|
739
|
-
return {
|
|
740
|
-
text: applyReplaceRules(page?.title || '', replaceRules),
|
|
741
|
-
link: normalizedItem,
|
|
742
|
-
_fileKey: page?._relativePath.replace(node_path.extname(page._relativePath), '')
|
|
743
|
-
};
|
|
744
|
-
}
|
|
745
1070
|
return {
|
|
746
1071
|
...item,
|
|
747
1072
|
text: applyReplaceRules(getI18nText(item.text, currentLang), replaceRules),
|
|
@@ -852,7 +1177,7 @@ async function siteDataVMPlugin(context) {
|
|
|
852
1177
|
description: userConfig?.description || '',
|
|
853
1178
|
icon: getIconUrlPath(userConfig?.icon) || '',
|
|
854
1179
|
route: userConfig?.route || {},
|
|
855
|
-
themeConfig: normalizeThemeConfig(userConfig
|
|
1180
|
+
themeConfig: normalizeThemeConfig(userConfig),
|
|
856
1181
|
base: userConfig?.base || '/',
|
|
857
1182
|
lang: userConfig?.lang || '',
|
|
858
1183
|
locales: userConfig?.locales || userConfig.themeConfig?.locales || [],
|
|
@@ -1442,19 +1767,18 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1442
1767
|
],
|
|
1443
1768
|
server: {
|
|
1444
1769
|
port: !isProduction() && process.env.PORT ? Number(process.env.PORT) : void 0,
|
|
1445
|
-
printUrls: ({ urls })=>urls.map((url)=>`${url}/${removeLeadingSlash(base)}`),
|
|
1446
1770
|
publicDir: {
|
|
1447
1771
|
name: node_path.join(userDocRoot, PUBLIC_DIR)
|
|
1448
|
-
}
|
|
1772
|
+
},
|
|
1773
|
+
...base.length > 0 ? {
|
|
1774
|
+
base: removeTrailingSlash(base)
|
|
1775
|
+
} : {}
|
|
1449
1776
|
},
|
|
1450
1777
|
dev: {
|
|
1451
1778
|
lazyCompilation: 'false' !== process.env.RSPRESS_LAZY_COMPILATION,
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
middlewares.unshift(serveSearchIndexMiddleware(config));
|
|
1456
|
-
}
|
|
1457
|
-
],
|
|
1779
|
+
setupMiddlewares: (middlewares)=>{
|
|
1780
|
+
middlewares.unshift(serveSearchIndexMiddleware(config));
|
|
1781
|
+
},
|
|
1458
1782
|
cliShortcuts: {
|
|
1459
1783
|
custom: (shortcuts)=>shortcuts.filter(({ key })=>'r' !== key)
|
|
1460
1784
|
}
|
|
@@ -1608,21 +1932,22 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1608
1932
|
}
|
|
1609
1933
|
};
|
|
1610
1934
|
}
|
|
1611
|
-
async function initRsbuild(rootDir,
|
|
1935
|
+
async function initRsbuild(rootDir, _config, pluginDriver, enableSSG, extraRsbuildConfig) {
|
|
1612
1936
|
const cwd = process.cwd();
|
|
1613
|
-
const userDocRoot = node_path.resolve(rootDir ||
|
|
1614
|
-
const builderPlugins =
|
|
1937
|
+
const userDocRoot = node_path.resolve(rootDir || _config?.root || cwd);
|
|
1938
|
+
const builderPlugins = _config?.builderPlugins ?? [];
|
|
1615
1939
|
const runtimeTempDir = node_path.join(RSPRESS_TEMP_DIR, 'runtime');
|
|
1616
1940
|
const runtimeAbsTempDir = node_path.join(cwd, 'node_modules', runtimeTempDir);
|
|
1617
1941
|
await node_fs_promises.mkdir(runtimeAbsTempDir, {
|
|
1618
1942
|
recursive: true
|
|
1619
1943
|
});
|
|
1620
1944
|
const routeService = await RouteService.create({
|
|
1621
|
-
config,
|
|
1945
|
+
config: _config,
|
|
1622
1946
|
runtimeTempDir: runtimeAbsTempDir,
|
|
1623
1947
|
scanDir: userDocRoot,
|
|
1624
1948
|
pluginDriver
|
|
1625
1949
|
});
|
|
1950
|
+
const config = await modifyConfigWithAutoNavSide(_config);
|
|
1626
1951
|
const { createRsbuild, mergeRsbuildConfig } = await import("@rsbuild/core");
|
|
1627
1952
|
const internalRsbuildConfig = await createInternalBuildConfig(userDocRoot, config, enableSSG, routeService, pluginDriver);
|
|
1628
1953
|
const rsbuild = await createRsbuild({
|
|
@@ -1713,8 +2038,8 @@ async function dev(options) {
|
|
|
1713
2038
|
await pluginDriver.init();
|
|
1714
2039
|
const modifiedConfig = await pluginDriver.modifyConfig();
|
|
1715
2040
|
try {
|
|
1716
|
-
await pluginDriver.beforeBuild();
|
|
1717
2041
|
const rsbuild = await initRsbuild(docDirectory, modifiedConfig, pluginDriver, false, extraBuilderConfig);
|
|
2042
|
+
await pluginDriver.beforeBuild();
|
|
1718
2043
|
rsbuild.onDevCompileDone(async ()=>{
|
|
1719
2044
|
await pluginDriver.afterBuild();
|
|
1720
2045
|
});
|
|
@@ -1730,11 +2055,13 @@ async function dev(options) {
|
|
|
1730
2055
|
async function bundle(docDirectory, config, pluginDriver, enableSSG) {
|
|
1731
2056
|
try {
|
|
1732
2057
|
const rsbuild = await initRsbuild(docDirectory, config, pluginDriver, enableSSG);
|
|
2058
|
+
await pluginDriver.beforeBuild();
|
|
1733
2059
|
await rsbuild.build();
|
|
1734
2060
|
} finally{
|
|
1735
2061
|
await writeSearchIndex(config);
|
|
1736
2062
|
await checkLanguageParity(config);
|
|
1737
2063
|
}
|
|
2064
|
+
await pluginDriver.afterBuild();
|
|
1738
2065
|
}
|
|
1739
2066
|
function emptyDir(path) {
|
|
1740
2067
|
return node_fs_promises.rm(path, {
|
|
@@ -1747,12 +2074,10 @@ async function build(options) {
|
|
|
1747
2074
|
const pluginDriver = new PluginDriver(config, true);
|
|
1748
2075
|
await pluginDriver.init();
|
|
1749
2076
|
const modifiedConfig = await pluginDriver.modifyConfig();
|
|
1750
|
-
await pluginDriver.beforeBuild();
|
|
1751
2077
|
const ssgConfig = modifiedConfig.ssg ?? true;
|
|
1752
2078
|
await emptyDir(constants_TEMP_DIR);
|
|
1753
2079
|
await bundle(docDirectory, modifiedConfig, pluginDriver, ssgConfig);
|
|
1754
2080
|
if (!ssgConfig) hintSSGFalse();
|
|
1755
|
-
await pluginDriver.afterBuild();
|
|
1756
2081
|
}
|
|
1757
2082
|
async function serve(options) {
|
|
1758
2083
|
const { config, port: userPort, host: userHost } = options;
|
|
@@ -1811,8 +2136,8 @@ function normalizeLink(nodeUrl, routeService, relativePath, cleanUrls) {
|
|
|
1811
2136
|
if ((routeService?.extensions ?? DEFAULT_PAGE_EXTENSIONS).includes(extname)) url = url.replace(new RegExp(`\\${extname}$`), '');
|
|
1812
2137
|
if (url.startsWith('.')) url = node_path.posix.join(slash(node_path.dirname(relativePath)), url);
|
|
1813
2138
|
else if (routeService) {
|
|
1814
|
-
const [pathVersion, pathLang] = routeService.getRoutePathParts(slash(relativePath));
|
|
1815
|
-
const [urlVersion, urlLang, urlPath] = routeService.getRoutePathParts(url);
|
|
2139
|
+
const [_, pathVersion, pathLang] = routeService.getRoutePathParts(slash(relativePath));
|
|
2140
|
+
const [__, urlVersion, urlLang, urlPath] = routeService.getRoutePathParts(url);
|
|
1816
2141
|
url = addLeadingSlash(urlPath);
|
|
1817
2142
|
if (pathLang && urlLang !== pathLang) url = `/${pathLang}${url}`;
|
|
1818
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
package/dist/processor.d.ts
CHANGED
|
@@ -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
|
|
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
|
|
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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspress/core",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
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": {
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"@mdx-js/loader": "^3.1.0",
|
|
48
48
|
"@mdx-js/mdx": "^3.1.0",
|
|
49
49
|
"@mdx-js/react": "^3.1.0",
|
|
50
|
-
"@rsbuild/core": "~1.
|
|
50
|
+
"@rsbuild/core": "~1.4.0-rc.0",
|
|
51
51
|
"@rsbuild/plugin-react": "~1.3.2",
|
|
52
52
|
"@rspress/mdx-rs": "0.6.6",
|
|
53
53
|
"@shikijs/rehype": "^3.4.2",
|
|
@@ -75,17 +75,16 @@
|
|
|
75
75
|
"unified": "^11.0.5",
|
|
76
76
|
"unist-util-visit": "^5.0.0",
|
|
77
77
|
"unist-util-visit-children": "^3.0.0",
|
|
78
|
-
"@rspress/plugin-
|
|
79
|
-
"@rspress/plugin-
|
|
80
|
-
"@rspress/
|
|
81
|
-
"@rspress/
|
|
82
|
-
"@rspress/
|
|
83
|
-
"@rspress/
|
|
84
|
-
"@rspress/plugin-last-updated": "2.0.0-beta.16"
|
|
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"
|
|
85
84
|
},
|
|
86
85
|
"devDependencies": {
|
|
87
86
|
"@microsoft/api-extractor": "^7.52.8",
|
|
88
|
-
"@rslib/core": "0.10.
|
|
87
|
+
"@rslib/core": "0.10.2",
|
|
89
88
|
"@rspress-dev/plugin-preview": "link:../plugin-preview",
|
|
90
89
|
"@types/hast": "^3.0.4",
|
|
91
90
|
"@types/html-to-text": "^9.0.4",
|
|
@@ -97,7 +96,7 @@
|
|
|
97
96
|
"@types/react-dom": "^19.1.6",
|
|
98
97
|
"memfs": "^4.17.2",
|
|
99
98
|
"p-map": "^7.0.3",
|
|
100
|
-
"postcss": "8.5.
|
|
99
|
+
"postcss": "8.5.6",
|
|
101
100
|
"rehype-stringify": "^10.0.1",
|
|
102
101
|
"remark-mdx": "^3.1.0",
|
|
103
102
|
"remark-parse": "^11.0.0",
|
|
@@ -105,7 +104,7 @@
|
|
|
105
104
|
"remark-stringify": "^11.0.0",
|
|
106
105
|
"rimraf": "^6.0.1",
|
|
107
106
|
"rsbuild-plugin-publint": "^0.3.2",
|
|
108
|
-
"rsbuild-plugin-virtual-module": "0.
|
|
107
|
+
"rsbuild-plugin-virtual-module": "0.3.0",
|
|
109
108
|
"tailwindcss": "^3.4.17",
|
|
110
109
|
"typescript": "^5.8.2",
|
|
111
110
|
"vfile": "^6.0.3",
|