@rspress/core 2.0.0-alpha.5 → 2.0.0-alpha.6
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.js +24 -10
- package/dist/loader.d.ts +2 -0
- package/dist/loader.js +15 -6
- package/dist/runtime/App.js +2 -4
- package/package.json +10 -10
package/dist/index.js
CHANGED
|
@@ -191,6 +191,7 @@ const inlineThemeScript = `{
|
|
|
191
191
|
const preferDark = window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
192
192
|
const isDark = !saved || saved === 'auto' ? preferDark : saved === 'dark'
|
|
193
193
|
document.documentElement.classList.toggle('dark', isDark)
|
|
194
|
+
document.documentElement.classList.toggle('rp-dark', isDark)
|
|
194
195
|
document.documentElement.style.colorScheme = isDark ? 'dark' : 'light'
|
|
195
196
|
}`.replace(/\n/g, ';').replace(/\s{2,}/g, '');
|
|
196
197
|
const dirname = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].dirname((0, __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__.fileURLToPath)(new URL(import.meta.url)));
|
|
@@ -234,6 +235,7 @@ async function hintThemeBreakingChange(customThemeDir) {
|
|
|
234
235
|
encoding: 'utf-8'
|
|
235
236
|
});
|
|
236
237
|
if (THEME_DEFAULT_EXPORT_PATTERN.test(content)) useDefaultExportFilePath = filePath;
|
|
238
|
+
break;
|
|
237
239
|
}
|
|
238
240
|
}
|
|
239
241
|
if (useDefaultExportFilePath) __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.logger.warn(`[Rspress] Theme breaking change: The theme/index is now using namedExports instead of defaultExports, please update your config file in ${useDefaultExportFilePath}`, __WEBPACK_EXTERNAL_MODULE_picocolors__["default"].red(`
|
|
@@ -259,7 +261,7 @@ function getPageKey(route) {
|
|
|
259
261
|
const cleanRoute = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.removeLeadingSlash)(route);
|
|
260
262
|
return cleanRoute.replace(/\//g, '_').replace(/\.[^.]+$/, '') || 'index';
|
|
261
263
|
}
|
|
262
|
-
const
|
|
264
|
+
const getRoutePathParts = (routePath, lang, version, langs, versions)=>{
|
|
263
265
|
const hasTrailSlash = routePath.endsWith('/');
|
|
264
266
|
let versionPart = '';
|
|
265
267
|
let langPart = '';
|
|
@@ -280,14 +282,20 @@ const normalizeRoutePath = (routePath, base, lang, version, langs, versions, ext
|
|
|
280
282
|
}
|
|
281
283
|
}
|
|
282
284
|
purePathPart = parts.join('/');
|
|
285
|
+
return [
|
|
286
|
+
versionPart,
|
|
287
|
+
langPart,
|
|
288
|
+
hasTrailSlash ? (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.addTrailingSlash)(purePathPart) : purePathPart
|
|
289
|
+
];
|
|
290
|
+
};
|
|
291
|
+
const normalizeRoutePath = (routePath, base, lang, version, langs, versions, extensions = __WEBPACK_EXTERNAL_MODULE__rspress_shared_constants_70084e62__.DEFAULT_PAGE_EXTENSIONS)=>{
|
|
292
|
+
const [versionPart, langPart, purePathPart] = getRoutePathParts(routePath, lang, version, langs, versions);
|
|
283
293
|
const extensionsWithoutDot = extensions.map((i)=>i.slice(1));
|
|
284
294
|
const cleanExtensionPattern = new RegExp(`\\.(${extensionsWithoutDot.join('|')})$`, 'i');
|
|
285
|
-
|
|
295
|
+
const normalizedRoutePath = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.addLeadingSlash)([
|
|
286
296
|
versionPart,
|
|
287
|
-
langPart
|
|
288
|
-
|
|
289
|
-
].filter(Boolean).join('/')).replace(cleanExtensionPattern, '').replace(/\.html$/, '').replace(/\/index$/, '/');
|
|
290
|
-
if (hasTrailSlash) normalizedRoutePath = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.addTrailingSlash)(normalizedRoutePath);
|
|
297
|
+
langPart
|
|
298
|
+
].filter(Boolean).join('/') + (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.addLeadingSlash)(purePathPart)).replace(cleanExtensionPattern, '').replace(/\.html$/, '').replace(/\/index$/, '/');
|
|
291
299
|
return {
|
|
292
300
|
routePath: (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.withBase)(normalizedRoutePath, base),
|
|
293
301
|
lang: langPart || lang,
|
|
@@ -345,6 +353,9 @@ function _define_property(obj, key, value) {
|
|
|
345
353
|
}
|
|
346
354
|
var _scanDir = /*#__PURE__*/ new WeakMap(), _defaultLang = /*#__PURE__*/ new WeakMap(), _defaultVersion = /*#__PURE__*/ new WeakMap(), _extensions = /*#__PURE__*/ new WeakMap(), _langs = /*#__PURE__*/ new WeakMap(), _versions = /*#__PURE__*/ new WeakMap(), _include = /*#__PURE__*/ new WeakMap(), _exclude = /*#__PURE__*/ new WeakMap(), _base = /*#__PURE__*/ new WeakMap(), _tempDir = /*#__PURE__*/ new WeakMap(), _pluginDriver = /*#__PURE__*/ new WeakMap(), _writeTempFile = /*#__PURE__*/ new WeakSet(), _generateRouteInfo = /*#__PURE__*/ new WeakSet();
|
|
347
355
|
class RouteService {
|
|
356
|
+
get extensions() {
|
|
357
|
+
return RouteService_class_private_field_get(this, _extensions);
|
|
358
|
+
}
|
|
348
359
|
async init() {
|
|
349
360
|
const extensions = RouteService_class_private_field_get(this, _extensions).map((i)=>i.slice(1));
|
|
350
361
|
const files = (await (0, __WEBPACK_EXTERNAL_MODULE_tinyglobby__.glob)([
|
|
@@ -435,6 +446,9 @@ ${routeMeta.map((route, index)=>{
|
|
|
435
446
|
];
|
|
436
447
|
`;
|
|
437
448
|
}
|
|
449
|
+
getRoutePathParts(routePath) {
|
|
450
|
+
return getRoutePathParts(routePath, RouteService_class_private_field_get(this, _defaultLang), RouteService_class_private_field_get(this, _defaultVersion), RouteService_class_private_field_get(this, _langs), RouteService_class_private_field_get(this, _versions));
|
|
451
|
+
}
|
|
438
452
|
normalizeRoutePath(routePath) {
|
|
439
453
|
return normalizeRoutePath(routePath, RouteService_class_private_field_get(this, _base), RouteService_class_private_field_get(this, _defaultLang), RouteService_class_private_field_get(this, _defaultVersion), RouteService_class_private_field_get(this, _langs), RouteService_class_private_field_get(this, _versions), RouteService_class_private_field_get(this, _extensions));
|
|
440
454
|
}
|
|
@@ -529,10 +543,10 @@ async function initRouteService(options) {
|
|
|
529
543
|
async function globalStylesVMPlugin(context) {
|
|
530
544
|
const { config, pluginDriver } = context;
|
|
531
545
|
const globalStylesByPlugins = pluginDriver.globalStyles();
|
|
532
|
-
const moduleContent =
|
|
533
|
-
|
|
546
|
+
const moduleContent = [
|
|
547
|
+
null == config ? void 0 : config.globalStyles,
|
|
534
548
|
...globalStylesByPlugins
|
|
535
|
-
].filter(
|
|
549
|
+
].filter(Boolean).map((source)=>`import ${JSON.stringify(source)};`).join('');
|
|
536
550
|
return {
|
|
537
551
|
[runtimeModule_RuntimeModuleID.GlobalStyles]: moduleContent
|
|
538
552
|
};
|
|
@@ -1553,7 +1567,7 @@ async function dev(options) {
|
|
|
1553
1567
|
await checkLanguageParity(modifiedConfig);
|
|
1554
1568
|
}
|
|
1555
1569
|
}
|
|
1556
|
-
var package_namespaceObject = JSON.parse('{"i8":"2.0.0-alpha.
|
|
1570
|
+
var package_namespaceObject = JSON.parse('{"i8":"2.0.0-alpha.6"}');
|
|
1557
1571
|
async function renderFrontmatterHead(route) {
|
|
1558
1572
|
if (!isRouteMeta(route)) return '';
|
|
1559
1573
|
const content = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readFile(route.absolutePath, {
|
package/dist/loader.d.ts
CHANGED
|
@@ -58,6 +58,7 @@ declare class RouteService {
|
|
|
58
58
|
#private;
|
|
59
59
|
routeData: Map<string, RouteMeta>;
|
|
60
60
|
constructor(scanDir: string, userConfig: UserConfig, tempDir: string, pluginDriver: PluginDriver);
|
|
61
|
+
get extensions(): readonly string[];
|
|
61
62
|
init(): Promise<void>;
|
|
62
63
|
addRoute(routeInfo: RouteMeta): void;
|
|
63
64
|
removeRoute(filePath: string): void;
|
|
@@ -66,6 +67,7 @@ declare class RouteService {
|
|
|
66
67
|
isEmpty(): boolean;
|
|
67
68
|
generateRoutesCode(isStaticImport?: boolean): string;
|
|
68
69
|
generateRoutesCodeByRouteMeta(routeMeta: RouteMeta[], isStaticImport: boolean): string;
|
|
70
|
+
getRoutePathParts(routePath: string): readonly [string, string, string];
|
|
69
71
|
normalizeRoutePath(routePath: string): {
|
|
70
72
|
routePath: string;
|
|
71
73
|
lang: string;
|
package/dist/loader.js
CHANGED
|
@@ -16,6 +16,7 @@ import * as __WEBPACK_EXTERNAL_MODULE_remark_gfm_073acf21__ from "remark-gfm";
|
|
|
16
16
|
import * as __WEBPACK_EXTERNAL_MODULE_unist_util_visit_555e002a__ from "unist-util-visit";
|
|
17
17
|
import * as __WEBPACK_EXTERNAL_MODULE_github_slugger_8e9a17cb__ from "github-slugger";
|
|
18
18
|
import * as __WEBPACK_EXTERNAL_MODULE_hast_util_heading_rank_cff646ba__ from "hast-util-heading-rank";
|
|
19
|
+
import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_constants_70084e62__ from "@rspress/shared/constants";
|
|
19
20
|
import * as __WEBPACK_EXTERNAL_MODULE_unist_util_visit_children_71921007__ from "unist-util-visit-children";
|
|
20
21
|
const importStatementRegex = /import\s+(.*?)\s+from\s+(['"])(.*?)(?:"|');?/gm;
|
|
21
22
|
`{
|
|
@@ -23,6 +24,7 @@ const importStatementRegex = /import\s+(.*?)\s+from\s+(['"])(.*?)(?:"|');?/gm;
|
|
|
23
24
|
const preferDark = window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
24
25
|
const isDark = !saved || saved === 'auto' ? preferDark : saved === 'dark'
|
|
25
26
|
document.documentElement.classList.toggle('dark', isDark)
|
|
27
|
+
document.documentElement.classList.toggle('rp-dark', isDark)
|
|
26
28
|
document.documentElement.style.colorScheme = isDark ? 'dark' : 'light'
|
|
27
29
|
}`.replace(/\n/g, ';').replace(/\s{2,}/g, '');
|
|
28
30
|
const dirname = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].dirname((0, __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__.fileURLToPath)(new URL(import.meta.url)));
|
|
@@ -173,8 +175,7 @@ const collectHeaderText = (node)=>{
|
|
|
173
175
|
child.value = textPart;
|
|
174
176
|
text += textPart;
|
|
175
177
|
id = idPart;
|
|
176
|
-
}
|
|
177
|
-
if ('element' === child.type) child.children.forEach((c)=>{
|
|
178
|
+
} else if ('element' === child.type) child.children.forEach((c)=>{
|
|
178
179
|
if ('text' === c.type) text += c.value;
|
|
179
180
|
});
|
|
180
181
|
});
|
|
@@ -258,7 +259,7 @@ const remarkCheckDeadLinks = (checkLink)=>{
|
|
|
258
259
|
(0, __WEBPACK_EXTERNAL_MODULE_unist_util_visit_555e002a__.visit)(tree, 'link', ({ url })=>{
|
|
259
260
|
if (!url) return;
|
|
260
261
|
if (internalLinks.has(url)) return;
|
|
261
|
-
if (!url.startsWith('http') && !url.startsWith('https')) {
|
|
262
|
+
if (!url.startsWith('http://') && !url.startsWith('https://')) {
|
|
262
263
|
var _url_split_join;
|
|
263
264
|
const { routePath: normalizeUrl } = routeService.normalizeRoutePath(null === (_url_split_join = url.split(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].sep).join('/')) || void 0 === _url_split_join ? void 0 : _url_split_join.split('#')[0]);
|
|
264
265
|
internalLinks.add(normalizeUrl);
|
|
@@ -267,7 +268,7 @@ const remarkCheckDeadLinks = (checkLink)=>{
|
|
|
267
268
|
checkLinks(Array.from(internalLinks), vfile.path, root, routeService);
|
|
268
269
|
};
|
|
269
270
|
};
|
|
270
|
-
const remarkPluginNormalizeLink = ({ root, cleanUrls })=>(tree, file)=>{
|
|
271
|
+
const remarkPluginNormalizeLink = ({ root, cleanUrls, routeService })=>(tree, file)=>{
|
|
271
272
|
const images = [];
|
|
272
273
|
(0, __WEBPACK_EXTERNAL_MODULE_unist_util_visit_555e002a__.visit)(tree, 'link', (node)=>{
|
|
273
274
|
if (!node.url) return;
|
|
@@ -281,9 +282,16 @@ const remarkPluginNormalizeLink = ({ root, cleanUrls })=>(tree, file)=>{
|
|
|
281
282
|
return;
|
|
282
283
|
}
|
|
283
284
|
const extname = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].extname(url);
|
|
284
|
-
if (
|
|
285
|
+
if (((null == routeService ? void 0 : routeService.extensions) ?? __WEBPACK_EXTERNAL_MODULE__rspress_shared_constants_70084e62__.DEFAULT_PAGE_EXTENSIONS).includes(extname)) url = url.replace(new RegExp(`\\${extname}$`), '');
|
|
285
286
|
const relativePath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].relative(root, file.path);
|
|
286
287
|
if (url.startsWith('.')) url = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].posix.join((0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.slash)(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].dirname(relativePath)), url);
|
|
288
|
+
else if (routeService) {
|
|
289
|
+
const [pathVersion, pathLang] = routeService.getRoutePathParts((0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.slash)(relativePath));
|
|
290
|
+
const [urlVersion, urlLang, urlPath] = routeService.getRoutePathParts(url);
|
|
291
|
+
url = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.addLeadingSlash)(urlPath);
|
|
292
|
+
if (pathLang && urlLang !== pathLang) url = `/${pathLang}${url}`;
|
|
293
|
+
if (pathVersion && urlVersion !== pathVersion) url = `/${pathVersion}${url}`;
|
|
294
|
+
}
|
|
287
295
|
url = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.normalizeHref)(url, cleanUrls);
|
|
288
296
|
if (hash) url += `#${hash}`;
|
|
289
297
|
node.url = url;
|
|
@@ -437,7 +445,8 @@ async function createMDXOptions(docDirectory, config, checkDeadLinks, routeServi
|
|
|
437
445
|
remarkPluginNormalizeLink,
|
|
438
446
|
{
|
|
439
447
|
cleanUrls,
|
|
440
|
-
root: docDirectory
|
|
448
|
+
root: docDirectory,
|
|
449
|
+
routeService
|
|
441
450
|
}
|
|
442
451
|
],
|
|
443
452
|
checkDeadLinks && [
|
package/dist/runtime/App.js
CHANGED
|
@@ -19,10 +19,8 @@ async function initPageData(routePath) {
|
|
|
19
19
|
var _mod_default___RSPRESS_PAGE_META;
|
|
20
20
|
const mod = await matchedRoute.preload();
|
|
21
21
|
const pagePath = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.cleanUrl)(matchedRoute.filePath);
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
return (0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.isEqualPath)(normalize(page.routePath), normalize(matchedRoute.path));
|
|
25
|
-
});
|
|
22
|
+
const normalize = (p)=>p.replace(/\/$/, '').toLowerCase();
|
|
23
|
+
const extractPageInfo = __WEBPACK_EXTERNAL_MODULE_virtual_site_data_fa42d4c0__["default"].pages.find((page)=>(0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.isEqualPath)(normalize(page.routePath), normalize(matchedRoute.path)));
|
|
26
24
|
const encodedPagePath = encodeURIComponent(pagePath);
|
|
27
25
|
const meta = (null === (_mod_default___RSPRESS_PAGE_META = mod.default.__RSPRESS_PAGE_META) || void 0 === _mod_default___RSPRESS_PAGE_META ? void 0 : _mod_default___RSPRESS_PAGE_META[encodedPagePath]) || {};
|
|
28
26
|
const { toc = [], title = '', frontmatter = {}, ...rest } = __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.MDX_OR_MD_REGEXP.test(matchedRoute.filePath) ? meta : mod;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspress/core",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.6",
|
|
4
4
|
"description": "The Rspress Documentation Framework",
|
|
5
5
|
"bugs": "https://github.com/web-infra-dev/rspress/issues",
|
|
6
6
|
"repository": {
|
|
@@ -70,17 +70,17 @@
|
|
|
70
70
|
"unified": "^10.1.2",
|
|
71
71
|
"unist-util-visit": "^4.1.2",
|
|
72
72
|
"unist-util-visit-children": "^2.0.2",
|
|
73
|
-
"@rspress/plugin-auto-nav-sidebar": "2.0.0-alpha.
|
|
74
|
-
"@rspress/plugin-container-syntax": "2.0.0-alpha.
|
|
75
|
-
"@rspress/plugin-last-updated": "2.0.0-alpha.
|
|
76
|
-
"@rspress/runtime": "2.0.0-alpha.
|
|
77
|
-
"@rspress/shared": "2.0.0-alpha.
|
|
78
|
-
"@rspress/plugin-medium-zoom": "2.0.0-alpha.
|
|
79
|
-
"@rspress/theme-default": "2.0.0-alpha.
|
|
73
|
+
"@rspress/plugin-auto-nav-sidebar": "2.0.0-alpha.6",
|
|
74
|
+
"@rspress/plugin-container-syntax": "2.0.0-alpha.6",
|
|
75
|
+
"@rspress/plugin-last-updated": "2.0.0-alpha.6",
|
|
76
|
+
"@rspress/runtime": "2.0.0-alpha.6",
|
|
77
|
+
"@rspress/shared": "2.0.0-alpha.6",
|
|
78
|
+
"@rspress/plugin-medium-zoom": "2.0.0-alpha.6",
|
|
79
|
+
"@rspress/theme-default": "2.0.0-alpha.6"
|
|
80
80
|
},
|
|
81
81
|
"devDependencies": {
|
|
82
82
|
"@microsoft/api-extractor": "^7.52.1",
|
|
83
|
-
"@rslib/core": "0.5.
|
|
83
|
+
"@rslib/core": "0.5.5",
|
|
84
84
|
"@rspress-dev/plugin-preview": "link:../plugin-preview",
|
|
85
85
|
"@types/hast": "^2.3.10",
|
|
86
86
|
"@types/html-to-text": "^9.0.4",
|
|
@@ -88,7 +88,7 @@
|
|
|
88
88
|
"@types/lodash-es": "^4.17.12",
|
|
89
89
|
"@types/mdast": "^3.0.15",
|
|
90
90
|
"@types/node": "^18.11.17",
|
|
91
|
-
"@types/react": "^18.3.
|
|
91
|
+
"@types/react": "^18.3.19",
|
|
92
92
|
"@types/react-dom": "^18.3.5",
|
|
93
93
|
"memfs": "^4.17.0",
|
|
94
94
|
"postcss": "8.5.3",
|