@rspress/core 2.0.0-beta.33 → 2.0.0-beta.35
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/_private/react/index.js +2 -0
- package/dist/_private/react/reconciler.js +169 -0
- package/dist/_private/react/render.js +105 -0
- package/dist/cli.js +3 -4
- package/dist/index.d.ts +1701 -5
- package/dist/index.js +551 -205
- package/dist/loader.d.ts +10 -2
- package/dist/loader.js +4 -3
- package/dist/processor.d.ts +10 -2
- package/dist/processor.js +3736 -40
- package/dist/renderPageWorker.js +2 -1
- package/dist/runtime/ssrMdServerEntry.d.ts +5 -0
- package/dist/runtime/ssrMdServerEntry.js +38 -0
- package/meta-json-schema.json +45 -3
- package/package.json +20 -14
- /package/dist/{101.js → 5~101.js} +0 -0
- /package/dist/{335.js → 5~335.js} +0 -0
- /package/dist/{395.js → 5~395.js} +0 -0
package/dist/index.js
CHANGED
|
@@ -17,11 +17,10 @@ import { chunk, groupBy } from "lodash-es";
|
|
|
17
17
|
import { compile } from "@rspress/mdx-rs";
|
|
18
18
|
import { htmlToText } from "html-to-text";
|
|
19
19
|
import { createProcessor } from "@mdx-js/mdx";
|
|
20
|
-
import
|
|
20
|
+
import { mergeRsbuildConfig as core_mergeRsbuildConfig, rspack as core_rspack } from "@rsbuild/core";
|
|
21
21
|
import { createHash } from "node:crypto";
|
|
22
22
|
import { createHead, transformHtmlTemplate } from "@unhead/react/server";
|
|
23
23
|
import { visit } from "unist-util-visit";
|
|
24
|
-
import { mergeRsbuildConfig as core_mergeRsbuildConfig } from "@rsbuild/core";
|
|
25
24
|
var __webpack_modules__ = {
|
|
26
25
|
"@rspress/shared": function(module) {
|
|
27
26
|
module.exports = __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__;
|
|
@@ -66,7 +65,7 @@ __webpack_require__.m = __webpack_modules__;
|
|
|
66
65
|
}, []));
|
|
67
66
|
})();
|
|
68
67
|
(()=>{
|
|
69
|
-
__webpack_require__.u = (chunkId)=>"" + chunkId + ".js";
|
|
68
|
+
__webpack_require__.u = (chunkId)=>"5~" + chunkId + ".js";
|
|
70
69
|
})();
|
|
71
70
|
(()=>{
|
|
72
71
|
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
@@ -212,7 +211,7 @@ function normalizePath(id) {
|
|
|
212
211
|
return external_node_path_["default"].posix.normalize(isWindows ? slash(id) : id);
|
|
213
212
|
}
|
|
214
213
|
var external_node_url_ = __webpack_require__("node:url");
|
|
215
|
-
var package_namespaceObject = JSON.parse('{"rE":"2.0.0-beta.
|
|
214
|
+
var package_namespaceObject = JSON.parse('{"rE":"2.0.0-beta.35"}');
|
|
216
215
|
const RSPRESS_VERSION = package_namespaceObject.rE;
|
|
217
216
|
const isProduction = ()=>'production' === process.env.NODE_ENV;
|
|
218
217
|
const importStatementRegex = /import\s+(.*?)\s+from\s+(['"])(.*?)(?:"|');?/gm;
|
|
@@ -230,6 +229,7 @@ const TEMPLATE_PATH = external_node_path_["default"].join(PACKAGE_ROOT, 'index.h
|
|
|
230
229
|
const CSR_CLIENT_ENTRY = external_node_path_["default"].join(PACKAGE_ROOT, 'dist', 'runtime', 'csrClientEntry.js');
|
|
231
230
|
const SSR_CLIENT_ENTRY = external_node_path_["default"].join(PACKAGE_ROOT, 'dist', 'runtime', 'ssrClientEntry.js');
|
|
232
231
|
const SSR_SERVER_ENTRY = external_node_path_["default"].join(PACKAGE_ROOT, 'dist', 'runtime', 'ssrServerEntry.js');
|
|
232
|
+
const SSG_MD_SERVER_ENTRY = external_node_path_["default"].join(PACKAGE_ROOT, 'dist', 'runtime', 'ssrMdServerEntry.js');
|
|
233
233
|
const OUTPUT_DIR = 'doc_build';
|
|
234
234
|
const APP_HTML_MARKER = '<!--<?- DOC_CONTENT ?>-->';
|
|
235
235
|
const HEAD_MARKER = '<!--<?- HEAD ?>-->';
|
|
@@ -238,6 +238,8 @@ const DEFAULT_TITLE = 'Rspress';
|
|
|
238
238
|
const PUBLIC_DIR = 'public';
|
|
239
239
|
const NODE_SSG_BUNDLE_FOLDER = '__ssg__';
|
|
240
240
|
const NODE_SSG_BUNDLE_NAME = 'rspress-ssg-entry.cjs';
|
|
241
|
+
const NODE_SSG_MD_BUNDLE_FOLDER = '__ssg_md__';
|
|
242
|
+
const NODE_SSG_MD_BUNDLE_NAME = 'rspress-ssg-md-entry.cjs';
|
|
241
243
|
const getRoutePathParts = (relativePath, lang, version, langs, versions)=>{
|
|
242
244
|
const [versionPart, langPart, purePath] = splitRoutePathParts(relativePath, lang, version, langs, versions);
|
|
243
245
|
return [
|
|
@@ -448,6 +450,15 @@ ${routeMeta.map((route, index)=>{
|
|
|
448
450
|
getRoutePageByRoutePath(routePath) {
|
|
449
451
|
return this.routeData.get(routePath);
|
|
450
452
|
}
|
|
453
|
+
getDocsDir() {
|
|
454
|
+
return this.#scanDir;
|
|
455
|
+
}
|
|
456
|
+
getLangs() {
|
|
457
|
+
return this.#langs;
|
|
458
|
+
}
|
|
459
|
+
getDefaultLang() {
|
|
460
|
+
return this.#defaultLang;
|
|
461
|
+
}
|
|
451
462
|
}
|
|
452
463
|
class RoutePage {
|
|
453
464
|
routeMeta;
|
|
@@ -518,18 +529,59 @@ async function utils_readJson(path) {
|
|
|
518
529
|
return JSON.parse(raw);
|
|
519
530
|
}
|
|
520
531
|
async function extractInfoFromFrontmatterWithAbsolutePath(absolutePath, rootDir) {
|
|
521
|
-
const
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
532
|
+
const fileHandle = await node_fs_promises.open(absolutePath, 'r');
|
|
533
|
+
try {
|
|
534
|
+
const buffer = Buffer.alloc(2048);
|
|
535
|
+
let content = '';
|
|
536
|
+
let bytesRead = 0;
|
|
537
|
+
let hasFrontmatter = false;
|
|
538
|
+
let frontmatterEnd = -1;
|
|
539
|
+
let h1Match = null;
|
|
540
|
+
let frontmatter = {};
|
|
541
|
+
do {
|
|
542
|
+
const result = await fileHandle.read(buffer, 0, buffer.length, bytesRead);
|
|
543
|
+
if (0 === result.bytesRead) break;
|
|
544
|
+
content += buffer.subarray(0, result.bytesRead).toString('utf-8');
|
|
545
|
+
bytesRead += result.bytesRead;
|
|
546
|
+
if (bytesRead <= buffer.length) if (content.startsWith('---')) {
|
|
547
|
+
hasFrontmatter = true;
|
|
548
|
+
const secondDelimiter = content.indexOf('\n---\n', 4);
|
|
549
|
+
if (-1 !== secondDelimiter) {
|
|
550
|
+
frontmatterEnd = secondDelimiter + 5;
|
|
551
|
+
const { frontmatter: fm } = loadFrontMatter(content.slice(0, frontmatterEnd + 100), absolutePath, rootDir);
|
|
552
|
+
frontmatter = fm;
|
|
553
|
+
}
|
|
554
|
+
} else hasFrontmatter = false;
|
|
555
|
+
if (!h1Match) {
|
|
556
|
+
const searchStart = hasFrontmatter && frontmatterEnd > -1 ? frontmatterEnd : 0;
|
|
557
|
+
const h1RegExp = /^#\s+(.*?)\n$/m;
|
|
558
|
+
h1Match = content.slice(searchStart).match(h1RegExp);
|
|
559
|
+
}
|
|
560
|
+
if (hasFrontmatter && frontmatterEnd > -1 && h1Match) break;
|
|
561
|
+
if (!hasFrontmatter && h1Match) break;
|
|
562
|
+
if (hasFrontmatter && frontmatterEnd > -1 && bytesRead > 16384) break;
|
|
563
|
+
}while (bytesRead < 65536);
|
|
564
|
+
if (hasFrontmatter && -1 === frontmatterEnd) {
|
|
565
|
+
const { frontmatter: fm } = loadFrontMatter(content, absolutePath, rootDir);
|
|
566
|
+
frontmatter = fm;
|
|
567
|
+
}
|
|
568
|
+
if (!h1Match) {
|
|
569
|
+
const h1RegExp = /^#\s+(.*)$/m;
|
|
570
|
+
h1Match = content.match(h1RegExp);
|
|
571
|
+
}
|
|
572
|
+
const fileNameWithoutExt = external_node_path_["default"].basename(absolutePath, external_node_path_["default"].extname(absolutePath));
|
|
573
|
+
return {
|
|
574
|
+
title: extractTextAndId(frontmatter.title || h1Match?.[1] || fileNameWithoutExt)[0],
|
|
575
|
+
overviewHeaders: frontmatter.overviewHeaders,
|
|
576
|
+
context: frontmatter.context,
|
|
577
|
+
tag: frontmatter.tag,
|
|
578
|
+
description: frontmatter.description
|
|
579
|
+
};
|
|
580
|
+
} finally{
|
|
581
|
+
await fileHandle.close();
|
|
582
|
+
}
|
|
531
583
|
}
|
|
532
|
-
function
|
|
584
|
+
function getFileKey(realPath, docsDir) {
|
|
533
585
|
return realPath ? (0, shared_.slash)((0, external_node_path_.relative)(docsDir, realPath).replace((0, external_node_path_.extname)(realPath), '')) : '';
|
|
534
586
|
}
|
|
535
587
|
async function fsDirToMetaItems(workDir, extensions) {
|
|
@@ -559,83 +611,15 @@ async function fsDirToMetaItems(workDir, extensions) {
|
|
|
559
611
|
}))).filter(Boolean);
|
|
560
612
|
return sideMeta;
|
|
561
613
|
}
|
|
562
|
-
async function metaItemToSidebarItem(metaItem, workDir, docsDir, extensions, metaFileSet,
|
|
563
|
-
if ('string' == typeof metaItem) return metaFileItemToSidebarItem(metaItem, workDir, docsDir, extensions);
|
|
614
|
+
async function metaItemToSidebarItem(metaItem, workDir, docsDir, extensions, metaFileSet, mdFileSet) {
|
|
615
|
+
if ('string' == typeof metaItem) return metaFileItemToSidebarItem(metaItem, workDir, docsDir, extensions, mdFileSet);
|
|
564
616
|
const { type } = metaItem;
|
|
565
|
-
if ('file' === type) return metaFileItemToSidebarItem(metaItem, workDir, docsDir, extensions);
|
|
566
|
-
if ('dir' === type)
|
|
567
|
-
|
|
568
|
-
const dirAbsolutePath = (0, external_node_path_.join)(workDir, name);
|
|
569
|
-
const dirMetaJsonPath = (0, external_node_path_.join)(dirAbsolutePath, '_meta.json');
|
|
570
|
-
const isMetaJsonExist = await utils_pathExists(dirMetaJsonPath);
|
|
571
|
-
let dirMetaJson = [];
|
|
572
|
-
if (isMetaJsonExist) {
|
|
573
|
-
metaFileSet.add(dirMetaJsonPath);
|
|
574
|
-
dirMetaJson = await utils_readJson(dirMetaJsonPath);
|
|
575
|
-
} else dirMetaJson = await fsDirToMetaItems(dirAbsolutePath, extensions);
|
|
576
|
-
async function getItems(withoutIndex = false) {
|
|
577
|
-
const items = await Promise.all((withoutIndex ? dirMetaJson.filter((i)=>{
|
|
578
|
-
let name;
|
|
579
|
-
if ('object' == typeof i && 'type' in i && 'file' === i.type) name = i.name;
|
|
580
|
-
else {
|
|
581
|
-
if ('string' != typeof i) return true;
|
|
582
|
-
name = i;
|
|
583
|
-
}
|
|
584
|
-
return 'index.md' !== name && 'index.mdx' !== i && 'index' !== i;
|
|
585
|
-
}) : dirMetaJson).map((item)=>metaItemToSidebarItem(item, dirAbsolutePath, docsDir, extensions, metaFileSet)));
|
|
586
|
-
return items;
|
|
587
|
-
}
|
|
588
|
-
try {
|
|
589
|
-
const sameNameFile = await metaFileItemToSidebarItem(name, workDir, docsDir, extensions);
|
|
590
|
-
const { link, text, _fileKey, context, overviewHeaders, tag } = sameNameFile;
|
|
591
|
-
return {
|
|
592
|
-
text: label || text || name,
|
|
593
|
-
collapsible,
|
|
594
|
-
collapsed,
|
|
595
|
-
items: await getItems(),
|
|
596
|
-
link,
|
|
597
|
-
tag: metaJsonTag || tag,
|
|
598
|
-
overviewHeaders: metaJsonOverviewHeaders || overviewHeaders,
|
|
599
|
-
context: metaJsonContext || context,
|
|
600
|
-
_fileKey
|
|
601
|
-
};
|
|
602
|
-
} catch (e) {
|
|
603
|
-
logger.debug(e);
|
|
604
|
-
const isIndexInMetaJsonIndex = dirMetaJson.find((i)=>{
|
|
605
|
-
if ('string' == typeof i) return 'index' === i.replace((0, external_node_path_.extname)(i), '');
|
|
606
|
-
return false;
|
|
607
|
-
});
|
|
608
|
-
const isIndexFileExists = await utils_pathExists((0, external_node_path_.join)(dirAbsolutePath, 'index.mdx')) || await utils_pathExists((0, external_node_path_.join)(dirAbsolutePath, 'index.md'));
|
|
609
|
-
if (isMetaJsonExist && isIndexInMetaJsonIndex || !isIndexFileExists) return {
|
|
610
|
-
text: label || name,
|
|
611
|
-
collapsible,
|
|
612
|
-
collapsed,
|
|
613
|
-
items: await getItems(),
|
|
614
|
-
link: void 0,
|
|
615
|
-
tag: metaJsonTag,
|
|
616
|
-
overviewHeaders: metaJsonOverviewHeaders,
|
|
617
|
-
context: metaJsonContext,
|
|
618
|
-
_fileKey: getHmrFileKey(dirAbsolutePath, docsDir)
|
|
619
|
-
};
|
|
620
|
-
{
|
|
621
|
-
const indexFile = await metaFileItemToSidebarItem('index', dirAbsolutePath, docsDir, extensions);
|
|
622
|
-
const { link, text, _fileKey, context, overviewHeaders, tag } = indexFile;
|
|
623
|
-
return {
|
|
624
|
-
text: label || text || name,
|
|
625
|
-
collapsible,
|
|
626
|
-
collapsed,
|
|
627
|
-
items: await getItems(!isFirstDir),
|
|
628
|
-
link,
|
|
629
|
-
tag: metaJsonTag || tag,
|
|
630
|
-
overviewHeaders: metaJsonOverviewHeaders || overviewHeaders,
|
|
631
|
-
context: metaJsonContext || context,
|
|
632
|
-
_fileKey
|
|
633
|
-
};
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
}
|
|
617
|
+
if ('file' === type) return metaFileItemToSidebarItem(metaItem, workDir, docsDir, extensions, mdFileSet);
|
|
618
|
+
if ('dir' === type) return metaDirItemToSidebarItem(metaItem, workDir, docsDir, extensions, metaFileSet, mdFileSet, false);
|
|
619
|
+
if ('dir-section-header' === type) return metaDirSectionHeaderItemToSidebarItem(metaItem, workDir, docsDir, extensions, metaFileSet, mdFileSet);
|
|
637
620
|
if ('custom-link' === type) return metaCustomLinkItemToSidebarItem(metaItem, workDir, docsDir);
|
|
638
|
-
if ('divider' === type
|
|
621
|
+
if ('divider' === type) return metaDividerToSidebarItem(metaItem);
|
|
622
|
+
if ('section-header' === type) return metaSectionHeaderToSidebarItem(metaItem);
|
|
639
623
|
throw new Error(`Unknown meta item type: ${metaItem.type}, please check it in "${(0, external_node_path_.join)(workDir, '_meta.json')}".`);
|
|
640
624
|
}
|
|
641
625
|
async function detectFilePath(absolutePath, extensions) {
|
|
@@ -647,7 +631,7 @@ async function detectFilePath(absolutePath, extensions) {
|
|
|
647
631
|
}
|
|
648
632
|
throw new Error(`The file extension "${ext}" is not supported, please use one of the following extensions: ${extensions.join(', ')}`);
|
|
649
633
|
}
|
|
650
|
-
async function metaFileItemToSidebarItem(metaItemRaw, workDir, docsDir, extensions) {
|
|
634
|
+
async function metaFileItemToSidebarItem(metaItemRaw, workDir, docsDir, extensions, mdFileSet) {
|
|
651
635
|
let metaItem = null;
|
|
652
636
|
metaItem = 'string' == typeof metaItemRaw ? {
|
|
653
637
|
name: metaItemRaw,
|
|
@@ -665,14 +649,101 @@ async function metaFileItemToSidebarItem(metaItemRaw, workDir, docsDir, extensio
|
|
|
665
649
|
const link = absolutePathToRoutePath(absolutePathWithExt, docsDir);
|
|
666
650
|
const info = await extractInfoFromFrontmatterWithAbsolutePath(absolutePathWithExt, docsDir);
|
|
667
651
|
const title = label || info.title;
|
|
652
|
+
mdFileSet.add(absolutePathWithExt);
|
|
668
653
|
return {
|
|
669
654
|
text: title,
|
|
670
655
|
link,
|
|
671
|
-
tag,
|
|
656
|
+
tag: info.tag || tag,
|
|
672
657
|
overviewHeaders: info.overviewHeaders || overviewHeaders,
|
|
673
658
|
context: info.context || context,
|
|
674
|
-
_fileKey:
|
|
659
|
+
_fileKey: getFileKey(absolutePathWithExt, docsDir)
|
|
660
|
+
};
|
|
661
|
+
}
|
|
662
|
+
async function metaDirItemToSidebarItem(metaItem, workDir, docsDir, extensions, metaFileSet, mdFileSet, forceIndexFileAsItem) {
|
|
663
|
+
const { name, label, collapsible, collapsed, tag: metaJsonTag, context: metaJsonContext, overviewHeaders: metaJsonOverviewHeaders } = metaItem;
|
|
664
|
+
const dirAbsolutePath = (0, external_node_path_.join)(workDir, name);
|
|
665
|
+
const dirMetaJsonPath = (0, external_node_path_.join)(dirAbsolutePath, '_meta.json');
|
|
666
|
+
const isMetaJsonExist = await utils_pathExists(dirMetaJsonPath);
|
|
667
|
+
let dirMetaJson = [];
|
|
668
|
+
if (isMetaJsonExist) {
|
|
669
|
+
metaFileSet.add(dirMetaJsonPath);
|
|
670
|
+
dirMetaJson = await utils_readJson(dirMetaJsonPath);
|
|
671
|
+
} else dirMetaJson = await fsDirToMetaItems(dirAbsolutePath, extensions);
|
|
672
|
+
async function getItems(withoutIndex = false) {
|
|
673
|
+
const items = await Promise.all((withoutIndex ? dirMetaJson.filter((i)=>{
|
|
674
|
+
let name;
|
|
675
|
+
if ('object' == typeof i && 'type' in i && 'file' === i.type) name = i.name;
|
|
676
|
+
else {
|
|
677
|
+
if ('string' != typeof i) return true;
|
|
678
|
+
name = i;
|
|
679
|
+
}
|
|
680
|
+
return 'index.md' !== name && 'index.mdx' !== i && 'index' !== i;
|
|
681
|
+
}) : dirMetaJson).map((item)=>metaItemToSidebarItem(item, dirAbsolutePath, docsDir, extensions, metaFileSet, mdFileSet)));
|
|
682
|
+
return items.flat();
|
|
683
|
+
}
|
|
684
|
+
try {
|
|
685
|
+
const sameNameFile = await metaFileItemToSidebarItem(name, workDir, docsDir, extensions, mdFileSet);
|
|
686
|
+
const { link, text, _fileKey, context, overviewHeaders, tag } = sameNameFile;
|
|
687
|
+
return {
|
|
688
|
+
text: label || text || name,
|
|
689
|
+
collapsible,
|
|
690
|
+
collapsed,
|
|
691
|
+
items: await getItems(),
|
|
692
|
+
link,
|
|
693
|
+
tag: metaJsonTag || tag,
|
|
694
|
+
overviewHeaders: metaJsonOverviewHeaders || overviewHeaders,
|
|
695
|
+
context: metaJsonContext || context,
|
|
696
|
+
_fileKey
|
|
697
|
+
};
|
|
698
|
+
} catch (e) {
|
|
699
|
+
logger.debug(e);
|
|
700
|
+
const isIndexInMetaJsonIndex = dirMetaJson.find((i)=>{
|
|
701
|
+
if ('string' == typeof i) return 'index' === i.replace((0, external_node_path_.extname)(i), '');
|
|
702
|
+
return false;
|
|
703
|
+
});
|
|
704
|
+
const isIndexFileExists = await utils_pathExists((0, external_node_path_.join)(dirAbsolutePath, 'index.mdx')) || await utils_pathExists((0, external_node_path_.join)(dirAbsolutePath, 'index.md'));
|
|
705
|
+
if (isMetaJsonExist && isIndexInMetaJsonIndex || !isIndexFileExists) return {
|
|
706
|
+
text: label || name,
|
|
707
|
+
collapsible,
|
|
708
|
+
collapsed,
|
|
709
|
+
items: await getItems(),
|
|
710
|
+
overviewHeaders: metaJsonOverviewHeaders,
|
|
711
|
+
context: metaJsonContext,
|
|
712
|
+
_fileKey: getFileKey(dirAbsolutePath, docsDir)
|
|
713
|
+
};
|
|
714
|
+
{
|
|
715
|
+
const indexFile = await metaFileItemToSidebarItem('index', dirAbsolutePath, docsDir, extensions, mdFileSet);
|
|
716
|
+
const { link, text, _fileKey, context, overviewHeaders, tag } = indexFile;
|
|
717
|
+
return {
|
|
718
|
+
text: label || text || name,
|
|
719
|
+
collapsible,
|
|
720
|
+
collapsed,
|
|
721
|
+
items: await getItems(!forceIndexFileAsItem),
|
|
722
|
+
link,
|
|
723
|
+
tag: metaJsonTag || tag,
|
|
724
|
+
overviewHeaders: metaJsonOverviewHeaders || overviewHeaders,
|
|
725
|
+
context: metaJsonContext || context,
|
|
726
|
+
_fileKey
|
|
727
|
+
};
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
async function metaDirSectionHeaderItemToSidebarItem(metaItem, workDir, docsDir, extensions, metaFileSet, mdFileSet) {
|
|
732
|
+
const fakeDirMetaItem = {
|
|
733
|
+
...metaItem,
|
|
734
|
+
type: 'dir'
|
|
735
|
+
};
|
|
736
|
+
const fakeSectionHeaderMetaItem = {
|
|
737
|
+
label: metaItem.label,
|
|
738
|
+
tag: metaItem.tag,
|
|
739
|
+
type: 'section-header'
|
|
675
740
|
};
|
|
741
|
+
const dirSideGroup = await metaDirItemToSidebarItem(fakeDirMetaItem, workDir, docsDir, extensions, metaFileSet, mdFileSet, true);
|
|
742
|
+
const sectionHeaderSideItem = metaSectionHeaderToSidebarItem(fakeSectionHeaderMetaItem);
|
|
743
|
+
return [
|
|
744
|
+
sectionHeaderSideItem,
|
|
745
|
+
...dirSideGroup.items.length >= 1 ? dirSideGroup.items : []
|
|
746
|
+
];
|
|
676
747
|
}
|
|
677
748
|
function metaCustomLinkItemToSidebarItem(metaItem, workDir, docsDir) {
|
|
678
749
|
if ('items' in metaItem && Array.isArray(metaItem.items) && metaItem.items.length > 0) {
|
|
@@ -709,24 +780,23 @@ function metaCustomLinkItemToSidebarItem(metaItem, workDir, docsDir) {
|
|
|
709
780
|
throw new Error(`The custom link "${label}" does not have a link, please check it in "${(0, external_node_path_.join)(workDir, '_meta.json')}".`);
|
|
710
781
|
}
|
|
711
782
|
function metaDividerToSidebarItem(metaItem) {
|
|
712
|
-
const {
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
}
|
|
783
|
+
const { dashed } = metaItem;
|
|
784
|
+
return {
|
|
785
|
+
dividerType: dashed ? 'dashed' : 'solid'
|
|
786
|
+
};
|
|
787
|
+
}
|
|
788
|
+
function metaSectionHeaderToSidebarItem(metaItem) {
|
|
719
789
|
const { label, tag } = metaItem;
|
|
720
790
|
return {
|
|
721
791
|
sectionHeaderText: label ?? '',
|
|
722
792
|
tag
|
|
723
793
|
};
|
|
724
794
|
}
|
|
725
|
-
async function scanSideMeta(workDir, docsDir, extensions, metaFileSet) {
|
|
726
|
-
const dir = await
|
|
795
|
+
async function scanSideMeta(workDir, docsDir, extensions, metaFileSet, mdFileSet) {
|
|
796
|
+
const dir = await metaDirItemToSidebarItem({
|
|
727
797
|
type: 'dir',
|
|
728
798
|
name: ''
|
|
729
|
-
}, workDir, docsDir, extensions, metaFileSet, true);
|
|
799
|
+
}, workDir, docsDir, extensions, metaFileSet, mdFileSet, true);
|
|
730
800
|
return dir.items;
|
|
731
801
|
}
|
|
732
802
|
async function scanNav(workDir, docsDir, metaFileSet) {
|
|
@@ -747,7 +817,7 @@ async function scanNav(workDir, docsDir, metaFileSet) {
|
|
|
747
817
|
});
|
|
748
818
|
return navConfig;
|
|
749
819
|
}
|
|
750
|
-
async function walk(workDir, docsDir, extensions, metaFileSet) {
|
|
820
|
+
async function walk(workDir, docsDir, extensions, metaFileSet, mdFileSet) {
|
|
751
821
|
const rootNavJson = external_node_path_["default"].resolve(workDir, '_nav.json');
|
|
752
822
|
const rootMetaJson = external_node_path_["default"].resolve(workDir, '_meta.json');
|
|
753
823
|
const isRootNavJsonExist = await pathExists(rootNavJson);
|
|
@@ -761,7 +831,7 @@ async function walk(workDir, docsDir, extensions, metaFileSet) {
|
|
|
761
831
|
return {
|
|
762
832
|
nav: navConfig,
|
|
763
833
|
sidebar: {
|
|
764
|
-
'/': await scanSideMeta(workDir, docsDir, extensions, metaFileSet)
|
|
834
|
+
'/': await scanSideMeta(workDir, docsDir, extensions, metaFileSet, mdFileSet)
|
|
765
835
|
}
|
|
766
836
|
};
|
|
767
837
|
}
|
|
@@ -774,7 +844,7 @@ async function walk(workDir, docsDir, extensions, metaFileSet) {
|
|
|
774
844
|
const sidebarConfig = {};
|
|
775
845
|
await Promise.all(subDirs.map(async (subDir)=>{
|
|
776
846
|
const sidebarGroupKey = addRoutePrefix(workDir, docsDir, subDir);
|
|
777
|
-
sidebarConfig[sidebarGroupKey] = await scanSideMeta(external_node_path_["default"].join(workDir, subDir), docsDir, extensions, metaFileSet);
|
|
847
|
+
sidebarConfig[sidebarGroupKey] = await scanSideMeta(external_node_path_["default"].join(workDir, subDir), docsDir, extensions, metaFileSet, mdFileSet);
|
|
778
848
|
}));
|
|
779
849
|
return {
|
|
780
850
|
nav: navConfig,
|
|
@@ -784,7 +854,7 @@ async function walk(workDir, docsDir, extensions, metaFileSet) {
|
|
|
784
854
|
return {
|
|
785
855
|
nav: [],
|
|
786
856
|
sidebar: {
|
|
787
|
-
'/': await scanSideMeta(workDir, docsDir, extensions, metaFileSet)
|
|
857
|
+
'/': await scanSideMeta(workDir, docsDir, extensions, metaFileSet, mdFileSet)
|
|
788
858
|
}
|
|
789
859
|
};
|
|
790
860
|
}
|
|
@@ -803,15 +873,15 @@ function combineWalkResult(walks, versions) {
|
|
|
803
873
|
sidebar: {}
|
|
804
874
|
});
|
|
805
875
|
}
|
|
806
|
-
function processLocales(langs, versions, root, extensions, metaFileSet) {
|
|
876
|
+
function processLocales(langs, versions, root, extensions, metaFileSet, mdFileSet) {
|
|
807
877
|
return Promise.all(langs.map(async (lang)=>{
|
|
808
|
-
const walks = versions.length ? await Promise.all(versions.map((version)=>walk(external_node_path_["default"].join(root, version, lang), root, extensions, metaFileSet))) : [
|
|
809
|
-
await walk(external_node_path_["default"].join(root, lang), root, extensions, metaFileSet)
|
|
878
|
+
const walks = versions.length ? await Promise.all(versions.map((version)=>walk(external_node_path_["default"].join(root, version, lang), root, extensions, metaFileSet, mdFileSet))) : [
|
|
879
|
+
await walk(external_node_path_["default"].join(root, lang), root, extensions, metaFileSet, mdFileSet)
|
|
810
880
|
];
|
|
811
881
|
return combineWalkResult(walks, versions);
|
|
812
882
|
}));
|
|
813
883
|
}
|
|
814
|
-
async function runAutoNavSide(config, metaFileSet) {
|
|
884
|
+
async function runAutoNavSide(config, metaFileSet, mdFileSet) {
|
|
815
885
|
config.themeConfig = config.themeConfig || {};
|
|
816
886
|
config.themeConfig.locales = config.themeConfig.locales || config.locales || [];
|
|
817
887
|
const langs = config.themeConfig.locales.map((locale)=>locale.lang);
|
|
@@ -819,11 +889,11 @@ async function runAutoNavSide(config, metaFileSet) {
|
|
|
819
889
|
const versions = config.multiVersion?.versions || [];
|
|
820
890
|
const { extensions = DEFAULT_PAGE_EXTENSIONS } = config?.route || {};
|
|
821
891
|
if (hasLocales) {
|
|
822
|
-
const metaInfo = await processLocales(langs, versions, config.root, extensions, metaFileSet);
|
|
892
|
+
const metaInfo = await processLocales(langs, versions, config.root, extensions, metaFileSet, mdFileSet);
|
|
823
893
|
return metaInfo;
|
|
824
894
|
}
|
|
825
|
-
const walks = versions.length ? await Promise.all(versions.map((version)=>walk(external_node_path_["default"].join(config.root, version), config.root, extensions, metaFileSet))) : [
|
|
826
|
-
await walk(config.root, config.root, extensions, metaFileSet)
|
|
895
|
+
const walks = versions.length ? await Promise.all(versions.map((version)=>walk(external_node_path_["default"].join(config.root, version), config.root, extensions, metaFileSet, mdFileSet))) : [
|
|
896
|
+
await walk(config.root, config.root, extensions, metaFileSet, mdFileSet)
|
|
827
897
|
];
|
|
828
898
|
const combined = combineWalkResult(walks, versions);
|
|
829
899
|
return combined;
|
|
@@ -833,9 +903,9 @@ function auto_nav_sidebar_haveNavSidebarConfig(config) {
|
|
|
833
903
|
const haveNavSidebarConfig = themeConfig.nav || themeConfig.sidebar || themeConfig.locales?.[0]?.nav || themeConfig.locales?.[0]?.sidebar;
|
|
834
904
|
return Boolean(haveNavSidebarConfig);
|
|
835
905
|
}
|
|
836
|
-
async function modifyConfigWithAutoNavSide(config, metaFileSet = new Set(), force = false) {
|
|
906
|
+
async function modifyConfigWithAutoNavSide(config, metaFileSet = new Set(), mdFileSet = new Set(), force = false) {
|
|
837
907
|
if (auto_nav_sidebar_haveNavSidebarConfig(config) && !force) return;
|
|
838
|
-
const autoNavSide = await runAutoNavSide(config, metaFileSet);
|
|
908
|
+
const autoNavSide = await runAutoNavSide(config, metaFileSet, mdFileSet);
|
|
839
909
|
if (null === autoNavSide) return;
|
|
840
910
|
if (Array.isArray(autoNavSide)) {
|
|
841
911
|
config.themeConfig = config.themeConfig || {};
|
|
@@ -855,7 +925,7 @@ const pluginVirtualModule = (pluginOptions = {})=>({
|
|
|
855
925
|
name: PLUGIN_VIRTUAL_MODULE_NAME,
|
|
856
926
|
async setup (api) {
|
|
857
927
|
const { virtualModules = {}, tempDir: virtualFolderName = '.rsbuild-virtual-module' } = pluginOptions;
|
|
858
|
-
const TEMP_DIR = (0, external_node_path_.join)(api.context.rootPath,
|
|
928
|
+
const TEMP_DIR = (0, external_node_path_.join)(api.context.rootPath, virtualFolderName);
|
|
859
929
|
const virtualFileAbsolutePaths = Object.keys(virtualModules).map((i)=>{
|
|
860
930
|
let absolutePath = (0, external_node_path_.join)(TEMP_DIR, i);
|
|
861
931
|
if (!(0, external_node_path_.extname)(absolutePath)) absolutePath = `${absolutePath}.js`;
|
|
@@ -864,23 +934,26 @@ const pluginVirtualModule = (pluginOptions = {})=>({
|
|
|
864
934
|
absolutePath
|
|
865
935
|
];
|
|
866
936
|
});
|
|
867
|
-
api.
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
937
|
+
api.modifyBundlerChain((chain, { rspack })=>{
|
|
938
|
+
const pluginId = 'RSBUILD_VIRTUAL_MODULE_PLUGIN';
|
|
939
|
+
const virtualModules = Object.fromEntries(virtualFileAbsolutePaths.map((i)=>[
|
|
940
|
+
i[1],
|
|
941
|
+
''
|
|
942
|
+
]));
|
|
943
|
+
if (chain.plugins.has(pluginId)) chain.plugin(pluginId).tap((options)=>{
|
|
944
|
+
const existingPaths = new Set(Object.keys(options[0] ?? {}));
|
|
945
|
+
const conflictPath = virtualFileAbsolutePaths.find(([, path])=>existingPaths.has(path));
|
|
946
|
+
if (conflictPath) throw new Error(`Virtual module name conflicted: ${conflictPath[0]}`);
|
|
947
|
+
return [
|
|
948
|
+
{
|
|
949
|
+
...options[0],
|
|
950
|
+
...virtualModules
|
|
951
|
+
}
|
|
952
|
+
];
|
|
953
|
+
});
|
|
954
|
+
else chain.plugin(pluginId).use(rspack.experiments.VirtualModulesPlugin, [
|
|
955
|
+
virtualModules
|
|
956
|
+
]);
|
|
884
957
|
chain.resolve.alias.merge(Object.fromEntries(virtualFileAbsolutePaths));
|
|
885
958
|
});
|
|
886
959
|
for (const [moduleName, absolutePath] of virtualFileAbsolutePaths){
|
|
@@ -953,30 +1026,21 @@ const i18nVMPlugin = (context)=>{
|
|
|
953
1026
|
};
|
|
954
1027
|
};
|
|
955
1028
|
var external_node_fs_ = __webpack_require__("node:fs");
|
|
956
|
-
|
|
1029
|
+
const RspackResolveFactory = core_rspack.experiments.resolver.ResolverFactory;
|
|
957
1030
|
let startFlatten = false;
|
|
1031
|
+
let flattenMdxContent_resolver;
|
|
958
1032
|
const processor = createProcessor();
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
async function resolveDepPath(importPath, importer, alias) {
|
|
962
|
-
if (!flattenMdxContent_resolver) flattenMdxContent_resolver = ResolverFactory.createResolver({
|
|
963
|
-
fileSystem: new CachedInputFileSystem(fileSystem, 0),
|
|
1033
|
+
async function resolveDepPath(moduleSpecifier, importer, alias) {
|
|
1034
|
+
if (!flattenMdxContent_resolver) flattenMdxContent_resolver = new RspackResolveFactory({
|
|
964
1035
|
extensions: [
|
|
965
1036
|
'.mdx',
|
|
966
1037
|
'.md'
|
|
967
1038
|
],
|
|
968
1039
|
alias
|
|
969
1040
|
});
|
|
970
|
-
const
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
}, importer, importPath, {}, (err, filePath)=>{
|
|
974
|
-
if (err) return reject(err);
|
|
975
|
-
if (!filePath) return reject(new Error(`Empty result when resolving ${importPath} from ${importer}`));
|
|
976
|
-
return resolve(filePath);
|
|
977
|
-
});
|
|
978
|
-
});
|
|
979
|
-
return resolveResult;
|
|
1041
|
+
const resolved = await flattenMdxContent_resolver.async(importer, moduleSpecifier);
|
|
1042
|
+
if (resolved.path) return resolved.path;
|
|
1043
|
+
throw new Error(`Empty result when resolving ${moduleSpecifier} from ${importer}`);
|
|
980
1044
|
}
|
|
981
1045
|
async function flattenMdxContent(content, basePath, alias) {
|
|
982
1046
|
const deps = [];
|
|
@@ -986,8 +1050,7 @@ async function flattenMdxContent(content, basePath, alias) {
|
|
|
986
1050
|
deps
|
|
987
1051
|
};
|
|
988
1052
|
if (!startFlatten) {
|
|
989
|
-
flattenMdxContent_resolver =
|
|
990
|
-
fileSystem: new CachedInputFileSystem(fileSystem, 0),
|
|
1053
|
+
flattenMdxContent_resolver = new RspackResolveFactory({
|
|
991
1054
|
extensions: [
|
|
992
1055
|
'.mdx',
|
|
993
1056
|
'.md',
|
|
@@ -1357,10 +1420,8 @@ function normalizeThemeConfig(docConfig) {
|
|
|
1357
1420
|
async function createSiteData(userConfig) {
|
|
1358
1421
|
const tempSearchObj = Object.assign({}, userConfig.search);
|
|
1359
1422
|
if (tempSearchObj) tempSearchObj.searchHooks = void 0;
|
|
1360
|
-
const { base } = userConfig;
|
|
1361
|
-
const normalizedBase = (0, shared_.addTrailingSlash)((0, shared_.addLeadingSlash)(base ?? '/'));
|
|
1362
1423
|
const siteData = {
|
|
1363
|
-
base:
|
|
1424
|
+
base: userConfig.base ?? '/',
|
|
1364
1425
|
title: userConfig?.title || '',
|
|
1365
1426
|
description: userConfig?.description || '',
|
|
1366
1427
|
icon: getIconUrlPath(userConfig?.icon) || '',
|
|
@@ -1393,10 +1454,14 @@ const siteDataVMPlugin = (context)=>{
|
|
|
1393
1454
|
["virtual-site-data"]: async ({ addDependency })=>{
|
|
1394
1455
|
const force = !pluginDriver.haveNavSidebarConfig;
|
|
1395
1456
|
const metaFileSet = new Set();
|
|
1457
|
+
const mdFileSet = new Set();
|
|
1458
|
+
const now = performance.now();
|
|
1396
1459
|
try {
|
|
1397
|
-
await modifyConfigWithAutoNavSide(config, metaFileSet, force);
|
|
1460
|
+
await modifyConfigWithAutoNavSide(config, metaFileSet, mdFileSet, force);
|
|
1398
1461
|
} finally{
|
|
1399
|
-
|
|
1462
|
+
for (const metaFile of metaFileSet)addDependency(metaFile);
|
|
1463
|
+
for (const mdFile of mdFileSet)addDependency(mdFile);
|
|
1464
|
+
logger.debug(`modifyConfigWithAutoNavSide - size: ${mdFileSet.size} cost: ${performance.now() - now}ms`);
|
|
1400
1465
|
}
|
|
1401
1466
|
const { siteData } = await createSiteData(config);
|
|
1402
1467
|
return `export default ${JSON.stringify(siteData, null, 2)}`;
|
|
@@ -1806,7 +1871,235 @@ const rsbuildPluginSSG = ({ routeService, config })=>({
|
|
|
1806
1871
|
});
|
|
1807
1872
|
}
|
|
1808
1873
|
});
|
|
1809
|
-
|
|
1874
|
+
function routePathToMdPath(routePath, base) {
|
|
1875
|
+
let url = routePath;
|
|
1876
|
+
url = (0, shared_.normalizeHref)(url, false);
|
|
1877
|
+
url = url.replace(/\.html$/, '.md');
|
|
1878
|
+
return (0, shared_.withBase)(url, base);
|
|
1879
|
+
}
|
|
1880
|
+
async function generateLlmsTxt(routeGroups, others, navList, title, description, base, routeService) {
|
|
1881
|
+
const lines = [];
|
|
1882
|
+
const summary = `# ${title}${description ? `\n\n> ${description}` : ''}`;
|
|
1883
|
+
async function genH2Part(nav, routes) {
|
|
1884
|
+
const lines = [];
|
|
1885
|
+
const { text } = nav;
|
|
1886
|
+
if (0 === routes.length) return lines;
|
|
1887
|
+
const routeLines = (await Promise.all(routes.map(async (route)=>{
|
|
1888
|
+
const routePage = routeService.getRoutePageByRoutePath(route);
|
|
1889
|
+
const { lang, routePath, absolutePath } = routePage.routeMeta;
|
|
1890
|
+
if ('/' === routePath || routePath === `/${lang}/`) return;
|
|
1891
|
+
const { title, description } = await extractInfoFromFrontmatterWithAbsolutePath(absolutePath, routeService.getDocsDir());
|
|
1892
|
+
return `- [${title}](${routePathToMdPath(routePath, base)})${description ? `: ${description}` : ''}`;
|
|
1893
|
+
}))).filter((i)=>Boolean(i));
|
|
1894
|
+
if (routeLines.length > 0) {
|
|
1895
|
+
const title = text;
|
|
1896
|
+
lines.push(`\n## ${title}\n`);
|
|
1897
|
+
lines.push(...routeLines);
|
|
1898
|
+
}
|
|
1899
|
+
return lines;
|
|
1900
|
+
}
|
|
1901
|
+
const h2Parts = await Promise.all(navList.map(async (nav, i)=>{
|
|
1902
|
+
const routes = routeGroups[i];
|
|
1903
|
+
const h2Part = await genH2Part(nav, routes);
|
|
1904
|
+
return h2Part;
|
|
1905
|
+
}));
|
|
1906
|
+
lines.push(...h2Parts.flat());
|
|
1907
|
+
const otherLines = await genH2Part({
|
|
1908
|
+
text: 'Others'
|
|
1909
|
+
}, others);
|
|
1910
|
+
lines.push(...otherLines);
|
|
1911
|
+
const llmsTxt = `${summary}\n${lines.join('\n')}`;
|
|
1912
|
+
return llmsTxt;
|
|
1913
|
+
}
|
|
1914
|
+
function generateLlmsFullTxt(routeGroups, navList, others, base, mdContents) {
|
|
1915
|
+
const lines = [];
|
|
1916
|
+
for(let i = 0; i < navList.length; i++){
|
|
1917
|
+
const routeGroup = routeGroups[i];
|
|
1918
|
+
if (0 !== routeGroup.length) for (const routePath of routeGroup){
|
|
1919
|
+
lines.push(`---
|
|
1920
|
+
url: ${routePathToMdPath(routePath, base)}
|
|
1921
|
+
---
|
|
1922
|
+
`);
|
|
1923
|
+
lines.push(mdContents.get(routePath) ?? '');
|
|
1924
|
+
lines.push('\n');
|
|
1925
|
+
}
|
|
1926
|
+
}
|
|
1927
|
+
for (const routePath of others){
|
|
1928
|
+
lines.push(`---
|
|
1929
|
+
url: ${routePathToMdPath(routePath, base)}
|
|
1930
|
+
---
|
|
1931
|
+
`);
|
|
1932
|
+
lines.push(mdContents.get(routePath) ?? '');
|
|
1933
|
+
lines.push('\n');
|
|
1934
|
+
}
|
|
1935
|
+
return lines.join('\n');
|
|
1936
|
+
}
|
|
1937
|
+
async function emitLlmsTxt(config, routeService, emitAsset, mdContents) {
|
|
1938
|
+
const base = config.base ?? '/';
|
|
1939
|
+
const locales = config.themeConfig?.locales;
|
|
1940
|
+
const isMultiLang = locales && locales.length > 0;
|
|
1941
|
+
const nav = isMultiLang ? locales.filter((i)=>Boolean(i.nav)).map((i)=>({
|
|
1942
|
+
nav: i.nav,
|
|
1943
|
+
lang: i.lang
|
|
1944
|
+
})) : [
|
|
1945
|
+
{
|
|
1946
|
+
nav: config.themeConfig?.nav,
|
|
1947
|
+
lang: config.lang ?? ''
|
|
1948
|
+
}
|
|
1949
|
+
];
|
|
1950
|
+
const sidebars = isMultiLang ? locales.map((i)=>i.sidebar) : [
|
|
1951
|
+
config.themeConfig?.sidebar
|
|
1952
|
+
];
|
|
1953
|
+
const sidebar = sidebars.reduce((prev, curr)=>{
|
|
1954
|
+
Object.assign(prev, curr);
|
|
1955
|
+
return prev;
|
|
1956
|
+
}, {});
|
|
1957
|
+
const noVersionNav = Array.isArray(nav) ? nav.map((i)=>{
|
|
1958
|
+
const nav = i.nav.default || i.nav;
|
|
1959
|
+
const lang = i.lang;
|
|
1960
|
+
return nav.map((i)=>({
|
|
1961
|
+
...i,
|
|
1962
|
+
lang
|
|
1963
|
+
}));
|
|
1964
|
+
}).flat().filter((i)=>i.activeMatch || i.link) : [];
|
|
1965
|
+
const defaultLang = routeService.getDefaultLang();
|
|
1966
|
+
await Promise.all(routeService.getLangs().map(async (lang)=>{
|
|
1967
|
+
const navList = noVersionNav.filter((i)=>i.lang === lang);
|
|
1968
|
+
const routeGroups = new Array(navList.length).fill(0).map(()=>[]);
|
|
1969
|
+
const others = [];
|
|
1970
|
+
routeService.getRoutes().forEach((routeMeta)=>{
|
|
1971
|
+
if (routeMeta.lang !== lang) return;
|
|
1972
|
+
const { routePath } = routeMeta;
|
|
1973
|
+
for(let i = 0; i < routeGroups.length; i++){
|
|
1974
|
+
const routeGroup = routeGroups[i];
|
|
1975
|
+
const navItem = navList[i];
|
|
1976
|
+
if (lang === navItem.lang && new RegExp(navItem.activeMatch ?? navItem.link).test(routePath)) return void routeGroup.push(routePath);
|
|
1977
|
+
}
|
|
1978
|
+
others.push(routePath);
|
|
1979
|
+
});
|
|
1980
|
+
for (const routeGroup of routeGroups)organizeBySidebar(sidebar, routeGroup);
|
|
1981
|
+
const llmsTxtContent = await generateLlmsTxt(routeGroups, others, navList, config.title, config.description, config.base, routeService);
|
|
1982
|
+
const llmsFullTxtContent = generateLlmsFullTxt(routeGroups, navList, others, base, mdContents);
|
|
1983
|
+
const prefix = defaultLang === lang ? '' : `${lang}/`;
|
|
1984
|
+
emitAsset(`${prefix}llms.txt`, llmsTxtContent);
|
|
1985
|
+
emitAsset(`${prefix}llms-full.txt`, llmsFullTxtContent);
|
|
1986
|
+
}));
|
|
1987
|
+
}
|
|
1988
|
+
function flatSidebar(sidebar) {
|
|
1989
|
+
if (!sidebar) return [];
|
|
1990
|
+
return sidebar.flatMap((i)=>{
|
|
1991
|
+
if ('string' == typeof i) return i;
|
|
1992
|
+
if ('link' in i && 'string' == typeof i.link) return [
|
|
1993
|
+
i.link,
|
|
1994
|
+
...flatSidebar(i?.items ?? [])
|
|
1995
|
+
];
|
|
1996
|
+
if ('items' in i && Array.isArray(i.items)) return flatSidebar(i.items);
|
|
1997
|
+
}).filter(Boolean);
|
|
1998
|
+
}
|
|
1999
|
+
function organizeBySidebar(sidebar, routes) {
|
|
2000
|
+
if (0 === routes.length) return;
|
|
2001
|
+
const route = routes[0];
|
|
2002
|
+
const currSidebar = (0, shared_.getSidebarDataGroup)(sidebar, route);
|
|
2003
|
+
if (0 === currSidebar.length) return;
|
|
2004
|
+
const orderList = flatSidebar(currSidebar);
|
|
2005
|
+
routes.sort((a, b)=>{
|
|
2006
|
+
let aIndex = orderList.findIndex((order)=>matchPath(order, a));
|
|
2007
|
+
if (-1 === aIndex) aIndex = Number.MAX_SAFE_INTEGER;
|
|
2008
|
+
let bIndex = orderList.findIndex((order)=>matchPath(order, b));
|
|
2009
|
+
if (-1 === bIndex) bIndex = Number.MAX_SAFE_INTEGER;
|
|
2010
|
+
return aIndex - bIndex;
|
|
2011
|
+
});
|
|
2012
|
+
}
|
|
2013
|
+
async function renderPage_renderPage(route, ssrBundlePath) {
|
|
2014
|
+
let render;
|
|
2015
|
+
try {
|
|
2016
|
+
const { default: ssrExports } = await import((0, external_node_url_.pathToFileURL)(ssrBundlePath).toString());
|
|
2017
|
+
render = await ssrExports.render;
|
|
2018
|
+
} catch (e) {
|
|
2019
|
+
if (e instanceof Error) {
|
|
2020
|
+
logger.error(`Failed to load SSG bundle: ${picocolors.yellow(ssrBundlePath)}: ${e.message}`);
|
|
2021
|
+
logger.debug(e);
|
|
2022
|
+
hintSSGFailed();
|
|
2023
|
+
}
|
|
2024
|
+
throw e;
|
|
2025
|
+
}
|
|
2026
|
+
const head = createHead();
|
|
2027
|
+
const { routePath } = route;
|
|
2028
|
+
let appMd = '';
|
|
2029
|
+
if (render) try {
|
|
2030
|
+
({ appMd } = await render(routePath, head));
|
|
2031
|
+
} catch (e) {
|
|
2032
|
+
if (e instanceof Error) {
|
|
2033
|
+
logger.error(`Page "${picocolors.yellow(routePath)}" SSG-MD rendering failed.\n ${picocolors.gray(e.toString())}`);
|
|
2034
|
+
throw e;
|
|
2035
|
+
}
|
|
2036
|
+
}
|
|
2037
|
+
return appMd;
|
|
2038
|
+
}
|
|
2039
|
+
const routePage2MdFilename = (routePath)=>{
|
|
2040
|
+
let fileName = routePath;
|
|
2041
|
+
fileName = fileName.endsWith('/') ? `${routePath}index.md` : `${routePath}.md`;
|
|
2042
|
+
return fileName.replace(/^\/+/, '');
|
|
2043
|
+
};
|
|
2044
|
+
async function renderPages_renderPages(routeService, ssrBundlePath, emitAsset) {
|
|
2045
|
+
logger.info('Rendering md pages...');
|
|
2046
|
+
const startTime = Date.now();
|
|
2047
|
+
const result = new Map();
|
|
2048
|
+
const routes = routeService.getRoutes();
|
|
2049
|
+
await pMap(routes, async (route)=>{
|
|
2050
|
+
const html = await renderPage_renderPage(route, ssrBundlePath);
|
|
2051
|
+
const fileName = routePage2MdFilename(route.routePath);
|
|
2052
|
+
emitAsset(fileName, html);
|
|
2053
|
+
result.set(route.routePath, html);
|
|
2054
|
+
}, {
|
|
2055
|
+
concurrency: SSGConcurrency()
|
|
2056
|
+
});
|
|
2057
|
+
const totalTime = Date.now() - startTime;
|
|
2058
|
+
logger.success(`Markdown rendered in ${picocolors.yellow(totalTime)} ms.`);
|
|
2059
|
+
return result;
|
|
2060
|
+
}
|
|
2061
|
+
const rsbuildPluginSSGMD = ({ routeService, config })=>({
|
|
2062
|
+
name: 'rspress-inner-rsbuild-plugin-ssg',
|
|
2063
|
+
async setup (api) {
|
|
2064
|
+
api.onBeforeBuild(()=>{
|
|
2065
|
+
let hasError = false;
|
|
2066
|
+
api.processAssets({
|
|
2067
|
+
stage: 'optimize-transfer',
|
|
2068
|
+
environments: [
|
|
2069
|
+
'node_md'
|
|
2070
|
+
]
|
|
2071
|
+
}, async ({ assets, compilation, environment, compiler })=>{
|
|
2072
|
+
if (compilation.errors.length > 0) {
|
|
2073
|
+
hasError = true;
|
|
2074
|
+
return;
|
|
2075
|
+
}
|
|
2076
|
+
if (hasError) return;
|
|
2077
|
+
const emitAsset = (assetName, content)=>{
|
|
2078
|
+
compilation.emitAsset(assetName, new compiler.webpack.sources.RawSource(content));
|
|
2079
|
+
};
|
|
2080
|
+
const distPath = environment.distPath;
|
|
2081
|
+
const ssgFolderPath = (0, external_node_path_.join)(distPath, NODE_SSG_MD_BUNDLE_FOLDER);
|
|
2082
|
+
const mainCjsAbsolutePath = (0, external_node_path_.join)(ssgFolderPath, NODE_SSG_MD_BUNDLE_NAME);
|
|
2083
|
+
await mkdir(ssgFolderPath, {
|
|
2084
|
+
recursive: true
|
|
2085
|
+
});
|
|
2086
|
+
await Promise.all(Object.entries(assets).map(async ([assetName, assetSource])=>{
|
|
2087
|
+
if (assetName.startsWith(`${NODE_SSG_MD_BUNDLE_FOLDER}/`)) {
|
|
2088
|
+
const fileAbsolutePath = (0, external_node_path_.join)(distPath, assetName);
|
|
2089
|
+
await writeFile(fileAbsolutePath, assetSource.source().toString());
|
|
2090
|
+
compilation.deleteAsset(assetName);
|
|
2091
|
+
}
|
|
2092
|
+
}));
|
|
2093
|
+
const mdContents = await renderPages_renderPages(routeService, mainCjsAbsolutePath, emitAsset);
|
|
2094
|
+
await emitLlmsTxt(config, routeService, emitAsset, mdContents);
|
|
2095
|
+
if (!(0, shared_.isDebugMode)()) await rm(ssgFolderPath, {
|
|
2096
|
+
recursive: true
|
|
2097
|
+
});
|
|
2098
|
+
});
|
|
2099
|
+
});
|
|
2100
|
+
}
|
|
2101
|
+
});
|
|
2102
|
+
const Resolver = core_rspack.experiments.resolver.ResolverFactory;
|
|
1810
2103
|
async function detectPackageMajorVersion(name) {
|
|
1811
2104
|
const cwd = process.cwd();
|
|
1812
2105
|
const pkgPath = external_node_path_["default"].join(cwd, 'node_modules', name);
|
|
@@ -1822,8 +2115,7 @@ async function detectReactVersion() {
|
|
|
1822
2115
|
}
|
|
1823
2116
|
async function resolveReactRouterDomAlias() {
|
|
1824
2117
|
const alias = {};
|
|
1825
|
-
const resolver =
|
|
1826
|
-
fileSystem: new detectReactVersion_CachedInputFileSystem(external_node_fs_["default"], 0),
|
|
2118
|
+
const resolver = new Resolver({
|
|
1827
2119
|
mainFields: [
|
|
1828
2120
|
'browser',
|
|
1829
2121
|
'module',
|
|
@@ -1835,16 +2127,11 @@ async function resolveReactRouterDomAlias() {
|
|
|
1835
2127
|
alias
|
|
1836
2128
|
});
|
|
1837
2129
|
try {
|
|
1838
|
-
const
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
}, PACKAGE_ROOT, 'react-router-dom', {}, (err, filePath)=>{
|
|
1842
|
-
if (err || !filePath) return reject(err);
|
|
1843
|
-
return resolve(filePath);
|
|
1844
|
-
});
|
|
1845
|
-
});
|
|
2130
|
+
const resolved = await resolver.async(PACKAGE_ROOT, 'react-router-dom');
|
|
2131
|
+
if (resolved.error) throw Error(resolved.error);
|
|
2132
|
+
if (!resolved.path) throw Error("'react-router-dom' resolved to empty path");
|
|
1846
2133
|
return {
|
|
1847
|
-
'react-router-dom':
|
|
2134
|
+
'react-router-dom': resolved.path
|
|
1848
2135
|
};
|
|
1849
2136
|
} catch (e) {
|
|
1850
2137
|
logger.warn('react-router-dom not found: \n', e);
|
|
@@ -1862,8 +2149,7 @@ async function resolveReactAlias(reactVersion, isSSR) {
|
|
|
1862
2149
|
'react-dom/server'
|
|
1863
2150
|
];
|
|
1864
2151
|
const alias = {};
|
|
1865
|
-
const resolver =
|
|
1866
|
-
fileSystem: new detectReactVersion_CachedInputFileSystem(external_node_fs_["default"], 0),
|
|
2152
|
+
const resolver = new Resolver({
|
|
1867
2153
|
extensions: [
|
|
1868
2154
|
'.js'
|
|
1869
2155
|
],
|
|
@@ -1877,14 +2163,9 @@ async function resolveReactAlias(reactVersion, isSSR) {
|
|
|
1877
2163
|
});
|
|
1878
2164
|
await Promise.all(libPaths.map(async (lib)=>{
|
|
1879
2165
|
try {
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
}, basedir, lib, {}, (err, filePath)=>{
|
|
1884
|
-
if (err || !filePath) return reject(err);
|
|
1885
|
-
return resolve(filePath);
|
|
1886
|
-
});
|
|
1887
|
-
});
|
|
2166
|
+
const resolved = await resolver.async(basedir, lib);
|
|
2167
|
+
if (resolved.error || !resolved.path) throw Error(resolved.error);
|
|
2168
|
+
alias[lib] = resolved.path;
|
|
1888
2169
|
} catch (e) {
|
|
1889
2170
|
if (e instanceof Error) {
|
|
1890
2171
|
logger.warn(`${lib} not found: \n ${picocolors.gray(e.toString())}`);
|
|
@@ -1941,6 +2222,7 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1941
2222
|
detectCustomIcon(CUSTOM_THEME_DIR),
|
|
1942
2223
|
resolveReactAlias(reactVersion, false),
|
|
1943
2224
|
enableSSG ? resolveReactAlias(reactVersion, true) : Promise.resolve({}),
|
|
2225
|
+
resolveReactAlias(reactVersion, true),
|
|
1944
2226
|
resolveReactRouterDomAlias()
|
|
1945
2227
|
]);
|
|
1946
2228
|
const context = {
|
|
@@ -1973,13 +2255,17 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1973
2255
|
...siteDataVMPlugin(context)
|
|
1974
2256
|
}
|
|
1975
2257
|
}),
|
|
1976
|
-
enableSSG ? rsbuildPluginSSG({
|
|
2258
|
+
enableSSG && config.ssg ? rsbuildPluginSSG({
|
|
1977
2259
|
routeService,
|
|
1978
2260
|
config
|
|
1979
2261
|
}) : rsbuildPluginCSR({
|
|
1980
2262
|
routeService,
|
|
1981
2263
|
config
|
|
1982
|
-
})
|
|
2264
|
+
}),
|
|
2265
|
+
enableSSG && config.llms ? rsbuildPluginSSGMD({
|
|
2266
|
+
routeService,
|
|
2267
|
+
config
|
|
2268
|
+
}) : null
|
|
1983
2269
|
],
|
|
1984
2270
|
server: {
|
|
1985
2271
|
port: !isProduction() && process.env.PORT ? Number(process.env.PORT) : void 0,
|
|
@@ -2072,8 +2358,9 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
2072
2358
|
}
|
|
2073
2359
|
},
|
|
2074
2360
|
tools: {
|
|
2075
|
-
bundlerChain (chain, { CHAIN_ID,
|
|
2076
|
-
const
|
|
2361
|
+
bundlerChain (chain, { CHAIN_ID, environment }) {
|
|
2362
|
+
const isSsg = 'node' === environment.name;
|
|
2363
|
+
const isSsgMd = 'node_md' === environment.name;
|
|
2077
2364
|
const jsModuleRule = chain.module.rule(CHAIN_ID.RULE.JS);
|
|
2078
2365
|
const swcLoaderOptions = jsModuleRule.use(CHAIN_ID.USE.SWC).get('options');
|
|
2079
2366
|
chain.module.rule('MDX').type("javascript/auto").test(shared_.MDX_OR_MD_REGEXP).resolve.merge({
|
|
@@ -2083,7 +2370,8 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
2083
2370
|
config,
|
|
2084
2371
|
docDirectory: userDocRoot,
|
|
2085
2372
|
routeService,
|
|
2086
|
-
pluginDriver
|
|
2373
|
+
pluginDriver,
|
|
2374
|
+
isSsgMd
|
|
2087
2375
|
}).end();
|
|
2088
2376
|
chain.experiments({
|
|
2089
2377
|
...chain.get('experiments'),
|
|
@@ -2105,10 +2393,14 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
2105
2393
|
chain.module.rule('css-virtual-module').test(/\.rspress[\\/]runtime[\\/]virtual-global-styles/).merge({
|
|
2106
2394
|
sideEffects: true
|
|
2107
2395
|
});
|
|
2108
|
-
if (
|
|
2396
|
+
if (isSsg) {
|
|
2109
2397
|
chain.output.filename(`${NODE_SSG_BUNDLE_FOLDER}/${NODE_SSG_BUNDLE_NAME}`);
|
|
2110
2398
|
chain.output.chunkFilename(`${NODE_SSG_BUNDLE_FOLDER}/[name].cjs`);
|
|
2111
|
-
chain.
|
|
2399
|
+
chain.output.set('asyncChunks', false);
|
|
2400
|
+
} else if (isSsgMd) {
|
|
2401
|
+
chain.output.filename(`${NODE_SSG_MD_BUNDLE_FOLDER}/${NODE_SSG_MD_BUNDLE_NAME}`);
|
|
2402
|
+
chain.output.chunkFilename(`${NODE_SSG_MD_BUNDLE_FOLDER}/[name].cjs`);
|
|
2403
|
+
chain.output.set('asyncChunks', false);
|
|
2112
2404
|
}
|
|
2113
2405
|
}
|
|
2114
2406
|
},
|
|
@@ -2129,7 +2421,8 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
2129
2421
|
'virtual-global-styles'
|
|
2130
2422
|
],
|
|
2131
2423
|
define: {
|
|
2132
|
-
'process.env.__SSR__': JSON.stringify(false)
|
|
2424
|
+
'process.env.__SSR__': JSON.stringify(false),
|
|
2425
|
+
'process.env.__SSR_MD__': JSON.stringify(false)
|
|
2133
2426
|
}
|
|
2134
2427
|
},
|
|
2135
2428
|
output: {
|
|
@@ -2139,7 +2432,7 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
2139
2432
|
}
|
|
2140
2433
|
}
|
|
2141
2434
|
},
|
|
2142
|
-
...enableSSG ? {
|
|
2435
|
+
...enableSSG && config.ssg ? {
|
|
2143
2436
|
node: {
|
|
2144
2437
|
resolve: {
|
|
2145
2438
|
alias: {
|
|
@@ -2152,7 +2445,45 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
2152
2445
|
index: SSR_SERVER_ENTRY
|
|
2153
2446
|
},
|
|
2154
2447
|
define: {
|
|
2155
|
-
'process.env.__SSR__': JSON.stringify(true)
|
|
2448
|
+
'process.env.__SSR__': JSON.stringify(true),
|
|
2449
|
+
'process.env.__SSR_MD__': JSON.stringify(false)
|
|
2450
|
+
}
|
|
2451
|
+
},
|
|
2452
|
+
performance: {
|
|
2453
|
+
printFileSize: {
|
|
2454
|
+
compressed: true
|
|
2455
|
+
}
|
|
2456
|
+
},
|
|
2457
|
+
output: {
|
|
2458
|
+
emitAssets: false,
|
|
2459
|
+
target: 'node',
|
|
2460
|
+
minify: false
|
|
2461
|
+
}
|
|
2462
|
+
}
|
|
2463
|
+
} : {},
|
|
2464
|
+
...enableSSG && config.llms ? {
|
|
2465
|
+
node_md: {
|
|
2466
|
+
resolve: {
|
|
2467
|
+
alias: {
|
|
2468
|
+
...reactSSRAlias,
|
|
2469
|
+
...reactRouterDomAlias
|
|
2470
|
+
}
|
|
2471
|
+
},
|
|
2472
|
+
tools: {
|
|
2473
|
+
rspack: {
|
|
2474
|
+
optimization: {
|
|
2475
|
+
moduleIds: 'named',
|
|
2476
|
+
chunkIds: 'named'
|
|
2477
|
+
}
|
|
2478
|
+
}
|
|
2479
|
+
},
|
|
2480
|
+
source: {
|
|
2481
|
+
entry: {
|
|
2482
|
+
index: SSG_MD_SERVER_ENTRY
|
|
2483
|
+
},
|
|
2484
|
+
define: {
|
|
2485
|
+
'process.env.__SSR__': JSON.stringify(true),
|
|
2486
|
+
'process.env.__SSR_MD__': JSON.stringify(true)
|
|
2156
2487
|
}
|
|
2157
2488
|
},
|
|
2158
2489
|
performance: {
|
|
@@ -2238,7 +2569,13 @@ class PluginDriver {
|
|
|
2238
2569
|
const index = this.#plugins.findIndex((item)=>item.name === pluginName);
|
|
2239
2570
|
if (-1 !== index) this.#plugins.splice(index, 1);
|
|
2240
2571
|
}
|
|
2572
|
+
async normalizeConfig() {
|
|
2573
|
+
this.#config.ssg ??= true;
|
|
2574
|
+
this.#config.llms ??= false;
|
|
2575
|
+
this.#config.base = (0, shared_.addTrailingSlash)((0, shared_.addLeadingSlash)(this.#config.base ?? '/'));
|
|
2576
|
+
}
|
|
2241
2577
|
async modifyConfig() {
|
|
2578
|
+
this.normalizeConfig();
|
|
2242
2579
|
let config = this.#config;
|
|
2243
2580
|
for(let i = 0; i < this.#plugins.length; i++){
|
|
2244
2581
|
const plugin = this.#plugins[i];
|
|
@@ -2382,7 +2719,7 @@ async function build(options) {
|
|
|
2382
2719
|
const { docDirectory, config, configFilePath } = options;
|
|
2383
2720
|
const pluginDriver = await PluginDriver.create(config, configFilePath, true);
|
|
2384
2721
|
const modifiedConfig = await pluginDriver.modifyConfig();
|
|
2385
|
-
const
|
|
2722
|
+
const enableSSG = Boolean((modifiedConfig.ssg || modifiedConfig.llms) ?? true);
|
|
2386
2723
|
const additionalPages = await pluginDriver.addPages();
|
|
2387
2724
|
const routeService = await RouteService.create({
|
|
2388
2725
|
config: modifiedConfig,
|
|
@@ -2394,13 +2731,13 @@ async function build(options) {
|
|
|
2394
2731
|
await modifyConfigWithAutoNavSide(modifiedConfig);
|
|
2395
2732
|
try {
|
|
2396
2733
|
await pluginDriver.beforeBuild();
|
|
2397
|
-
const rsbuild = await initRsbuild(docDirectory, modifiedConfig, pluginDriver, routeService,
|
|
2734
|
+
const rsbuild = await initRsbuild(docDirectory, modifiedConfig, pluginDriver, routeService, enableSSG);
|
|
2398
2735
|
await rsbuild.build();
|
|
2399
2736
|
} finally{
|
|
2400
2737
|
await checkLanguageParity(config);
|
|
2401
2738
|
}
|
|
2402
2739
|
await pluginDriver.afterBuild();
|
|
2403
|
-
if (!
|
|
2740
|
+
if (!enableSSG) hintSSGFalse();
|
|
2404
2741
|
}
|
|
2405
2742
|
async function dev(options) {
|
|
2406
2743
|
const { docDirectory, config, extraBuilderConfig, configFilePath } = options;
|
|
@@ -2484,7 +2821,7 @@ Please use below:
|
|
|
2484
2821
|
});
|
|
2485
2822
|
await Promise.all(promiseList);
|
|
2486
2823
|
};
|
|
2487
|
-
function link_checkDeadLinks(checkDeadLinks, internalLinks,
|
|
2824
|
+
function link_checkDeadLinks(checkDeadLinks, internalLinks, file, lint) {
|
|
2488
2825
|
const errorInfos = [];
|
|
2489
2826
|
const excludes = 'object' == typeof checkDeadLinks ? checkDeadLinks.excludes : void 0;
|
|
2490
2827
|
const excludesUrl = Array.isArray(excludes) ? new Set(excludes) : void 0;
|
|
@@ -2503,9 +2840,13 @@ function link_checkDeadLinks(checkDeadLinks, internalLinks, filePath) {
|
|
|
2503
2840
|
});
|
|
2504
2841
|
if (errorInfos.length > 0) {
|
|
2505
2842
|
if (possibleBreakingChange) hintRelativeMarkdownLink();
|
|
2506
|
-
|
|
2507
|
-
${errorInfos.map(([nodeUrl, link])=>` ${picocolors.green(`"[..](${nodeUrl})"`)} ${picocolors.gray(link)}`).join('\n')}
|
|
2508
|
-
if (
|
|
2843
|
+
const message = `Dead links found${lint ? '' : ` in ${picocolors.cyan(file.path)}`}:
|
|
2844
|
+
${errorInfos.map(([nodeUrl, link])=>` ${picocolors.green(`"[..](${nodeUrl})"`)} ${picocolors.gray(link)}`).join('\n')}`;
|
|
2845
|
+
if (lint) file.message(message);
|
|
2846
|
+
else {
|
|
2847
|
+
logger.error(message);
|
|
2848
|
+
if ((0, shared_.isProduction)()) throw new Error('Dead link found');
|
|
2849
|
+
}
|
|
2509
2850
|
}
|
|
2510
2851
|
}
|
|
2511
2852
|
function looseMarkdownLink(url, routeService, filePath) {
|
|
@@ -2539,20 +2880,25 @@ function normalizeLink(nodeUrl, routeService, filePath, cleanUrls, autoPrefix, d
|
|
|
2539
2880
|
const anotherFileAbsolutePath = external_node_path_["default"].join(external_node_path_["default"].dirname(filePath), url);
|
|
2540
2881
|
url = routeService.absolutePathToRoutePath(anotherFileAbsolutePath);
|
|
2541
2882
|
}
|
|
2542
|
-
if ('boolean' == typeof cleanUrls)
|
|
2543
|
-
|
|
2883
|
+
if ('boolean' == typeof cleanUrls) {
|
|
2884
|
+
url = (0, shared_.normalizeHref)(url, cleanUrls);
|
|
2885
|
+
if (!routeService.isExistRoute(url)) {
|
|
2886
|
+
deadLinks.set(nodeUrl, url);
|
|
2887
|
+
return nodeUrl;
|
|
2888
|
+
}
|
|
2889
|
+
} else {
|
|
2544
2890
|
url = (0, shared_.normalizeHref)(url, false);
|
|
2891
|
+
if (!routeService.isExistRoute(url)) {
|
|
2892
|
+
deadLinks.set(nodeUrl, url);
|
|
2893
|
+
return nodeUrl;
|
|
2894
|
+
}
|
|
2545
2895
|
url = url.replace(/\.html$/, cleanUrls);
|
|
2546
2896
|
}
|
|
2547
|
-
if (!routeService.isExistRoute(url)) {
|
|
2548
|
-
deadLinks.set(nodeUrl, url);
|
|
2549
|
-
return nodeUrl;
|
|
2550
|
-
}
|
|
2551
2897
|
if (hash) url += `#${hash}`;
|
|
2552
2898
|
if (__base) url = (0, shared_.withBase)(url, __base);
|
|
2553
2899
|
return url;
|
|
2554
2900
|
}
|
|
2555
|
-
const remarkLink = ({ cleanUrls, routeService, remarkLinkOptions, __base })=>(tree, file)=>{
|
|
2901
|
+
const remarkLink = ({ cleanUrls, routeService, remarkLinkOptions, lint, __base })=>(tree, file)=>{
|
|
2556
2902
|
const { checkDeadLinks: shouldCheckDeadLinks = true, autoPrefix = true } = remarkLinkOptions ?? {};
|
|
2557
2903
|
const deadLinks = new Map();
|
|
2558
2904
|
visit(tree, 'link', (node)=>{
|
|
@@ -2565,7 +2911,7 @@ const remarkLink = ({ cleanUrls, routeService, remarkLinkOptions, __base })=>(tr
|
|
|
2565
2911
|
const link = normalizeLink(nodeUrl, routeService, file.path, cleanUrls, autoPrefix, deadLinks, __base);
|
|
2566
2912
|
node.url = link;
|
|
2567
2913
|
});
|
|
2568
|
-
if (shouldCheckDeadLinks && routeService) link_checkDeadLinks(shouldCheckDeadLinks, deadLinks, file
|
|
2914
|
+
if (shouldCheckDeadLinks && routeService) link_checkDeadLinks(shouldCheckDeadLinks, deadLinks, file, lint);
|
|
2569
2915
|
};
|
|
2570
2916
|
async function serve(options) {
|
|
2571
2917
|
const { config, port: userPort, host: userHost, configFilePath } = options;
|
|
@@ -2591,4 +2937,4 @@ var __webpack_exports__normalizeHref = shared_.normalizeHref;
|
|
|
2591
2937
|
var __webpack_exports__normalizePosixPath = shared_.normalizePosixPath;
|
|
2592
2938
|
var __webpack_exports__removeTrailingSlash = shared_.removeTrailingSlash;
|
|
2593
2939
|
var __webpack_exports__withBase = shared_.withBase;
|
|
2594
|
-
export { build, defineConfig, dev, getIconUrlPath, getNodeAttribute, logger, matchPath, mergeDocConfig, remarkFileCodeBlock, remarkLink, serve, __webpack_exports__RSPRESS_TEMP_DIR as RSPRESS_TEMP_DIR, __webpack_exports__getSidebarDataGroup as getSidebarDataGroup, __webpack_exports__normalizeHref as normalizeHref, __webpack_exports__normalizePosixPath as normalizePosixPath, __webpack_exports__removeTrailingSlash as removeTrailingSlash, __webpack_exports__withBase as withBase };
|
|
2940
|
+
export { PluginDriver, RouteService, build, defineConfig, dev, getIconUrlPath, getNodeAttribute, logger, matchPath, mergeDocConfig, remarkFileCodeBlock, remarkLink, serve, __webpack_exports__RSPRESS_TEMP_DIR as RSPRESS_TEMP_DIR, __webpack_exports__getSidebarDataGroup as getSidebarDataGroup, __webpack_exports__normalizeHref as normalizeHref, __webpack_exports__normalizePosixPath as normalizePosixPath, __webpack_exports__removeTrailingSlash as removeTrailingSlash, __webpack_exports__withBase as withBase };
|