@rspress/core 2.0.0-beta.16 → 2.0.0-beta.18
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 +3 -1
- package/dist/index.js +425 -87
- package/dist/loader.d.ts +4 -2
- package/dist/loader.js +3 -4
- package/dist/processor.d.ts +3 -1
- package/dist/processor.js +203 -5
- package/dist/runtime/ClientApp.js +6 -0
- package/dist/runtime/initPageData.js +2 -1
- package/dist/runtime/ssrServerEntry.d.ts +1 -1
- package/dist/runtime/ssrServerEntry.js +7 -5
- package/dist/shiki-transformers.js +0 -2
- package/package.json +12 -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[];
|
|
@@ -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,17 @@
|
|
|
1
1
|
import __rslib_shim_module__ from 'module';
|
|
2
2
|
const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(import.meta.url);
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import node_path, { extname as external_node_path_extname, join } from "node:path";
|
|
3
|
+
import node_fs_promises, { mkdir, readFile, readdir, rm, stat as promises_stat, writeFile } from "node:fs/promises";
|
|
4
|
+
import node_path, { dirname, extname as external_node_path_extname, join, relative } from "node:path";
|
|
6
5
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
7
6
|
import { PLUGIN_REACT_NAME, pluginReact } from "@rsbuild/plugin-react";
|
|
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
|
|
7
|
+
import { APPEARANCE_KEY, MDX_OR_MD_REGEXP, RSPRESS_TEMP_DIR, SEARCH_INDEX_NAME, addLeadingSlash, addTrailingSlash, isDebugMode, isExternalUrl, isSCM, normalizeHref, normalizeSlash, parseUrl, removeLeadingSlash, removeTrailingSlash, slash } from "@rspress/shared";
|
|
8
|
+
import { DEFAULT_PAGE_EXTENSIONS } from "@rspress/shared/constants";
|
|
9
9
|
import { logger } from "@rspress/shared/logger";
|
|
10
10
|
import picocolors from "picocolors";
|
|
11
|
-
import { DEFAULT_PAGE_EXTENSIONS } from "@rspress/shared/constants";
|
|
12
|
-
import { glob } from "tinyglobby";
|
|
13
11
|
import node_os from "node:os";
|
|
12
|
+
import { glob } from "tinyglobby";
|
|
13
|
+
import { extractTextAndId, getIconUrlPath, getNodeAttribute, loadFrontMatter, mergeDocConfig } from "@rspress/shared/node-utils";
|
|
14
14
|
import { RspackVirtualModulePlugin } from "rspack-plugin-virtual-module";
|
|
15
|
-
import { getIconUrlPath, getNodeAttribute, loadFrontMatter, mergeDocConfig } from "@rspress/shared/node-utils";
|
|
16
15
|
import { groupBy } from "lodash-es";
|
|
17
16
|
import { compile } from "@rspress/mdx-rs";
|
|
18
17
|
import { htmlToText } from "html-to-text";
|
|
@@ -39,7 +38,6 @@ class PluginDriver {
|
|
|
39
38
|
const themeConfig = config?.themeConfig || {};
|
|
40
39
|
const enableLastUpdated = themeConfig?.lastUpdated || themeConfig?.locales?.some((locale)=>locale.lastUpdated);
|
|
41
40
|
const mediumZoomConfig = config?.mediumZoom ?? true;
|
|
42
|
-
const haveNavSidebarConfig = themeConfig.nav || themeConfig.sidebar || themeConfig.locales?.[0]?.nav || themeConfig.locales?.[0]?.sidebar;
|
|
43
41
|
if (enableLastUpdated) {
|
|
44
42
|
const { pluginLastUpdated } = await import("@rspress/plugin-last-updated");
|
|
45
43
|
this.addPlugin(pluginLastUpdated());
|
|
@@ -48,14 +46,9 @@ class PluginDriver {
|
|
|
48
46
|
const { pluginMediumZoom } = await import("@rspress/plugin-medium-zoom");
|
|
49
47
|
this.addPlugin(pluginMediumZoom('object' == typeof mediumZoomConfig ? mediumZoomConfig : void 0));
|
|
50
48
|
}
|
|
51
|
-
this.addPlugin(pluginContainerSyntax());
|
|
52
49
|
(config.plugins || []).forEach((plugin)=>{
|
|
53
50
|
this.addPlugin(plugin);
|
|
54
51
|
});
|
|
55
|
-
if (!haveNavSidebarConfig) {
|
|
56
|
-
const { pluginAutoNavSidebar } = await import("@rspress/plugin-auto-nav-sidebar");
|
|
57
|
-
this.addPlugin(pluginAutoNavSidebar());
|
|
58
|
-
}
|
|
59
52
|
}
|
|
60
53
|
addPlugin(plugin) {
|
|
61
54
|
const existedIndex = this.#plugins.findIndex((item)=>item.name === plugin.name);
|
|
@@ -163,10 +156,13 @@ const pluginVirtualModule = (pluginOptions = {})=>({
|
|
|
163
156
|
];
|
|
164
157
|
});
|
|
165
158
|
api.onBeforeCreateCompiler(async ()=>{
|
|
166
|
-
await
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
159
|
+
await Promise.all(virtualFileAbsolutePaths.map(async ([_, absolutePath])=>{
|
|
160
|
+
const dir = dirname(absolutePath);
|
|
161
|
+
await mkdir(dir, {
|
|
162
|
+
recursive: true
|
|
163
|
+
});
|
|
164
|
+
return writeFile(absolutePath, '', 'utf-8');
|
|
165
|
+
}));
|
|
170
166
|
});
|
|
171
167
|
api.modifyBundlerChain((chain)=>{
|
|
172
168
|
chain.resolve.alias.merge(Object.fromEntries(virtualFileAbsolutePaths));
|
|
@@ -179,33 +175,6 @@ const pluginVirtualModule = (pluginOptions = {})=>({
|
|
|
179
175
|
}
|
|
180
176
|
}
|
|
181
177
|
});
|
|
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
178
|
async function pathExists(path) {
|
|
210
179
|
try {
|
|
211
180
|
await node_fs_promises.access(path);
|
|
@@ -261,13 +230,42 @@ function hintSSGFalse() {
|
|
|
261
230
|
function hintReactVersion() {
|
|
262
231
|
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
232
|
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
233
|
+
function hintNavJsonChangeThenPanic(metaJson, metaJsonDir, docsDir) {
|
|
234
|
+
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))) {
|
|
235
|
+
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.');
|
|
236
|
+
logger.error(error);
|
|
237
|
+
const dir = relative(docsDir, metaJsonDir);
|
|
238
|
+
logger.info(`Please rename "${picocolors.greenBright(join(dir, '_meta.json'))}" to "${picocolors.greenBright(join(dir, '_nav.json'))}".`);
|
|
239
|
+
process.exit(1);
|
|
240
|
+
}
|
|
270
241
|
}
|
|
242
|
+
var package_namespaceObject = JSON.parse('{"i8":"2.0.0-beta.18"}');
|
|
243
|
+
const RSPRESS_VERSION = package_namespaceObject.i8;
|
|
244
|
+
const isProduction = ()=>'production' === process.env.NODE_ENV;
|
|
245
|
+
const importStatementRegex = /import\s+(.*?)\s+from\s+(['"])(.*?)(?:"|');?/gm;
|
|
246
|
+
const inlineThemeScript = `{
|
|
247
|
+
const saved = localStorage.getItem('${APPEARANCE_KEY}')
|
|
248
|
+
const preferDark = window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
249
|
+
const isDark = !saved || saved === 'auto' ? preferDark : saved === 'dark'
|
|
250
|
+
document.documentElement.classList.toggle('dark', isDark)
|
|
251
|
+
document.documentElement.classList.toggle('rp-dark', isDark)
|
|
252
|
+
document.documentElement.style.colorScheme = isDark ? 'dark' : 'light'
|
|
253
|
+
}`.replace(/\n/g, ';').replace(/\s{2,}/g, '');
|
|
254
|
+
const constants_dirname = node_path.dirname(fileURLToPath(new URL(import.meta.url)));
|
|
255
|
+
const PACKAGE_ROOT = node_path.join(constants_dirname, '..');
|
|
256
|
+
const TEMPLATE_PATH = node_path.join(PACKAGE_ROOT, 'index.html');
|
|
257
|
+
const CSR_CLIENT_ENTRY = node_path.join(PACKAGE_ROOT, 'dist', 'runtime', 'csrClientEntry.js');
|
|
258
|
+
const SSR_CLIENT_ENTRY = node_path.join(PACKAGE_ROOT, 'dist', 'runtime', 'ssrClientEntry.js');
|
|
259
|
+
const SSR_SERVER_ENTRY = node_path.join(PACKAGE_ROOT, 'dist', 'runtime', 'ssrServerEntry.js');
|
|
260
|
+
const OUTPUT_DIR = 'doc_build';
|
|
261
|
+
const APP_HTML_MARKER = '<!--<?- DOC_CONTENT ?>-->';
|
|
262
|
+
const HEAD_MARKER = '<!--<?- HEAD ?>-->';
|
|
263
|
+
const META_GENERATOR = '<!--<?- GENERATOR ?>-->';
|
|
264
|
+
const DEFAULT_TITLE = 'Rspress';
|
|
265
|
+
const PUBLIC_DIR = 'public';
|
|
266
|
+
const constants_TEMP_DIR = node_path.join(process.cwd(), 'node_modules', RSPRESS_TEMP_DIR);
|
|
267
|
+
const NODE_SSG_BUNDLE_FOLDER = '__ssg__';
|
|
268
|
+
const NODE_SSG_BUNDLE_NAME = 'rspress-ssg-entry.cjs';
|
|
271
269
|
function getPageKey(route) {
|
|
272
270
|
const cleanRoute = removeLeadingSlash(route);
|
|
273
271
|
return cleanRoute.replace(/\//g, '_').replace(/\.[^.]+$/, '') || 'index';
|
|
@@ -308,7 +306,7 @@ const getRoutePathParts = (routePath, lang, version, langs, versions)=>{
|
|
|
308
306
|
hasTrailSlash ? addTrailingSlash(purePathPart) : purePathPart
|
|
309
307
|
];
|
|
310
308
|
};
|
|
311
|
-
const normalizeRoutePath = (routePath,
|
|
309
|
+
const normalizeRoutePath = (routePath, lang, version, langs, versions, extensions = DEFAULT_PAGE_EXTENSIONS)=>{
|
|
312
310
|
const [versionPart, langPart, purePathPart] = getRoutePathParts(routePath, lang, version, langs, versions);
|
|
313
311
|
const extensionsWithoutDot = extensions.map((i)=>i.slice(1));
|
|
314
312
|
const cleanExtensionPattern = new RegExp(`\\.(${extensionsWithoutDot.join('|')})$`, 'i');
|
|
@@ -317,7 +315,7 @@ const normalizeRoutePath = (routePath, base, lang, version, langs, versions, ext
|
|
|
317
315
|
langPart
|
|
318
316
|
].filter(Boolean).join('/') + addLeadingSlash(purePathPart)).replace(cleanExtensionPattern, '').replace(/\.html$/, '').replace(/\/index$/, '/');
|
|
319
317
|
return {
|
|
320
|
-
routePath:
|
|
318
|
+
routePath: normalizedRoutePath,
|
|
321
319
|
lang: langPart || lang,
|
|
322
320
|
version: versionPart || version
|
|
323
321
|
};
|
|
@@ -332,14 +330,18 @@ class RouteService {
|
|
|
332
330
|
#versions = [];
|
|
333
331
|
#include = [];
|
|
334
332
|
#exclude = [];
|
|
335
|
-
#base = '';
|
|
336
333
|
#tempDir = '';
|
|
337
334
|
#pluginDriver;
|
|
335
|
+
static __instance__ = null;
|
|
336
|
+
static getInstance() {
|
|
337
|
+
return RouteService.__instance__;
|
|
338
|
+
}
|
|
338
339
|
static async create(options) {
|
|
339
340
|
const { scanDir, config, runtimeTempDir, pluginDriver } = options;
|
|
340
341
|
const routeService = new RouteService(scanDir, config, runtimeTempDir, pluginDriver);
|
|
341
342
|
await routeService.#init();
|
|
342
343
|
await pluginDriver.routeServiceGenerated(routeService);
|
|
344
|
+
RouteService.__instance__ = routeService;
|
|
343
345
|
return routeService;
|
|
344
346
|
}
|
|
345
347
|
constructor(scanDir, userConfig, tempDir, pluginDriver){
|
|
@@ -350,7 +352,6 @@ class RouteService {
|
|
|
350
352
|
this.#exclude = routeOptions.exclude || [];
|
|
351
353
|
this.#defaultLang = userConfig?.lang || '';
|
|
352
354
|
this.#langs = (userConfig?.locales ?? userConfig?.themeConfig?.locales ?? []).map((item)=>item.lang);
|
|
353
|
-
this.#base = userConfig?.base || '';
|
|
354
355
|
this.#tempDir = tempDir;
|
|
355
356
|
this.#pluginDriver = pluginDriver;
|
|
356
357
|
if (userConfig.multiVersion) {
|
|
@@ -453,7 +454,7 @@ ${routeMeta.map((route, index)=>{
|
|
|
453
454
|
return getRoutePathParts(routePath, this.#defaultLang, this.#defaultVersion, this.#langs, this.#versions);
|
|
454
455
|
}
|
|
455
456
|
normalizeRoutePath(routePath) {
|
|
456
|
-
return normalizeRoutePath(routePath, this.#
|
|
457
|
+
return normalizeRoutePath(routePath, this.#defaultLang, this.#defaultVersion, this.#langs, this.#versions, this.#extensions);
|
|
457
458
|
}
|
|
458
459
|
async #writeTempFile(index, content) {
|
|
459
460
|
const tempFilePath = node_path.join(this.#tempDir, `temp-${index}.mdx`);
|
|
@@ -475,6 +476,334 @@ ${routeMeta.map((route, index)=>{
|
|
|
475
476
|
return this.routeData.get(routePath);
|
|
476
477
|
}
|
|
477
478
|
}
|
|
479
|
+
const isWindows = 'win32' === node_os.platform();
|
|
480
|
+
function normalizePath_slash(p) {
|
|
481
|
+
return p.replace(/\\/g, '/');
|
|
482
|
+
}
|
|
483
|
+
function normalizePath(id) {
|
|
484
|
+
return node_path.posix.normalize(isWindows ? normalizePath_slash(id) : id);
|
|
485
|
+
}
|
|
486
|
+
function absolutePathToLink(absolutePath, docsDir) {
|
|
487
|
+
const relativePath = normalizePath_slash(node_path.relative(docsDir, absolutePath.replace(node_path.extname(absolutePath), '')));
|
|
488
|
+
const routeService = RouteService.getInstance();
|
|
489
|
+
return routeService.normalizeRoutePath(relativePath).routePath;
|
|
490
|
+
}
|
|
491
|
+
function absolutePathToRoutePrefix(absolutePath, docsDir) {
|
|
492
|
+
const relativePath = normalizePath_slash(node_path.relative(docsDir, absolutePath.replace(node_path.extname(absolutePath), '')));
|
|
493
|
+
const routeService = RouteService.getInstance();
|
|
494
|
+
const [versionPrefix, langPrefix] = routeService.getRoutePathParts(relativePath);
|
|
495
|
+
return `${versionPrefix ? `/${versionPrefix}` : ''}${langPrefix ? `/${langPrefix}` : ''}`;
|
|
496
|
+
}
|
|
497
|
+
function addRoutePrefix(workDir, docsDir, link) {
|
|
498
|
+
const routePrefix = absolutePathToRoutePrefix(workDir, docsDir);
|
|
499
|
+
return `${routePrefix.replace(/\/$/, '')}/${link.replace(/^\//, '')}`;
|
|
500
|
+
}
|
|
501
|
+
async function utils_pathExists(path) {
|
|
502
|
+
try {
|
|
503
|
+
await node_fs_promises.access(path);
|
|
504
|
+
return true;
|
|
505
|
+
} catch {
|
|
506
|
+
return false;
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
async function utils_readJson(path) {
|
|
510
|
+
const raw = await node_fs_promises.readFile(path, 'utf8');
|
|
511
|
+
return JSON.parse(raw);
|
|
512
|
+
}
|
|
513
|
+
async function extractInfoFromFrontmatterWithAbsolutePath(absolutePath, rootDir) {
|
|
514
|
+
const content = await node_fs_promises.readFile(absolutePath, 'utf-8');
|
|
515
|
+
const fileNameWithoutExt = node_path.basename(absolutePath, node_path.extname(absolutePath));
|
|
516
|
+
const h1RegExp = /^#\s+(.*)$/m;
|
|
517
|
+
const match = content.match(h1RegExp);
|
|
518
|
+
const { frontmatter } = loadFrontMatter(content, absolutePath, rootDir);
|
|
519
|
+
return {
|
|
520
|
+
title: extractTextAndId(frontmatter.title || match?.[1] || fileNameWithoutExt)[0],
|
|
521
|
+
overviewHeaders: frontmatter.overviewHeaders,
|
|
522
|
+
context: frontmatter.context
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
function getHmrFileKey(realPath, docsDir) {
|
|
526
|
+
return realPath ? slash(relative(docsDir, realPath).replace(external_node_path_extname(realPath), '')) : '';
|
|
527
|
+
}
|
|
528
|
+
async function fsDirToMetaItems(workDir, extensions) {
|
|
529
|
+
let subItems = await readdir(workDir);
|
|
530
|
+
subItems = subItems.filter((item)=>{
|
|
531
|
+
const hasExtension = extensions.some((ext)=>item.endsWith(ext));
|
|
532
|
+
const hasSameBaseName = subItems.some((elem)=>{
|
|
533
|
+
const baseName = elem.replace(/\.[^/.]+$/, '');
|
|
534
|
+
return baseName === item.replace(/\.[^/.]+$/, '') && elem !== item;
|
|
535
|
+
});
|
|
536
|
+
return !(hasExtension && hasSameBaseName);
|
|
537
|
+
});
|
|
538
|
+
const sideMeta = (await Promise.all(subItems.map(async (item)=>{
|
|
539
|
+
if ('_meta.json' === item) return null;
|
|
540
|
+
const stat = await promises_stat(join(workDir, item));
|
|
541
|
+
if (stat.isDirectory()) return {
|
|
542
|
+
type: 'dir',
|
|
543
|
+
name: item
|
|
544
|
+
};
|
|
545
|
+
return extensions.some((ext)=>item.endsWith(ext)) ? item : null;
|
|
546
|
+
}))).filter(Boolean);
|
|
547
|
+
return sideMeta;
|
|
548
|
+
}
|
|
549
|
+
async function metaItemToSidebarItem(metaItem, workDir, docsDir, extensions, isFirstDir = false) {
|
|
550
|
+
if ('string' == typeof metaItem) return metaFileItemToSidebarItem(metaItem, workDir, docsDir, extensions);
|
|
551
|
+
const { type } = metaItem;
|
|
552
|
+
if ('file' === type) return metaFileItemToSidebarItem(metaItem, workDir, docsDir, extensions);
|
|
553
|
+
if ('dir' === type) {
|
|
554
|
+
const { name, label, collapsible, collapsed, tag: metaJsonTag, context: metaJsonContext, overviewHeaders: metaJsonOverviewHeaders } = metaItem;
|
|
555
|
+
const dirAbsolutePath = join(workDir, name);
|
|
556
|
+
const dirMetaJsonPath = join(dirAbsolutePath, '_meta.json');
|
|
557
|
+
const isMetaJsonExist = await utils_pathExists(dirMetaJsonPath);
|
|
558
|
+
let dirMetaJson = [];
|
|
559
|
+
dirMetaJson = isMetaJsonExist ? await utils_readJson(dirMetaJsonPath) : await fsDirToMetaItems(dirAbsolutePath, extensions);
|
|
560
|
+
async function getItems(withoutIndex = false) {
|
|
561
|
+
const items = await Promise.all((withoutIndex ? dirMetaJson.filter((i)=>{
|
|
562
|
+
let name;
|
|
563
|
+
if ('object' == typeof i && 'type' in i && 'file' === i.type) name = i.name;
|
|
564
|
+
else {
|
|
565
|
+
if ('string' != typeof i) return true;
|
|
566
|
+
name = i;
|
|
567
|
+
}
|
|
568
|
+
return 'index.md' !== name && 'index.mdx' !== i && 'index' !== i;
|
|
569
|
+
}) : dirMetaJson).map((item)=>metaItemToSidebarItem(item, dirAbsolutePath, docsDir, extensions)));
|
|
570
|
+
return items;
|
|
571
|
+
}
|
|
572
|
+
try {
|
|
573
|
+
const sameNameFile = await metaFileItemToSidebarItem(name, workDir, docsDir, extensions);
|
|
574
|
+
const { link, text, _fileKey, context, overviewHeaders, tag } = sameNameFile;
|
|
575
|
+
return {
|
|
576
|
+
text: label || text || name,
|
|
577
|
+
collapsible,
|
|
578
|
+
collapsed,
|
|
579
|
+
items: await getItems(),
|
|
580
|
+
link,
|
|
581
|
+
tag: metaJsonTag || tag,
|
|
582
|
+
overviewHeaders: metaJsonOverviewHeaders || overviewHeaders,
|
|
583
|
+
context: metaJsonContext || context,
|
|
584
|
+
_fileKey
|
|
585
|
+
};
|
|
586
|
+
} catch (e) {
|
|
587
|
+
logger.debug(e);
|
|
588
|
+
const isIndexInMetaJsonIndex = dirMetaJson.find((i)=>{
|
|
589
|
+
if ('string' == typeof i) return 'index' === i.replace(external_node_path_extname(i), '');
|
|
590
|
+
return false;
|
|
591
|
+
});
|
|
592
|
+
const isIndexFileExists = await utils_pathExists(join(dirAbsolutePath, 'index.mdx')) || await utils_pathExists(join(dirAbsolutePath, 'index.md'));
|
|
593
|
+
if (isMetaJsonExist && isIndexInMetaJsonIndex || !isIndexFileExists) return {
|
|
594
|
+
text: label || name,
|
|
595
|
+
collapsible,
|
|
596
|
+
collapsed,
|
|
597
|
+
items: await getItems(),
|
|
598
|
+
link: void 0,
|
|
599
|
+
tag: metaJsonTag,
|
|
600
|
+
overviewHeaders: metaJsonOverviewHeaders,
|
|
601
|
+
context: metaJsonContext,
|
|
602
|
+
_fileKey: getHmrFileKey(dirAbsolutePath, docsDir)
|
|
603
|
+
};
|
|
604
|
+
{
|
|
605
|
+
const indexFile = await metaFileItemToSidebarItem('index', dirAbsolutePath, docsDir, extensions);
|
|
606
|
+
const { link, text, _fileKey, context, overviewHeaders, tag } = indexFile;
|
|
607
|
+
return {
|
|
608
|
+
text: label || text || name,
|
|
609
|
+
collapsible,
|
|
610
|
+
collapsed,
|
|
611
|
+
items: await getItems(!isFirstDir),
|
|
612
|
+
link,
|
|
613
|
+
tag: metaJsonTag || tag,
|
|
614
|
+
overviewHeaders: metaJsonOverviewHeaders || overviewHeaders,
|
|
615
|
+
context: metaJsonContext || context,
|
|
616
|
+
_fileKey
|
|
617
|
+
};
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
if ('custom-link' === type) return metaCustomLinkItemToSidebarItem(metaItem, workDir, docsDir);
|
|
622
|
+
if ('divider' === type || 'section-header' === type) return metaDividerToSidebarItem(metaItem);
|
|
623
|
+
throw new Error(`Unknown meta item type: ${metaItem.type}, please check it in "${join(workDir, '_meta.json')}".`);
|
|
624
|
+
}
|
|
625
|
+
async function detectFilePath(absolutePath, extensions) {
|
|
626
|
+
const ext = external_node_path_extname(absolutePath);
|
|
627
|
+
if (ext && extensions.includes(ext)) return absolutePath;
|
|
628
|
+
for (const extension of extensions){
|
|
629
|
+
const realPath = absolutePath + extension;
|
|
630
|
+
if (await utils_pathExists(realPath)) return realPath;
|
|
631
|
+
}
|
|
632
|
+
throw new Error(`The file extension "${ext}" is not supported, please use one of the following extensions: ${extensions.join(', ')}`);
|
|
633
|
+
}
|
|
634
|
+
async function metaFileItemToSidebarItem(metaItemRaw, workDir, docsDir, extensions) {
|
|
635
|
+
let metaItem = null;
|
|
636
|
+
metaItem = 'string' == typeof metaItemRaw ? {
|
|
637
|
+
name: metaItemRaw,
|
|
638
|
+
type: 'file'
|
|
639
|
+
} : metaItemRaw;
|
|
640
|
+
const { name, context, label, overviewHeaders, tag } = metaItem;
|
|
641
|
+
if ('string' != typeof name) throw new Error(`The file name "${name}" is not a string, please check it in "${join(workDir, '_meta.json')}".`);
|
|
642
|
+
const absolutePath = join(workDir, name);
|
|
643
|
+
let absolutePathWithExt;
|
|
644
|
+
try {
|
|
645
|
+
absolutePathWithExt = await detectFilePath(absolutePath, extensions);
|
|
646
|
+
} catch {
|
|
647
|
+
throw new Error(`The file "${absolutePath}" does not exist, please check it in "${join(workDir, '_meta.json')}".`);
|
|
648
|
+
}
|
|
649
|
+
const link = absolutePathToLink(absolutePathWithExt, docsDir);
|
|
650
|
+
const info = await extractInfoFromFrontmatterWithAbsolutePath(absolutePathWithExt, docsDir);
|
|
651
|
+
const title = label || info.title;
|
|
652
|
+
return {
|
|
653
|
+
text: title,
|
|
654
|
+
link,
|
|
655
|
+
tag,
|
|
656
|
+
overviewHeaders: info.overviewHeaders || overviewHeaders,
|
|
657
|
+
context: info.context || context,
|
|
658
|
+
_fileKey: getHmrFileKey(absolutePathWithExt, docsDir)
|
|
659
|
+
};
|
|
660
|
+
}
|
|
661
|
+
function metaCustomLinkItemToSidebarItem(metaItem, workDir, docsDir) {
|
|
662
|
+
const { label, link, context, tag } = metaItem;
|
|
663
|
+
if (void 0 === link) throw new Error(`The custom link "${label}" does not have a link, please check it in "${join(workDir, '_meta.json')}".`);
|
|
664
|
+
if (isExternalUrl(link)) return {
|
|
665
|
+
text: label ?? link,
|
|
666
|
+
link,
|
|
667
|
+
tag,
|
|
668
|
+
context
|
|
669
|
+
};
|
|
670
|
+
return {
|
|
671
|
+
text: label ?? link,
|
|
672
|
+
link: addRoutePrefix(workDir, docsDir, link),
|
|
673
|
+
tag,
|
|
674
|
+
context
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
function metaDividerToSidebarItem(metaItem) {
|
|
678
|
+
const { type } = metaItem;
|
|
679
|
+
if ('divider' === type) {
|
|
680
|
+
const { dashed } = metaItem;
|
|
681
|
+
return {
|
|
682
|
+
dividerType: dashed ? 'dashed' : 'solid'
|
|
683
|
+
};
|
|
684
|
+
}
|
|
685
|
+
const { label, tag } = metaItem;
|
|
686
|
+
return {
|
|
687
|
+
sectionHeaderText: label ?? '',
|
|
688
|
+
tag
|
|
689
|
+
};
|
|
690
|
+
}
|
|
691
|
+
async function scanSideMeta(workDir, docsDir, extensions) {
|
|
692
|
+
const dir = await metaItemToSidebarItem({
|
|
693
|
+
type: 'dir',
|
|
694
|
+
name: ''
|
|
695
|
+
}, workDir, docsDir, extensions, true);
|
|
696
|
+
return dir.items;
|
|
697
|
+
}
|
|
698
|
+
async function scanNav(workDir, docsDir) {
|
|
699
|
+
let navConfig;
|
|
700
|
+
const rootNavJson = node_path.resolve(workDir, '_nav.json');
|
|
701
|
+
try {
|
|
702
|
+
navConfig = await utils_readJson(rootNavJson);
|
|
703
|
+
} catch (e) {
|
|
704
|
+
logger.error('[auto-nav-sidebar]', `Generate nav meta error: ${rootNavJson} failed`);
|
|
705
|
+
navConfig = [];
|
|
706
|
+
}
|
|
707
|
+
navConfig.forEach((navItem)=>{
|
|
708
|
+
if ('items' in navItem) navItem.items.forEach((item)=>{
|
|
709
|
+
if ('link' in item && !isExternalUrl(item.link)) item.link = addRoutePrefix(workDir, docsDir, item.link);
|
|
710
|
+
});
|
|
711
|
+
if ('link' in navItem && !isExternalUrl(navItem.link)) navItem.link = addRoutePrefix(workDir, docsDir, navItem.link);
|
|
712
|
+
});
|
|
713
|
+
return navConfig;
|
|
714
|
+
}
|
|
715
|
+
async function walk(workDir, docsDir, extensions) {
|
|
716
|
+
const rootNavJson = node_path.resolve(workDir, '_nav.json');
|
|
717
|
+
const rootMetaJson = node_path.resolve(workDir, '_meta.json');
|
|
718
|
+
const isRootNavJsonExist = await pathExists(rootNavJson);
|
|
719
|
+
const isRootMetaJsonExist = await pathExists(rootMetaJson);
|
|
720
|
+
if (isRootMetaJsonExist) {
|
|
721
|
+
const metaConfig = await utils_readJson(rootMetaJson);
|
|
722
|
+
hintNavJsonChangeThenPanic(metaConfig, workDir, docsDir);
|
|
723
|
+
}
|
|
724
|
+
if (isRootNavJsonExist) {
|
|
725
|
+
const navConfig = await scanNav(workDir, docsDir);
|
|
726
|
+
const subDirs = (await Promise.all((await node_fs_promises.readdir(workDir)).map((v)=>node_fs_promises.stat(node_path.join(workDir, v)).then((s)=>{
|
|
727
|
+
if (s.isDirectory() && 'node_modules' !== v) return v;
|
|
728
|
+
return false;
|
|
729
|
+
})))).filter(Boolean);
|
|
730
|
+
const sidebarConfig = {};
|
|
731
|
+
await Promise.all(subDirs.map(async (subDir)=>{
|
|
732
|
+
const sidebarGroupKey = addRoutePrefix(workDir, docsDir, subDir);
|
|
733
|
+
sidebarConfig[sidebarGroupKey] = await scanSideMeta(node_path.join(workDir, subDir), docsDir, extensions);
|
|
734
|
+
}));
|
|
735
|
+
if (isRootMetaJsonExist) {
|
|
736
|
+
const rootMetaConfig = await scanSideMeta(workDir, docsDir, extensions);
|
|
737
|
+
sidebarConfig['/'] = rootMetaConfig;
|
|
738
|
+
}
|
|
739
|
+
return {
|
|
740
|
+
nav: navConfig,
|
|
741
|
+
sidebar: sidebarConfig
|
|
742
|
+
};
|
|
743
|
+
}
|
|
744
|
+
return {
|
|
745
|
+
nav: [],
|
|
746
|
+
sidebar: {
|
|
747
|
+
'/': await scanSideMeta(workDir, docsDir, extensions)
|
|
748
|
+
}
|
|
749
|
+
};
|
|
750
|
+
}
|
|
751
|
+
function combineWalkResult(walks, versions) {
|
|
752
|
+
return walks.reduce((acc, cur, curIndex)=>({
|
|
753
|
+
nav: {
|
|
754
|
+
...acc.nav,
|
|
755
|
+
[versions[curIndex] || 'default']: cur.nav
|
|
756
|
+
},
|
|
757
|
+
sidebar: {
|
|
758
|
+
...acc.sidebar,
|
|
759
|
+
...cur.sidebar
|
|
760
|
+
}
|
|
761
|
+
}), {
|
|
762
|
+
nav: {},
|
|
763
|
+
sidebar: {}
|
|
764
|
+
});
|
|
765
|
+
}
|
|
766
|
+
function processLocales(langs, versions, root, extensions) {
|
|
767
|
+
return Promise.all(langs.map(async (lang)=>{
|
|
768
|
+
const walks = versions.length ? await Promise.all(versions.map((version)=>walk(node_path.join(root, version, lang), root, extensions))) : [
|
|
769
|
+
await walk(node_path.join(root, lang), root, extensions)
|
|
770
|
+
];
|
|
771
|
+
return combineWalkResult(walks, versions);
|
|
772
|
+
}));
|
|
773
|
+
}
|
|
774
|
+
async function modifyConfigWithAutoNavSide(config) {
|
|
775
|
+
const themeConfig = config.themeConfig || {};
|
|
776
|
+
const haveNavSidebarConfig = themeConfig.nav || themeConfig.sidebar || themeConfig.locales?.[0]?.nav || themeConfig.locales?.[0]?.sidebar;
|
|
777
|
+
if (haveNavSidebarConfig) return config;
|
|
778
|
+
config.themeConfig = config.themeConfig || {};
|
|
779
|
+
config.themeConfig.locales = config.themeConfig.locales || config.locales || [];
|
|
780
|
+
const langs = config.themeConfig.locales.map((locale)=>locale.lang);
|
|
781
|
+
const hasLocales = langs.length > 0;
|
|
782
|
+
const hasLang = Boolean(config.lang);
|
|
783
|
+
const versions = config.multiVersion?.versions || [];
|
|
784
|
+
const { extensions = DEFAULT_PAGE_EXTENSIONS } = config?.route || {};
|
|
785
|
+
if (hasLocales) {
|
|
786
|
+
const metaInfo = await processLocales(langs, versions, config.root, extensions);
|
|
787
|
+
config.themeConfig.locales = config.themeConfig.locales.map((item, index)=>({
|
|
788
|
+
...item,
|
|
789
|
+
...metaInfo[index]
|
|
790
|
+
}));
|
|
791
|
+
} else {
|
|
792
|
+
if (hasLang) {
|
|
793
|
+
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");
|
|
794
|
+
return config;
|
|
795
|
+
}
|
|
796
|
+
const walks = versions.length ? await Promise.all(versions.map((version)=>walk(node_path.join(config.root, version), config.root, extensions))) : [
|
|
797
|
+
await walk(config.root, config.root, extensions)
|
|
798
|
+
];
|
|
799
|
+
const combined = combineWalkResult(walks, versions);
|
|
800
|
+
config.themeConfig = {
|
|
801
|
+
...config.themeConfig,
|
|
802
|
+
...combined
|
|
803
|
+
};
|
|
804
|
+
}
|
|
805
|
+
return config;
|
|
806
|
+
}
|
|
478
807
|
let flattenMdxContent_resolver;
|
|
479
808
|
let startFlatten = false;
|
|
480
809
|
const processor = createProcessor();
|
|
@@ -673,6 +1002,7 @@ var types_RuntimeModuleID = /*#__PURE__*/ function(RuntimeModuleID) {
|
|
|
673
1002
|
RuntimeModuleID["SearchIndexHash"] = "virtual-search-index-hash";
|
|
674
1003
|
RuntimeModuleID["I18nText"] = "virtual-i18n-text";
|
|
675
1004
|
RuntimeModuleID["SearchHooks"] = "virtual-search-hooks";
|
|
1005
|
+
RuntimeModuleID["RuntimeConfig"] = "virtual-runtime-config";
|
|
676
1006
|
return RuntimeModuleID;
|
|
677
1007
|
}({});
|
|
678
1008
|
const DEFAULT_I18N_SOURCE = join(process.cwd(), 'i18n.json');
|
|
@@ -698,8 +1028,8 @@ const i18nVMPlugin = (context)=>{
|
|
|
698
1028
|
}
|
|
699
1029
|
};
|
|
700
1030
|
};
|
|
701
|
-
function normalizeThemeConfig(docConfig
|
|
702
|
-
const { locales: siteLocales,
|
|
1031
|
+
function normalizeThemeConfig(docConfig) {
|
|
1032
|
+
const { locales: siteLocales, lang, replaceRules = [], multiVersion } = docConfig;
|
|
703
1033
|
const { versions = [] } = multiVersion || {};
|
|
704
1034
|
const hasMultiVersion = versions.length > 0;
|
|
705
1035
|
docConfig.themeConfig = docConfig.themeConfig || {};
|
|
@@ -708,7 +1038,7 @@ function normalizeThemeConfig(docConfig, pages = []) {
|
|
|
708
1038
|
const i18nTextData = getI18nData(docConfig);
|
|
709
1039
|
const normalizeLinkPrefix = (link = '', currentLang = '')=>{
|
|
710
1040
|
const normalizedLink = slash(link);
|
|
711
|
-
if (!currentLang || !link ||
|
|
1041
|
+
if (!currentLang || !link || normalizedLink.startsWith(`/${currentLang}`) || isExternalUrl(normalizedLink) || hasMultiVersion) return normalizedLink;
|
|
712
1042
|
return lang === currentLang ? normalizedLink : `/${currentLang}${addLeadingSlash(normalizedLink)}`;
|
|
713
1043
|
};
|
|
714
1044
|
const getI18nText = (key = '', currentLang = '')=>{
|
|
@@ -733,15 +1063,6 @@ function normalizeThemeConfig(docConfig, pages = []) {
|
|
|
733
1063
|
tag: item.tag,
|
|
734
1064
|
items: item.items.map((subItem)=>normalizeSidebarItem(subItem))
|
|
735
1065
|
};
|
|
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
1066
|
return {
|
|
746
1067
|
...item,
|
|
747
1068
|
text: applyReplaceRules(getI18nText(item.text, currentLang), replaceRules),
|
|
@@ -852,8 +1173,7 @@ async function siteDataVMPlugin(context) {
|
|
|
852
1173
|
description: userConfig?.description || '',
|
|
853
1174
|
icon: getIconUrlPath(userConfig?.icon) || '',
|
|
854
1175
|
route: userConfig?.route || {},
|
|
855
|
-
themeConfig: normalizeThemeConfig(userConfig
|
|
856
|
-
base: userConfig?.base || '/',
|
|
1176
|
+
themeConfig: normalizeThemeConfig(userConfig),
|
|
857
1177
|
lang: userConfig?.lang || '',
|
|
858
1178
|
locales: userConfig?.locales || userConfig.themeConfig?.locales || [],
|
|
859
1179
|
logo: userConfig?.logo || '',
|
|
@@ -956,6 +1276,14 @@ const routeListVMPlugin = (context)=>{
|
|
|
956
1276
|
[types_RuntimeModuleID.Routes]: ()=>routeService.generateRoutesCode()
|
|
957
1277
|
};
|
|
958
1278
|
};
|
|
1279
|
+
const runtimeConfigVMPlugin = (context)=>({
|
|
1280
|
+
[types_RuntimeModuleID.RuntimeConfig]: ()=>{
|
|
1281
|
+
const { config } = context;
|
|
1282
|
+
const { base } = config;
|
|
1283
|
+
const normalizedBase = normalizeSlash(base ?? '/');
|
|
1284
|
+
return `export const base = ${JSON.stringify(normalizedBase)};`;
|
|
1285
|
+
}
|
|
1286
|
+
});
|
|
959
1287
|
const searchHookVMPlugin = (context)=>({
|
|
960
1288
|
[`${types_RuntimeModuleID.SearchHooks}`]: ()=>{
|
|
961
1289
|
const { config } = context;
|
|
@@ -1145,9 +1473,8 @@ async function renderPages(routeService, config, pluginDriver, ssrBundlePath, ht
|
|
|
1145
1473
|
}
|
|
1146
1474
|
try {
|
|
1147
1475
|
const routes = routeService.getRoutes();
|
|
1148
|
-
const base = config?.base ?? '';
|
|
1149
1476
|
const additionalRoutes = (await pluginDriver.addSSGRoutes()).map((route)=>({
|
|
1150
|
-
routePath:
|
|
1477
|
+
routePath: route.path
|
|
1151
1478
|
}));
|
|
1152
1479
|
const allRoutes = [
|
|
1153
1480
|
...routes,
|
|
@@ -1200,6 +1527,7 @@ const rsbuildPluginSSG = ({ routeService, config, pluginDriver })=>({
|
|
|
1200
1527
|
async setup (api) {
|
|
1201
1528
|
api.onBeforeBuild(()=>{
|
|
1202
1529
|
let htmlTemplate = '';
|
|
1530
|
+
let hasError = false;
|
|
1203
1531
|
const indexHtmlEmittedInWeb = new Promise((resolve, reject)=>{
|
|
1204
1532
|
api.processAssets({
|
|
1205
1533
|
stage: 'report',
|
|
@@ -1208,6 +1536,10 @@ const rsbuildPluginSSG = ({ routeService, config, pluginDriver })=>({
|
|
|
1208
1536
|
]
|
|
1209
1537
|
}, ({ assets, compilation, environment })=>{
|
|
1210
1538
|
if ('web' !== environment.name) return;
|
|
1539
|
+
if (compilation.errors.length > 0) {
|
|
1540
|
+
hasError = true;
|
|
1541
|
+
return;
|
|
1542
|
+
}
|
|
1211
1543
|
for (const [assetName, assetSource] of Object.entries(assets))if ('index.html' === assetName) {
|
|
1212
1544
|
htmlTemplate = assetSource.source().toString();
|
|
1213
1545
|
compilation.deleteAsset(assetName);
|
|
@@ -1229,6 +1561,11 @@ const rsbuildPluginSSG = ({ routeService, config, pluginDriver })=>({
|
|
|
1229
1561
|
]
|
|
1230
1562
|
}, async ({ assets, compilation, environment, compiler })=>{
|
|
1231
1563
|
if ('node' !== environment.name) return;
|
|
1564
|
+
if (compilation.errors.length > 0) {
|
|
1565
|
+
hasError = true;
|
|
1566
|
+
return;
|
|
1567
|
+
}
|
|
1568
|
+
if (hasError) return;
|
|
1232
1569
|
const distPath = environment.distPath;
|
|
1233
1570
|
const ssgFolderPath = join(distPath, NODE_SSG_BUNDLE_FOLDER);
|
|
1234
1571
|
const mainCjsAbsolutePath = join(ssgFolderPath, NODE_SSG_BUNDLE_NAME);
|
|
@@ -1429,7 +1766,8 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1429
1766
|
...globalStylesVMPlugin(context),
|
|
1430
1767
|
...searchHookVMPlugin(context),
|
|
1431
1768
|
...routeListVMPlugin(context),
|
|
1432
|
-
...await getVirtualModulesFromPlugins(pluginDriver)
|
|
1769
|
+
...await getVirtualModulesFromPlugins(pluginDriver),
|
|
1770
|
+
...runtimeConfigVMPlugin(context)
|
|
1433
1771
|
}
|
|
1434
1772
|
}),
|
|
1435
1773
|
...enableSSG ? [
|
|
@@ -1442,19 +1780,18 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1442
1780
|
],
|
|
1443
1781
|
server: {
|
|
1444
1782
|
port: !isProduction() && process.env.PORT ? Number(process.env.PORT) : void 0,
|
|
1445
|
-
printUrls: ({ urls })=>urls.map((url)=>`${url}/${removeLeadingSlash(base)}`),
|
|
1446
1783
|
publicDir: {
|
|
1447
1784
|
name: node_path.join(userDocRoot, PUBLIC_DIR)
|
|
1448
|
-
}
|
|
1785
|
+
},
|
|
1786
|
+
...base.length > 0 ? {
|
|
1787
|
+
base: removeTrailingSlash(base)
|
|
1788
|
+
} : {}
|
|
1449
1789
|
},
|
|
1450
1790
|
dev: {
|
|
1451
1791
|
lazyCompilation: 'false' !== process.env.RSPRESS_LAZY_COMPILATION,
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
middlewares.unshift(serveSearchIndexMiddleware(config));
|
|
1456
|
-
}
|
|
1457
|
-
],
|
|
1792
|
+
setupMiddlewares: (middlewares)=>{
|
|
1793
|
+
middlewares.unshift(serveSearchIndexMiddleware(config));
|
|
1794
|
+
},
|
|
1458
1795
|
cliShortcuts: {
|
|
1459
1796
|
custom: (shortcuts)=>shortcuts.filter(({ key })=>'r' !== key)
|
|
1460
1797
|
}
|
|
@@ -1608,21 +1945,22 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1608
1945
|
}
|
|
1609
1946
|
};
|
|
1610
1947
|
}
|
|
1611
|
-
async function initRsbuild(rootDir,
|
|
1948
|
+
async function initRsbuild(rootDir, _config, pluginDriver, enableSSG, extraRsbuildConfig) {
|
|
1612
1949
|
const cwd = process.cwd();
|
|
1613
|
-
const userDocRoot = node_path.resolve(rootDir ||
|
|
1614
|
-
const builderPlugins =
|
|
1950
|
+
const userDocRoot = node_path.resolve(rootDir || _config?.root || cwd);
|
|
1951
|
+
const builderPlugins = _config?.builderPlugins ?? [];
|
|
1615
1952
|
const runtimeTempDir = node_path.join(RSPRESS_TEMP_DIR, 'runtime');
|
|
1616
1953
|
const runtimeAbsTempDir = node_path.join(cwd, 'node_modules', runtimeTempDir);
|
|
1617
1954
|
await node_fs_promises.mkdir(runtimeAbsTempDir, {
|
|
1618
1955
|
recursive: true
|
|
1619
1956
|
});
|
|
1620
1957
|
const routeService = await RouteService.create({
|
|
1621
|
-
config,
|
|
1958
|
+
config: _config,
|
|
1622
1959
|
runtimeTempDir: runtimeAbsTempDir,
|
|
1623
1960
|
scanDir: userDocRoot,
|
|
1624
1961
|
pluginDriver
|
|
1625
1962
|
});
|
|
1963
|
+
const config = await modifyConfigWithAutoNavSide(_config);
|
|
1626
1964
|
const { createRsbuild, mergeRsbuildConfig } = await import("@rsbuild/core");
|
|
1627
1965
|
const internalRsbuildConfig = await createInternalBuildConfig(userDocRoot, config, enableSSG, routeService, pluginDriver);
|
|
1628
1966
|
const rsbuild = await createRsbuild({
|
|
@@ -1713,8 +2051,8 @@ async function dev(options) {
|
|
|
1713
2051
|
await pluginDriver.init();
|
|
1714
2052
|
const modifiedConfig = await pluginDriver.modifyConfig();
|
|
1715
2053
|
try {
|
|
1716
|
-
await pluginDriver.beforeBuild();
|
|
1717
2054
|
const rsbuild = await initRsbuild(docDirectory, modifiedConfig, pluginDriver, false, extraBuilderConfig);
|
|
2055
|
+
await pluginDriver.beforeBuild();
|
|
1718
2056
|
rsbuild.onDevCompileDone(async ()=>{
|
|
1719
2057
|
await pluginDriver.afterBuild();
|
|
1720
2058
|
});
|
|
@@ -1730,11 +2068,13 @@ async function dev(options) {
|
|
|
1730
2068
|
async function bundle(docDirectory, config, pluginDriver, enableSSG) {
|
|
1731
2069
|
try {
|
|
1732
2070
|
const rsbuild = await initRsbuild(docDirectory, config, pluginDriver, enableSSG);
|
|
2071
|
+
await pluginDriver.beforeBuild();
|
|
1733
2072
|
await rsbuild.build();
|
|
1734
2073
|
} finally{
|
|
1735
2074
|
await writeSearchIndex(config);
|
|
1736
2075
|
await checkLanguageParity(config);
|
|
1737
2076
|
}
|
|
2077
|
+
await pluginDriver.afterBuild();
|
|
1738
2078
|
}
|
|
1739
2079
|
function emptyDir(path) {
|
|
1740
2080
|
return node_fs_promises.rm(path, {
|
|
@@ -1747,12 +2087,10 @@ async function build(options) {
|
|
|
1747
2087
|
const pluginDriver = new PluginDriver(config, true);
|
|
1748
2088
|
await pluginDriver.init();
|
|
1749
2089
|
const modifiedConfig = await pluginDriver.modifyConfig();
|
|
1750
|
-
await pluginDriver.beforeBuild();
|
|
1751
2090
|
const ssgConfig = modifiedConfig.ssg ?? true;
|
|
1752
2091
|
await emptyDir(constants_TEMP_DIR);
|
|
1753
2092
|
await bundle(docDirectory, modifiedConfig, pluginDriver, ssgConfig);
|
|
1754
2093
|
if (!ssgConfig) hintSSGFalse();
|
|
1755
|
-
await pluginDriver.afterBuild();
|
|
1756
2094
|
}
|
|
1757
2095
|
async function serve(options) {
|
|
1758
2096
|
const { config, port: userPort, host: userHost } = options;
|
package/dist/loader.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { AdditionalPage } from '@rspress/shared';
|
|
|
2
2
|
import { DefaultThemeConfig } from '@rspress/shared';
|
|
3
3
|
import type { PageIndexInfo } from '@rspress/shared';
|
|
4
4
|
import type { RouteMeta } from '@rspress/shared';
|
|
5
|
-
import
|
|
5
|
+
import { Rspack as Rspack_2 } from '@rsbuild/core';
|
|
6
6
|
import type { RspressPlugin } from '@rspress/shared';
|
|
7
7
|
import type { UserConfig } from '@rspress/shared';
|
|
8
8
|
|
|
@@ -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[];
|
|
@@ -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,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import 'module';
|
|
2
2
|
/*#__PURE__*/ import.meta.url;
|
|
3
|
-
import { logger } from "@
|
|
3
|
+
import { logger } from "@rsbuild/core";
|
|
4
4
|
import { compile, compileWithCrossCompilerCache } from "./processor.js";
|
|
5
5
|
async function mdxLoader(source) {
|
|
6
6
|
this.cacheable(true);
|
|
@@ -35,10 +35,9 @@ async function mdxLoader(source) {
|
|
|
35
35
|
}
|
|
36
36
|
} catch (e) {
|
|
37
37
|
if (e instanceof Error) {
|
|
38
|
-
logger.error(`MDX compile error: ${e.message} in ${filepath}`);
|
|
39
38
|
logger.debug(e);
|
|
40
39
|
callback({
|
|
41
|
-
message: e.message
|
|
40
|
+
message: `MDX compile error: ${e.message} in ${filepath}`,
|
|
42
41
|
name: `${filepath} compile error`
|
|
43
42
|
});
|
|
44
43
|
}
|
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[];
|
|
@@ -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,8 +1,7 @@
|
|
|
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";
|
|
5
|
-
import { logger } from "@rspress/shared/logger";
|
|
6
5
|
import { extractTextAndId, getNodeAttribute, loadFrontMatter } from "@rspress/shared/node-utils";
|
|
7
6
|
import node_os from "node:os";
|
|
8
7
|
import rehype_external_links from "rehype-external-links";
|
|
@@ -12,6 +11,7 @@ import github_slugger from "github-slugger";
|
|
|
12
11
|
import { headingRank } from "hast-util-heading-rank";
|
|
13
12
|
import { visit } from "unist-util-visit";
|
|
14
13
|
import { addLeadingSlash, cleanUrl, isExternalUrl, isProduction, normalizeHref, parseUrl, slash as shared_slash } from "@rspress/shared";
|
|
14
|
+
import { logger } from "@rspress/shared/logger";
|
|
15
15
|
import { DEFAULT_PAGE_EXTENSIONS } from "@rspress/shared/constants";
|
|
16
16
|
import { visitChildren } from "unist-util-visit-children";
|
|
17
17
|
import rehype from "@shikijs/rehype";
|
|
@@ -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
|
});
|
|
@@ -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,
|
|
@@ -360,6 +360,204 @@ function createRehypeShikiOptions(showLineNumbers, options) {
|
|
|
360
360
|
transformers: newTransformers
|
|
361
361
|
};
|
|
362
362
|
}
|
|
363
|
+
const DIRECTIVE_TYPES = [
|
|
364
|
+
'tip',
|
|
365
|
+
'note',
|
|
366
|
+
'warning',
|
|
367
|
+
'caution',
|
|
368
|
+
'danger',
|
|
369
|
+
'info',
|
|
370
|
+
'details'
|
|
371
|
+
];
|
|
372
|
+
const REGEX_BEGIN = /^\s*:::\s*(\w+)\s*(.*)?/;
|
|
373
|
+
const REGEX_END = /\s*:::$/;
|
|
374
|
+
const REGEX_GH_BEGIN = /^\s*\s*\[!(\w+)\]\s*(.*)?/;
|
|
375
|
+
const TITLE_REGEX_IN_MD = /{\s*title=["']?(.+)}\s*/;
|
|
376
|
+
const TITLE_REGEX_IN_MDX = /\s*title=["']?(.+)\s*/;
|
|
377
|
+
const trimTailingQuote = (str)=>str.replace(/['"]$/g, '');
|
|
378
|
+
const parseTitle = (rawTitle = '', isMDX = false)=>{
|
|
379
|
+
const matched = rawTitle?.match(isMDX ? TITLE_REGEX_IN_MDX : TITLE_REGEX_IN_MD);
|
|
380
|
+
return trimTailingQuote(matched?.[1] || rawTitle);
|
|
381
|
+
};
|
|
382
|
+
const createContainer = (type, title, children)=>{
|
|
383
|
+
const isDetails = 'details' === type;
|
|
384
|
+
const rootHName = isDetails ? 'details' : 'div';
|
|
385
|
+
const titleHName = isDetails ? 'summary' : 'div';
|
|
386
|
+
return {
|
|
387
|
+
type: 'containerDirective',
|
|
388
|
+
data: {
|
|
389
|
+
hName: rootHName,
|
|
390
|
+
hProperties: {
|
|
391
|
+
class: `rspress-directive ${type}`
|
|
392
|
+
}
|
|
393
|
+
},
|
|
394
|
+
children: [
|
|
395
|
+
{
|
|
396
|
+
type: 'paragraph',
|
|
397
|
+
data: {
|
|
398
|
+
hName: titleHName,
|
|
399
|
+
hProperties: {
|
|
400
|
+
class: 'rspress-directive-title'
|
|
401
|
+
}
|
|
402
|
+
},
|
|
403
|
+
children: [
|
|
404
|
+
{
|
|
405
|
+
type: 'text',
|
|
406
|
+
value: title || type.toUpperCase()
|
|
407
|
+
}
|
|
408
|
+
]
|
|
409
|
+
},
|
|
410
|
+
{
|
|
411
|
+
type: 'paragraph',
|
|
412
|
+
data: {
|
|
413
|
+
hName: 'div',
|
|
414
|
+
hProperties: {
|
|
415
|
+
class: 'rspress-directive-content'
|
|
416
|
+
}
|
|
417
|
+
},
|
|
418
|
+
children: children
|
|
419
|
+
}
|
|
420
|
+
]
|
|
421
|
+
};
|
|
422
|
+
};
|
|
423
|
+
function transformer(tree) {
|
|
424
|
+
let i = 0;
|
|
425
|
+
try {
|
|
426
|
+
while(i < tree.children.length){
|
|
427
|
+
const node = tree.children[i];
|
|
428
|
+
if ('children' in node) transformer(node);
|
|
429
|
+
if ('containerDirective' === node.type) {
|
|
430
|
+
const type = node.name;
|
|
431
|
+
if (DIRECTIVE_TYPES.includes(type)) tree.children.splice(i, 1, createContainer(type, node.attributes?.title ?? type.toUpperCase(), node.children));
|
|
432
|
+
} else if ('blockquote' === node.type && node.children[0]?.type === 'paragraph' && node.children[0].children?.[0] && 'value' in node.children[0].children[0]) {
|
|
433
|
+
const initiatorTag = node.children[0].children[0].value;
|
|
434
|
+
const match = initiatorTag.match(REGEX_GH_BEGIN);
|
|
435
|
+
if (match) {
|
|
436
|
+
const [, type] = match;
|
|
437
|
+
if (!DIRECTIVE_TYPES.includes(type.toLowerCase())) {
|
|
438
|
+
i++;
|
|
439
|
+
continue;
|
|
440
|
+
}
|
|
441
|
+
if (1 === node.children.length && 'paragraph' === node.children[0].type) node.children[0].children[0].value = match[2] ?? '';
|
|
442
|
+
const newChild = createContainer(type.toLowerCase(), type.toUpperCase(), 0 === node.children.slice(1).length ? node.children.slice(0) : node.children.slice(1));
|
|
443
|
+
tree.children.splice(i, 1, newChild);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
if ('paragraph' !== node.type || 'text' !== node.children[0].type) {
|
|
447
|
+
i++;
|
|
448
|
+
continue;
|
|
449
|
+
}
|
|
450
|
+
const firstTextNode = node.children[0];
|
|
451
|
+
const text = firstTextNode.value;
|
|
452
|
+
const metaText = text.split('\n')[0];
|
|
453
|
+
const content = text.slice(metaText.length);
|
|
454
|
+
const match = metaText.match(REGEX_BEGIN);
|
|
455
|
+
if (!match) {
|
|
456
|
+
i++;
|
|
457
|
+
continue;
|
|
458
|
+
}
|
|
459
|
+
const [, type, rawTitle] = match;
|
|
460
|
+
let title = parseTitle(rawTitle);
|
|
461
|
+
const titleExpressionNode = node.children[1] && 'mdxTextExpression' === node.children[1].type ? node.children[1] : null;
|
|
462
|
+
if (titleExpressionNode) {
|
|
463
|
+
title = parseTitle(titleExpressionNode.value, true);
|
|
464
|
+
node.children.splice(1, 1);
|
|
465
|
+
}
|
|
466
|
+
if (!DIRECTIVE_TYPES.includes(type)) {
|
|
467
|
+
i++;
|
|
468
|
+
continue;
|
|
469
|
+
}
|
|
470
|
+
const wrappedChildren = [];
|
|
471
|
+
if (content?.endsWith(':::')) {
|
|
472
|
+
wrappedChildren.push({
|
|
473
|
+
type: 'paragraph',
|
|
474
|
+
children: [
|
|
475
|
+
{
|
|
476
|
+
type: 'text',
|
|
477
|
+
value: content.replace(REGEX_END, '')
|
|
478
|
+
}
|
|
479
|
+
]
|
|
480
|
+
});
|
|
481
|
+
const newChild = createContainer(type, title, wrappedChildren);
|
|
482
|
+
tree.children.splice(i, 1, newChild);
|
|
483
|
+
} else {
|
|
484
|
+
const paragraphChild = {
|
|
485
|
+
type: 'paragraph',
|
|
486
|
+
children: []
|
|
487
|
+
};
|
|
488
|
+
wrappedChildren.push(paragraphChild);
|
|
489
|
+
if (content.length) paragraphChild.children.push({
|
|
490
|
+
type: 'text',
|
|
491
|
+
value: content
|
|
492
|
+
});
|
|
493
|
+
paragraphChild.children.push(...node.children.slice(1, -1));
|
|
494
|
+
if (0 === paragraphChild.children.length) wrappedChildren.pop();
|
|
495
|
+
const lastChildInNode = node.children[node.children.length - 1];
|
|
496
|
+
if ('text' === lastChildInNode.type && REGEX_END.test(lastChildInNode.value)) {
|
|
497
|
+
const lastChildInNodeText = lastChildInNode.value;
|
|
498
|
+
const matchedEndContent = lastChildInNodeText.slice(0, -3).trimEnd();
|
|
499
|
+
if (wrappedChildren.length) wrappedChildren[0].children.push({
|
|
500
|
+
type: 'text',
|
|
501
|
+
value: matchedEndContent
|
|
502
|
+
});
|
|
503
|
+
else if (matchedEndContent) wrappedChildren.push({
|
|
504
|
+
type: 'paragraph',
|
|
505
|
+
children: [
|
|
506
|
+
{
|
|
507
|
+
type: 'text',
|
|
508
|
+
value: matchedEndContent
|
|
509
|
+
}
|
|
510
|
+
]
|
|
511
|
+
});
|
|
512
|
+
const newChild = createContainer(type, title, wrappedChildren);
|
|
513
|
+
tree.children.splice(i, 1, newChild);
|
|
514
|
+
i++;
|
|
515
|
+
continue;
|
|
516
|
+
}
|
|
517
|
+
if (lastChildInNode !== firstTextNode && wrappedChildren.length) wrappedChildren[0].children.push(lastChildInNode);
|
|
518
|
+
let j = i + 1;
|
|
519
|
+
while(j < tree.children.length){
|
|
520
|
+
const currentParagraph = tree.children[j];
|
|
521
|
+
if ('paragraph' !== currentParagraph.type) {
|
|
522
|
+
wrappedChildren.push(currentParagraph);
|
|
523
|
+
j++;
|
|
524
|
+
continue;
|
|
525
|
+
}
|
|
526
|
+
const lastChild = currentParagraph.children[currentParagraph.children.length - 1];
|
|
527
|
+
if (lastChild === firstTextNode || 'text' === lastChild.type && REGEX_END.test(lastChild.value)) {
|
|
528
|
+
const lastChildText = lastChild.value;
|
|
529
|
+
const matchedEndContent = lastChildText.slice(0, -3).trimEnd();
|
|
530
|
+
const filteredChildren = currentParagraph.children.filter((child)=>child !== firstTextNode && child !== lastChild);
|
|
531
|
+
if (matchedEndContent) wrappedChildren.push({
|
|
532
|
+
type: 'paragraph',
|
|
533
|
+
children: [
|
|
534
|
+
...filteredChildren,
|
|
535
|
+
{
|
|
536
|
+
type: 'text',
|
|
537
|
+
value: matchedEndContent
|
|
538
|
+
}
|
|
539
|
+
]
|
|
540
|
+
});
|
|
541
|
+
else wrappedChildren.push(...filteredChildren);
|
|
542
|
+
const newChild = createContainer(type, title, wrappedChildren);
|
|
543
|
+
tree.children.splice(i, j - i + 1, newChild);
|
|
544
|
+
break;
|
|
545
|
+
}
|
|
546
|
+
wrappedChildren.push({
|
|
547
|
+
...currentParagraph,
|
|
548
|
+
children: currentParagraph.children.filter((child)=>child !== firstTextNode)
|
|
549
|
+
});
|
|
550
|
+
j++;
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
i++;
|
|
554
|
+
}
|
|
555
|
+
} catch (e) {
|
|
556
|
+
console.log(e);
|
|
557
|
+
throw e;
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
const remarkContainerSyntax = ()=>transformer;
|
|
363
561
|
async function createMDXOptions(options) {
|
|
364
562
|
const { docDirectory, config, checkDeadLinks, routeService, filepath, pluginDriver } = options;
|
|
365
563
|
const format = node_path.extname(filepath).slice(1);
|
|
@@ -378,6 +576,7 @@ async function createMDXOptions(options) {
|
|
|
378
576
|
remarkPlugins: [
|
|
379
577
|
remark_gfm,
|
|
380
578
|
remarkPluginToc,
|
|
579
|
+
remarkContainerSyntax,
|
|
381
580
|
[
|
|
382
581
|
remarkPluginNormalizeLink,
|
|
383
582
|
{
|
|
@@ -478,7 +677,6 @@ MDXContent.__RSPRESS_PAGE_META["${encodeURIComponent(normalizePath(node_path.rel
|
|
|
478
677
|
return result;
|
|
479
678
|
} catch (e) {
|
|
480
679
|
if (e instanceof Error) throw e;
|
|
481
|
-
logger.error(`MDX compile error: ${e} in ${filepath}`);
|
|
482
680
|
throw new Error(`MDX compile error: ${e} in ${filepath}`);
|
|
483
681
|
}
|
|
484
682
|
}
|
|
@@ -3,6 +3,7 @@ import { BrowserRouter, DataContext, ThemeContext } from "@rspress/runtime";
|
|
|
3
3
|
import { useThemeState } from "@theme";
|
|
4
4
|
import { UnheadProvider, createHead } from "@unhead/react/client";
|
|
5
5
|
import { useMemo, useState } from "react";
|
|
6
|
+
import { base } from "virtual-runtime-config";
|
|
6
7
|
import { App } from "./App.js";
|
|
7
8
|
const head = createHead();
|
|
8
9
|
function ClientApp({ initialPageData = null }) {
|
|
@@ -25,6 +26,11 @@ function ClientApp({ initialPageData = null }) {
|
|
|
25
26
|
setData
|
|
26
27
|
]),
|
|
27
28
|
children: /*#__PURE__*/ jsx(BrowserRouter, {
|
|
29
|
+
future: {
|
|
30
|
+
v7_relativeSplatPath: true,
|
|
31
|
+
v7_startTransition: true
|
|
32
|
+
},
|
|
33
|
+
basename: base,
|
|
28
34
|
children: /*#__PURE__*/ jsx(UnheadProvider, {
|
|
29
35
|
head: head,
|
|
30
36
|
children: /*#__PURE__*/ jsx(App, {})
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isEqualPath, pathnameToRouteService } from "@rspress/runtime";
|
|
2
2
|
import { MDX_OR_MD_REGEXP, cleanUrl } from "@rspress/shared";
|
|
3
|
+
import { base } from "virtual-runtime-config";
|
|
3
4
|
import virtual_site_data from "virtual-site-data";
|
|
4
5
|
async function initPageData(routePath) {
|
|
5
6
|
const matchedRoute = pathnameToRouteService(routePath);
|
|
@@ -27,7 +28,7 @@ async function initPageData(routePath) {
|
|
|
27
28
|
let lang = virtual_site_data.lang || '';
|
|
28
29
|
let version = virtual_site_data.multiVersion?.default || '';
|
|
29
30
|
if (virtual_site_data.lang && 'undefined' != typeof window) {
|
|
30
|
-
const path = location.pathname.replace(
|
|
31
|
+
const path = location.pathname.replace(base, '').split('/').slice(0, 2);
|
|
31
32
|
if (virtual_site_data.locales.length) {
|
|
32
33
|
const result = virtual_site_data.locales.find(({ lang })=>path.includes(lang));
|
|
33
34
|
if (result) lang = result.lang;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { PageData } from '@rspress/shared';
|
|
2
2
|
import { type Unhead } from '@unhead/react/server';
|
|
3
|
-
export declare function render(
|
|
3
|
+
export declare function render(routePath: string, head: Unhead): Promise<{
|
|
4
4
|
appHtml: string;
|
|
5
5
|
pageData: PageData;
|
|
6
6
|
}>;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { DataContext, ThemeContext, pathnameToRouteService } from "@rspress/runtime";
|
|
2
|
+
import { DataContext, ThemeContext, pathnameToRouteService, withBase } from "@rspress/runtime";
|
|
3
3
|
import { StaticRouter } from "@rspress/runtime/server";
|
|
4
4
|
import { UnheadProvider } from "@unhead/react/server";
|
|
5
5
|
import { renderToPipeableStream } from "react-dom/server";
|
|
6
6
|
import { PassThrough } from "node:stream";
|
|
7
7
|
import { text as consumers_text } from "node:stream/consumers";
|
|
8
|
+
import { base } from "virtual-runtime-config";
|
|
8
9
|
import { App } from "./App.js";
|
|
9
10
|
import { initPageData } from "./initPageData.js";
|
|
10
11
|
import { routes } from "virtual-routes";
|
|
@@ -27,9 +28,9 @@ function renderToHtml(app) {
|
|
|
27
28
|
});
|
|
28
29
|
});
|
|
29
30
|
}
|
|
30
|
-
async function render(
|
|
31
|
-
const initialPageData = await initPageData(
|
|
32
|
-
await preloadRoute(
|
|
31
|
+
async function render(routePath, head) {
|
|
32
|
+
const initialPageData = await initPageData(routePath);
|
|
33
|
+
await preloadRoute(routePath);
|
|
33
34
|
const appHtml = await renderToHtml(/*#__PURE__*/ jsx(ThemeContext.Provider, {
|
|
34
35
|
value: {
|
|
35
36
|
theme: DEFAULT_THEME
|
|
@@ -39,7 +40,8 @@ async function render(pagePath, head) {
|
|
|
39
40
|
data: initialPageData
|
|
40
41
|
},
|
|
41
42
|
children: /*#__PURE__*/ jsx(StaticRouter, {
|
|
42
|
-
location:
|
|
43
|
+
location: withBase(routePath),
|
|
44
|
+
basename: base,
|
|
43
45
|
children: /*#__PURE__*/ jsx(UnheadProvider, {
|
|
44
46
|
value: head,
|
|
45
47
|
children: /*#__PURE__*/ jsx(App, {})
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
/*! For license information please see shiki-transformers.js.LICENSE.txt */
|
|
2
|
-
import __rslib_shim_module__ from 'module';
|
|
3
|
-
/*#__PURE__*/ import.meta.url;
|
|
4
2
|
const SHIKI_TRANSFORMER_LINE_NUMBER = 'shiki-transformer:line-number';
|
|
5
3
|
function transformerLineNumber(options = {}) {
|
|
6
4
|
const { classActiveLine = 'line-number', classActivePre = 'has-line-number' } = 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.18",
|
|
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",
|
|
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,15 @@
|
|
|
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/theme-default": "2.0.0-beta.16",
|
|
84
|
-
"@rspress/plugin-last-updated": "2.0.0-beta.16"
|
|
78
|
+
"@rspress/plugin-last-updated": "2.0.0-beta.18",
|
|
79
|
+
"@rspress/plugin-medium-zoom": "2.0.0-beta.18",
|
|
80
|
+
"@rspress/runtime": "2.0.0-beta.18",
|
|
81
|
+
"@rspress/shared": "2.0.0-beta.18",
|
|
82
|
+
"@rspress/theme-default": "2.0.0-beta.18"
|
|
85
83
|
},
|
|
86
84
|
"devDependencies": {
|
|
87
85
|
"@microsoft/api-extractor": "^7.52.8",
|
|
88
|
-
"@rslib/core": "0.10.
|
|
86
|
+
"@rslib/core": "0.10.3",
|
|
89
87
|
"@rspress-dev/plugin-preview": "link:../plugin-preview",
|
|
90
88
|
"@types/hast": "^3.0.4",
|
|
91
89
|
"@types/html-to-text": "^9.0.4",
|
|
@@ -95,17 +93,19 @@
|
|
|
95
93
|
"@types/node": "^22.8.1",
|
|
96
94
|
"@types/react": "^19.1.8",
|
|
97
95
|
"@types/react-dom": "^19.1.6",
|
|
96
|
+
"mdast-util-mdx-expression": "^2.0.1",
|
|
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",
|
|
101
|
+
"remark-directive": "^4.0.0",
|
|
102
102
|
"remark-mdx": "^3.1.0",
|
|
103
103
|
"remark-parse": "^11.0.0",
|
|
104
104
|
"remark-rehype": "^11.1.2",
|
|
105
105
|
"remark-stringify": "^11.0.0",
|
|
106
106
|
"rimraf": "^6.0.1",
|
|
107
107
|
"rsbuild-plugin-publint": "^0.3.2",
|
|
108
|
-
"rsbuild-plugin-virtual-module": "0.
|
|
108
|
+
"rsbuild-plugin-virtual-module": "0.3.0",
|
|
109
109
|
"tailwindcss": "^3.4.17",
|
|
110
110
|
"typescript": "^5.8.2",
|
|
111
111
|
"vfile": "^6.0.3",
|