@rspress/core 2.0.0-beta.17 → 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 +1 -1
- package/dist/index.js +36 -23
- package/dist/loader.d.ts +2 -2
- package/dist/loader.js +2 -3
- package/dist/processor.d.ts +1 -1
- package/dist/processor.js +202 -4
- package/dist/runtime/ClientApp.js +2 -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 +10 -9
package/dist/index.d.ts
CHANGED
|
@@ -179,7 +179,7 @@ export declare class RouteService {
|
|
|
179
179
|
isExistRoute(routePath: string): boolean;
|
|
180
180
|
generateRoutesCode(): string;
|
|
181
181
|
generateRoutesCodeByRouteMeta(routeMeta: RouteMeta[]): string;
|
|
182
|
-
getRoutePathParts(routePath: string): readonly [string, string, string
|
|
182
|
+
getRoutePathParts(routePath: string): readonly [string, string, string];
|
|
183
183
|
normalizeRoutePath(routePath: string): {
|
|
184
184
|
routePath: string;
|
|
185
185
|
lang: string;
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import __rslib_shim_module__ from 'module';
|
|
2
2
|
const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(import.meta.url);
|
|
3
|
-
import { pluginContainerSyntax } from "@rspress/plugin-container-syntax";
|
|
4
3
|
import node_fs_promises, { mkdir, readFile, readdir, rm, stat as promises_stat, writeFile } from "node:fs/promises";
|
|
5
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";
|
|
9
8
|
import { DEFAULT_PAGE_EXTENSIONS } from "@rspress/shared/constants";
|
|
10
9
|
import { logger } from "@rspress/shared/logger";
|
|
11
10
|
import picocolors from "picocolors";
|
|
@@ -47,7 +46,6 @@ class PluginDriver {
|
|
|
47
46
|
const { pluginMediumZoom } = await import("@rspress/plugin-medium-zoom");
|
|
48
47
|
this.addPlugin(pluginMediumZoom('object' == typeof mediumZoomConfig ? mediumZoomConfig : void 0));
|
|
49
48
|
}
|
|
50
|
-
this.addPlugin(pluginContainerSyntax());
|
|
51
49
|
(config.plugins || []).forEach((plugin)=>{
|
|
52
50
|
this.addPlugin(plugin);
|
|
53
51
|
});
|
|
@@ -241,7 +239,7 @@ function hintNavJsonChangeThenPanic(metaJson, metaJsonDir, docsDir) {
|
|
|
241
239
|
process.exit(1);
|
|
242
240
|
}
|
|
243
241
|
}
|
|
244
|
-
var package_namespaceObject = JSON.parse('{"i8":"2.0.0-beta.
|
|
242
|
+
var package_namespaceObject = JSON.parse('{"i8":"2.0.0-beta.18"}');
|
|
245
243
|
const RSPRESS_VERSION = package_namespaceObject.i8;
|
|
246
244
|
const isProduction = ()=>'production' === process.env.NODE_ENV;
|
|
247
245
|
const importStatementRegex = /import\s+(.*?)\s+from\s+(['"])(.*?)(?:"|');?/gm;
|
|
@@ -281,7 +279,7 @@ class RoutePage {
|
|
|
281
279
|
this.routeMeta = routeMeta;
|
|
282
280
|
}
|
|
283
281
|
}
|
|
284
|
-
const getRoutePathParts = (routePath,
|
|
282
|
+
const getRoutePathParts = (routePath, lang, version, langs, versions)=>{
|
|
285
283
|
const hasTrailSlash = routePath.endsWith('/');
|
|
286
284
|
let versionPart = '';
|
|
287
285
|
let langPart = '';
|
|
@@ -303,14 +301,13 @@ const getRoutePathParts = (routePath, base, lang, version, langs, versions)=>{
|
|
|
303
301
|
}
|
|
304
302
|
purePathPart = parts.join('/');
|
|
305
303
|
return [
|
|
306
|
-
base,
|
|
307
304
|
versionPart,
|
|
308
305
|
langPart,
|
|
309
306
|
hasTrailSlash ? addTrailingSlash(purePathPart) : purePathPart
|
|
310
307
|
];
|
|
311
308
|
};
|
|
312
|
-
const normalizeRoutePath = (routePath,
|
|
313
|
-
const [
|
|
309
|
+
const normalizeRoutePath = (routePath, lang, version, langs, versions, extensions = DEFAULT_PAGE_EXTENSIONS)=>{
|
|
310
|
+
const [versionPart, langPart, purePathPart] = getRoutePathParts(routePath, lang, version, langs, versions);
|
|
314
311
|
const extensionsWithoutDot = extensions.map((i)=>i.slice(1));
|
|
315
312
|
const cleanExtensionPattern = new RegExp(`\\.(${extensionsWithoutDot.join('|')})$`, 'i');
|
|
316
313
|
const normalizedRoutePath = addLeadingSlash([
|
|
@@ -318,7 +315,7 @@ const normalizeRoutePath = (routePath, base, lang, version, langs, versions, ext
|
|
|
318
315
|
langPart
|
|
319
316
|
].filter(Boolean).join('/') + addLeadingSlash(purePathPart)).replace(cleanExtensionPattern, '').replace(/\.html$/, '').replace(/\/index$/, '/');
|
|
320
317
|
return {
|
|
321
|
-
routePath:
|
|
318
|
+
routePath: normalizedRoutePath,
|
|
322
319
|
lang: langPart || lang,
|
|
323
320
|
version: versionPart || version
|
|
324
321
|
};
|
|
@@ -333,7 +330,6 @@ class RouteService {
|
|
|
333
330
|
#versions = [];
|
|
334
331
|
#include = [];
|
|
335
332
|
#exclude = [];
|
|
336
|
-
#base = '';
|
|
337
333
|
#tempDir = '';
|
|
338
334
|
#pluginDriver;
|
|
339
335
|
static __instance__ = null;
|
|
@@ -356,7 +352,6 @@ class RouteService {
|
|
|
356
352
|
this.#exclude = routeOptions.exclude || [];
|
|
357
353
|
this.#defaultLang = userConfig?.lang || '';
|
|
358
354
|
this.#langs = (userConfig?.locales ?? userConfig?.themeConfig?.locales ?? []).map((item)=>item.lang);
|
|
359
|
-
this.#base = userConfig?.base || '';
|
|
360
355
|
this.#tempDir = tempDir;
|
|
361
356
|
this.#pluginDriver = pluginDriver;
|
|
362
357
|
if (userConfig.multiVersion) {
|
|
@@ -456,10 +451,10 @@ ${routeMeta.map((route, index)=>{
|
|
|
456
451
|
`;
|
|
457
452
|
}
|
|
458
453
|
getRoutePathParts(routePath) {
|
|
459
|
-
return getRoutePathParts(routePath, this.#
|
|
454
|
+
return getRoutePathParts(routePath, this.#defaultLang, this.#defaultVersion, this.#langs, this.#versions);
|
|
460
455
|
}
|
|
461
456
|
normalizeRoutePath(routePath) {
|
|
462
|
-
return normalizeRoutePath(routePath, this.#
|
|
457
|
+
return normalizeRoutePath(routePath, this.#defaultLang, this.#defaultVersion, this.#langs, this.#versions, this.#extensions);
|
|
463
458
|
}
|
|
464
459
|
async #writeTempFile(index, content) {
|
|
465
460
|
const tempFilePath = node_path.join(this.#tempDir, `temp-${index}.mdx`);
|
|
@@ -496,8 +491,8 @@ function absolutePathToLink(absolutePath, docsDir) {
|
|
|
496
491
|
function absolutePathToRoutePrefix(absolutePath, docsDir) {
|
|
497
492
|
const relativePath = normalizePath_slash(node_path.relative(docsDir, absolutePath.replace(node_path.extname(absolutePath), '')));
|
|
498
493
|
const routeService = RouteService.getInstance();
|
|
499
|
-
const [
|
|
500
|
-
return `${
|
|
494
|
+
const [versionPrefix, langPrefix] = routeService.getRoutePathParts(relativePath);
|
|
495
|
+
return `${versionPrefix ? `/${versionPrefix}` : ''}${langPrefix ? `/${langPrefix}` : ''}`;
|
|
501
496
|
}
|
|
502
497
|
function addRoutePrefix(workDir, docsDir, link) {
|
|
503
498
|
const routePrefix = absolutePathToRoutePrefix(workDir, docsDir);
|
|
@@ -1007,6 +1002,7 @@ var types_RuntimeModuleID = /*#__PURE__*/ function(RuntimeModuleID) {
|
|
|
1007
1002
|
RuntimeModuleID["SearchIndexHash"] = "virtual-search-index-hash";
|
|
1008
1003
|
RuntimeModuleID["I18nText"] = "virtual-i18n-text";
|
|
1009
1004
|
RuntimeModuleID["SearchHooks"] = "virtual-search-hooks";
|
|
1005
|
+
RuntimeModuleID["RuntimeConfig"] = "virtual-runtime-config";
|
|
1010
1006
|
return RuntimeModuleID;
|
|
1011
1007
|
}({});
|
|
1012
1008
|
const DEFAULT_I18N_SOURCE = join(process.cwd(), 'i18n.json');
|
|
@@ -1033,7 +1029,7 @@ const i18nVMPlugin = (context)=>{
|
|
|
1033
1029
|
};
|
|
1034
1030
|
};
|
|
1035
1031
|
function normalizeThemeConfig(docConfig) {
|
|
1036
|
-
const { locales: siteLocales,
|
|
1032
|
+
const { locales: siteLocales, lang, replaceRules = [], multiVersion } = docConfig;
|
|
1037
1033
|
const { versions = [] } = multiVersion || {};
|
|
1038
1034
|
const hasMultiVersion = versions.length > 0;
|
|
1039
1035
|
docConfig.themeConfig = docConfig.themeConfig || {};
|
|
@@ -1042,7 +1038,7 @@ function normalizeThemeConfig(docConfig) {
|
|
|
1042
1038
|
const i18nTextData = getI18nData(docConfig);
|
|
1043
1039
|
const normalizeLinkPrefix = (link = '', currentLang = '')=>{
|
|
1044
1040
|
const normalizedLink = slash(link);
|
|
1045
|
-
if (!currentLang || !link ||
|
|
1041
|
+
if (!currentLang || !link || normalizedLink.startsWith(`/${currentLang}`) || isExternalUrl(normalizedLink) || hasMultiVersion) return normalizedLink;
|
|
1046
1042
|
return lang === currentLang ? normalizedLink : `/${currentLang}${addLeadingSlash(normalizedLink)}`;
|
|
1047
1043
|
};
|
|
1048
1044
|
const getI18nText = (key = '', currentLang = '')=>{
|
|
@@ -1178,7 +1174,6 @@ async function siteDataVMPlugin(context) {
|
|
|
1178
1174
|
icon: getIconUrlPath(userConfig?.icon) || '',
|
|
1179
1175
|
route: userConfig?.route || {},
|
|
1180
1176
|
themeConfig: normalizeThemeConfig(userConfig),
|
|
1181
|
-
base: userConfig?.base || '/',
|
|
1182
1177
|
lang: userConfig?.lang || '',
|
|
1183
1178
|
locales: userConfig?.locales || userConfig.themeConfig?.locales || [],
|
|
1184
1179
|
logo: userConfig?.logo || '',
|
|
@@ -1281,6 +1276,14 @@ const routeListVMPlugin = (context)=>{
|
|
|
1281
1276
|
[types_RuntimeModuleID.Routes]: ()=>routeService.generateRoutesCode()
|
|
1282
1277
|
};
|
|
1283
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
|
+
});
|
|
1284
1287
|
const searchHookVMPlugin = (context)=>({
|
|
1285
1288
|
[`${types_RuntimeModuleID.SearchHooks}`]: ()=>{
|
|
1286
1289
|
const { config } = context;
|
|
@@ -1470,9 +1473,8 @@ async function renderPages(routeService, config, pluginDriver, ssrBundlePath, ht
|
|
|
1470
1473
|
}
|
|
1471
1474
|
try {
|
|
1472
1475
|
const routes = routeService.getRoutes();
|
|
1473
|
-
const base = config?.base ?? '';
|
|
1474
1476
|
const additionalRoutes = (await pluginDriver.addSSGRoutes()).map((route)=>({
|
|
1475
|
-
routePath:
|
|
1477
|
+
routePath: route.path
|
|
1476
1478
|
}));
|
|
1477
1479
|
const allRoutes = [
|
|
1478
1480
|
...routes,
|
|
@@ -1525,6 +1527,7 @@ const rsbuildPluginSSG = ({ routeService, config, pluginDriver })=>({
|
|
|
1525
1527
|
async setup (api) {
|
|
1526
1528
|
api.onBeforeBuild(()=>{
|
|
1527
1529
|
let htmlTemplate = '';
|
|
1530
|
+
let hasError = false;
|
|
1528
1531
|
const indexHtmlEmittedInWeb = new Promise((resolve, reject)=>{
|
|
1529
1532
|
api.processAssets({
|
|
1530
1533
|
stage: 'report',
|
|
@@ -1533,6 +1536,10 @@ const rsbuildPluginSSG = ({ routeService, config, pluginDriver })=>({
|
|
|
1533
1536
|
]
|
|
1534
1537
|
}, ({ assets, compilation, environment })=>{
|
|
1535
1538
|
if ('web' !== environment.name) return;
|
|
1539
|
+
if (compilation.errors.length > 0) {
|
|
1540
|
+
hasError = true;
|
|
1541
|
+
return;
|
|
1542
|
+
}
|
|
1536
1543
|
for (const [assetName, assetSource] of Object.entries(assets))if ('index.html' === assetName) {
|
|
1537
1544
|
htmlTemplate = assetSource.source().toString();
|
|
1538
1545
|
compilation.deleteAsset(assetName);
|
|
@@ -1554,6 +1561,11 @@ const rsbuildPluginSSG = ({ routeService, config, pluginDriver })=>({
|
|
|
1554
1561
|
]
|
|
1555
1562
|
}, async ({ assets, compilation, environment, compiler })=>{
|
|
1556
1563
|
if ('node' !== environment.name) return;
|
|
1564
|
+
if (compilation.errors.length > 0) {
|
|
1565
|
+
hasError = true;
|
|
1566
|
+
return;
|
|
1567
|
+
}
|
|
1568
|
+
if (hasError) return;
|
|
1557
1569
|
const distPath = environment.distPath;
|
|
1558
1570
|
const ssgFolderPath = join(distPath, NODE_SSG_BUNDLE_FOLDER);
|
|
1559
1571
|
const mainCjsAbsolutePath = join(ssgFolderPath, NODE_SSG_BUNDLE_NAME);
|
|
@@ -1754,7 +1766,8 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1754
1766
|
...globalStylesVMPlugin(context),
|
|
1755
1767
|
...searchHookVMPlugin(context),
|
|
1756
1768
|
...routeListVMPlugin(context),
|
|
1757
|
-
...await getVirtualModulesFromPlugins(pluginDriver)
|
|
1769
|
+
...await getVirtualModulesFromPlugins(pluginDriver),
|
|
1770
|
+
...runtimeConfigVMPlugin(context)
|
|
1758
1771
|
}
|
|
1759
1772
|
}),
|
|
1760
1773
|
...enableSSG ? [
|
|
@@ -2136,8 +2149,8 @@ function normalizeLink(nodeUrl, routeService, relativePath, cleanUrls) {
|
|
|
2136
2149
|
if ((routeService?.extensions ?? DEFAULT_PAGE_EXTENSIONS).includes(extname)) url = url.replace(new RegExp(`\\${extname}$`), '');
|
|
2137
2150
|
if (url.startsWith('.')) url = node_path.posix.join(slash(node_path.dirname(relativePath)), url);
|
|
2138
2151
|
else if (routeService) {
|
|
2139
|
-
const [
|
|
2140
|
-
const [
|
|
2152
|
+
const [pathVersion, pathLang] = routeService.getRoutePathParts(slash(relativePath));
|
|
2153
|
+
const [urlVersion, urlLang, urlPath] = routeService.getRoutePathParts(url);
|
|
2141
2154
|
url = addLeadingSlash(urlPath);
|
|
2142
2155
|
if (pathLang && urlLang !== pathLang) url = `/${pathLang}${url}`;
|
|
2143
2156
|
if (pathVersion && urlVersion !== pathVersion) url = `/${pathVersion}${url}`;
|
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
|
|
|
@@ -73,7 +73,7 @@ declare class RouteService {
|
|
|
73
73
|
isExistRoute(routePath: string): boolean;
|
|
74
74
|
generateRoutesCode(): string;
|
|
75
75
|
generateRoutesCodeByRouteMeta(routeMeta: RouteMeta[]): string;
|
|
76
|
-
getRoutePathParts(routePath: string): readonly [string, string, string
|
|
76
|
+
getRoutePathParts(routePath: string): readonly [string, string, string];
|
|
77
77
|
normalizeRoutePath(routePath: string): {
|
|
78
78
|
routePath: string;
|
|
79
79
|
lang: string;
|
package/dist/loader.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
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
|
@@ -75,7 +75,7 @@ declare class RouteService {
|
|
|
75
75
|
isExistRoute(routePath: string): boolean;
|
|
76
76
|
generateRoutesCode(): string;
|
|
77
77
|
generateRoutesCodeByRouteMeta(routeMeta: RouteMeta[]): string;
|
|
78
|
-
getRoutePathParts(routePath: string): readonly [string, string, string
|
|
78
|
+
getRoutePathParts(routePath: string): readonly [string, string, string];
|
|
79
79
|
normalizeRoutePath(routePath: string): {
|
|
80
80
|
routePath: string;
|
|
81
81
|
lang: string;
|
package/dist/processor.js
CHANGED
|
@@ -2,7 +2,6 @@ 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";
|
|
@@ -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 [
|
|
160
|
-
const [
|
|
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}`;
|
|
@@ -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 }) {
|
|
@@ -29,6 +30,7 @@ function ClientApp({ initialPageData = null }) {
|
|
|
29
30
|
v7_relativeSplatPath: true,
|
|
30
31
|
v7_startTransition: true
|
|
31
32
|
},
|
|
33
|
+
basename: base,
|
|
32
34
|
children: /*#__PURE__*/ jsx(UnheadProvider, {
|
|
33
35
|
head: head,
|
|
34
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 '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.4.0
|
|
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,16 +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-last-updated": "2.0.0-beta.
|
|
79
|
-
"@rspress/plugin-medium-zoom": "2.0.0-beta.
|
|
80
|
-
"@rspress/runtime": "2.0.0-beta.
|
|
81
|
-
"@rspress/shared": "2.0.0-beta.
|
|
82
|
-
"@rspress/theme-default": "2.0.0-beta.
|
|
83
|
-
"@rspress/plugin-container-syntax": "2.0.0-beta.17"
|
|
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"
|
|
84
83
|
},
|
|
85
84
|
"devDependencies": {
|
|
86
85
|
"@microsoft/api-extractor": "^7.52.8",
|
|
87
|
-
"@rslib/core": "0.10.
|
|
86
|
+
"@rslib/core": "0.10.3",
|
|
88
87
|
"@rspress-dev/plugin-preview": "link:../plugin-preview",
|
|
89
88
|
"@types/hast": "^3.0.4",
|
|
90
89
|
"@types/html-to-text": "^9.0.4",
|
|
@@ -94,10 +93,12 @@
|
|
|
94
93
|
"@types/node": "^22.8.1",
|
|
95
94
|
"@types/react": "^19.1.8",
|
|
96
95
|
"@types/react-dom": "^19.1.6",
|
|
96
|
+
"mdast-util-mdx-expression": "^2.0.1",
|
|
97
97
|
"memfs": "^4.17.2",
|
|
98
98
|
"p-map": "^7.0.3",
|
|
99
99
|
"postcss": "8.5.6",
|
|
100
100
|
"rehype-stringify": "^10.0.1",
|
|
101
|
+
"remark-directive": "^4.0.0",
|
|
101
102
|
"remark-mdx": "^3.1.0",
|
|
102
103
|
"remark-parse": "^11.0.0",
|
|
103
104
|
"remark-rehype": "^11.1.2",
|