@rspress/core 1.40.3-cannary-20250126 → 1.41.0
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 +122 -51
- package/dist/index.js.map +1 -1
- package/dist/loader.js +2 -2
- package/dist/loader.js.map +1 -1
- package/package.json +13 -13
package/dist/index.js
CHANGED
|
@@ -66,7 +66,7 @@ var require_package = __commonJS({
|
|
|
66
66
|
"package.json"(exports, module) {
|
|
67
67
|
module.exports = {
|
|
68
68
|
name: "@rspress/core",
|
|
69
|
-
version: "1.
|
|
69
|
+
version: "1.41.0",
|
|
70
70
|
description: "The Rspress Documentation Framework",
|
|
71
71
|
bugs: "https://github.com/web-infra-dev/rspress/issues",
|
|
72
72
|
repository: {
|
|
@@ -124,7 +124,7 @@ var require_package = __commonJS({
|
|
|
124
124
|
"@mdx-js/loader": "2.3.0",
|
|
125
125
|
"@mdx-js/mdx": "2.3.0",
|
|
126
126
|
"@mdx-js/react": "2.3.0",
|
|
127
|
-
"@rsbuild/core": "1.2.
|
|
127
|
+
"@rsbuild/core": "1.2.3",
|
|
128
128
|
"@rsbuild/plugin-less": "~1.1.0",
|
|
129
129
|
"@rsbuild/plugin-react": "~1.1.0",
|
|
130
130
|
"@rsbuild/plugin-sass": "~1.2.0",
|
|
@@ -160,8 +160,8 @@ var require_package = __commonJS({
|
|
|
160
160
|
"unist-util-visit-children": "^3.0.0"
|
|
161
161
|
},
|
|
162
162
|
devDependencies: {
|
|
163
|
-
"@modern-js/plugin-tailwindcss": "2.
|
|
164
|
-
"@modern-js/tsconfig": "2.
|
|
163
|
+
"@modern-js/plugin-tailwindcss": "2.64.0",
|
|
164
|
+
"@modern-js/tsconfig": "2.64.0",
|
|
165
165
|
"@types/hast": "3.0.4",
|
|
166
166
|
"@types/html-to-text": "^9.0.4",
|
|
167
167
|
"@types/jest": "~29.5.14",
|
|
@@ -170,14 +170,14 @@ var require_package = __commonJS({
|
|
|
170
170
|
"@types/node": "^18.11.17",
|
|
171
171
|
"@types/react": "^18.3.18",
|
|
172
172
|
"@types/react-dom": "^18.3.5",
|
|
173
|
-
postcss: "8.
|
|
173
|
+
postcss: "8.5.1",
|
|
174
174
|
"rehype-stringify": "^9.0.4",
|
|
175
175
|
"remark-parse": "^10.0.2",
|
|
176
176
|
"remark-rehype": "^10.1.0",
|
|
177
177
|
rimraf: "^3.0.2",
|
|
178
178
|
tailwindcss: "^3.4.17",
|
|
179
179
|
typescript: "^5.5.3",
|
|
180
|
-
vitest: "2.1.
|
|
180
|
+
vitest: "2.1.9"
|
|
181
181
|
},
|
|
182
182
|
engines: {
|
|
183
183
|
node: ">=14.17.6"
|
|
@@ -382,6 +382,7 @@ _plugins = new WeakMap();
|
|
|
382
382
|
_isProd = new WeakMap();
|
|
383
383
|
|
|
384
384
|
// src/node/initRsbuild.ts
|
|
385
|
+
import fs9 from "fs/promises";
|
|
385
386
|
import path11 from "path";
|
|
386
387
|
import { PLUGIN_LESS_NAME, pluginLess } from "@rsbuild/plugin-less";
|
|
387
388
|
import { PLUGIN_REACT_NAME, pluginReact } from "@rsbuild/plugin-react";
|
|
@@ -393,7 +394,6 @@ import {
|
|
|
393
394
|
removeLeadingSlash as removeLeadingSlash2,
|
|
394
395
|
removeTrailingSlash
|
|
395
396
|
} from "@rspress/shared";
|
|
396
|
-
import fs8 from "@rspress/shared/fs-extra";
|
|
397
397
|
|
|
398
398
|
// src/node/constants.ts
|
|
399
399
|
import path from "path";
|
|
@@ -437,13 +437,13 @@ var TEMP_DIR = path.join(
|
|
|
437
437
|
);
|
|
438
438
|
|
|
439
439
|
// src/node/route/RouteService.ts
|
|
440
|
+
import fs4 from "fs/promises";
|
|
440
441
|
import path5 from "path";
|
|
441
442
|
import {
|
|
442
443
|
addLeadingSlash,
|
|
443
444
|
addTrailingSlash,
|
|
444
445
|
withBase
|
|
445
446
|
} from "@rspress/shared";
|
|
446
|
-
import fs3 from "@rspress/shared/fs-extra";
|
|
447
447
|
import { glob } from "tinyglobby";
|
|
448
448
|
|
|
449
449
|
// src/node/utils/normalizePath.ts
|
|
@@ -471,18 +471,37 @@ function createHash(str) {
|
|
|
471
471
|
}
|
|
472
472
|
|
|
473
473
|
// src/node/utils/detectReactVersion.ts
|
|
474
|
+
import fs2 from "fs";
|
|
474
475
|
import path3 from "path";
|
|
475
|
-
import fs from "@rspress/shared/fs-extra";
|
|
476
476
|
import { logger } from "@rspress/shared/logger";
|
|
477
477
|
import enhancedResolve from "enhanced-resolve";
|
|
478
|
+
|
|
479
|
+
// src/node/utils/fs.ts
|
|
480
|
+
import fs from "fs/promises";
|
|
481
|
+
async function pathExists(path13) {
|
|
482
|
+
try {
|
|
483
|
+
await fs.access(path13);
|
|
484
|
+
return true;
|
|
485
|
+
} catch {
|
|
486
|
+
return false;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
async function readJson(path13) {
|
|
490
|
+
const raw = await fs.readFile(path13, "utf8");
|
|
491
|
+
return JSON.parse(raw);
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
// src/node/utils/detectReactVersion.ts
|
|
478
495
|
var { CachedInputFileSystem, ResolverFactory } = enhancedResolve;
|
|
479
496
|
var DEFAULT_REACT_VERSION = 18;
|
|
480
497
|
async function detectReactVersion() {
|
|
481
498
|
const cwd = process.cwd();
|
|
482
499
|
const reactPath = path3.join(cwd, "node_modules", "react");
|
|
483
|
-
if (await
|
|
484
|
-
const reactPkg = await
|
|
485
|
-
|
|
500
|
+
if (await pathExists(reactPath)) {
|
|
501
|
+
const reactPkg = await readJson(
|
|
502
|
+
path3.join(reactPath, "package.json")
|
|
503
|
+
);
|
|
504
|
+
const version = Number(reactPkg.version?.split(".")[0]);
|
|
486
505
|
return version;
|
|
487
506
|
}
|
|
488
507
|
return DEFAULT_REACT_VERSION;
|
|
@@ -501,7 +520,7 @@ async function resolveReactAlias(reactVersion, isSSR) {
|
|
|
501
520
|
}
|
|
502
521
|
const alias = {};
|
|
503
522
|
const resolver2 = ResolverFactory.createResolver({
|
|
504
|
-
fileSystem: new CachedInputFileSystem(
|
|
523
|
+
fileSystem: new CachedInputFileSystem(fs2, 0),
|
|
505
524
|
extensions: [".js"],
|
|
506
525
|
alias,
|
|
507
526
|
conditionNames: isSSR ? ["..."] : ["browser", "..."]
|
|
@@ -533,10 +552,10 @@ async function resolveReactAlias(reactVersion, isSSR) {
|
|
|
533
552
|
}
|
|
534
553
|
|
|
535
554
|
// src/node/utils/flattenMdxContent.ts
|
|
555
|
+
import fs3 from "fs";
|
|
536
556
|
import path4 from "path";
|
|
537
557
|
import { createProcessor } from "@mdx-js/mdx";
|
|
538
558
|
import { MDX_REGEXP } from "@rspress/shared";
|
|
539
|
-
import fs2 from "@rspress/shared/fs-extra";
|
|
540
559
|
import enhancedResolve2 from "enhanced-resolve";
|
|
541
560
|
var resolver;
|
|
542
561
|
var startFlatten = false;
|
|
@@ -545,7 +564,7 @@ var { CachedInputFileSystem: CachedInputFileSystem2, ResolverFactory: ResolverFa
|
|
|
545
564
|
async function resolveDepPath(importPath, importer, alias) {
|
|
546
565
|
if (!resolver) {
|
|
547
566
|
resolver = ResolverFactory2.createResolver({
|
|
548
|
-
fileSystem: new CachedInputFileSystem2(
|
|
567
|
+
fileSystem: new CachedInputFileSystem2(fs3, 0),
|
|
549
568
|
extensions: [".mdx", ".md"],
|
|
550
569
|
alias
|
|
551
570
|
});
|
|
@@ -583,7 +602,7 @@ async function flattenMdxContent(content, basePath, alias) {
|
|
|
583
602
|
}
|
|
584
603
|
if (!startFlatten) {
|
|
585
604
|
resolver = ResolverFactory2.createResolver({
|
|
586
|
-
fileSystem: new CachedInputFileSystem2(
|
|
605
|
+
fileSystem: new CachedInputFileSystem2(fs3, 0),
|
|
587
606
|
extensions: [".mdx", ".md", ".js"],
|
|
588
607
|
alias
|
|
589
608
|
});
|
|
@@ -611,7 +630,7 @@ async function flattenMdxContent(content, basePath, alias) {
|
|
|
611
630
|
continue;
|
|
612
631
|
}
|
|
613
632
|
if (MDX_REGEXP.test(absoluteImportPath)) {
|
|
614
|
-
const importedContent =
|
|
633
|
+
const importedContent = fs3.readFileSync(absoluteImportPath, "utf-8");
|
|
615
634
|
const { flattenContent: replacedValue, deps: subDeps } = await flattenMdxContent(importedContent, absoluteImportPath, alias);
|
|
616
635
|
result = result.replace(
|
|
617
636
|
new RegExp(`import\\s+${id}\\s+from\\s+['"](${importPath})['"];?`),
|
|
@@ -828,7 +847,7 @@ _pluginDriver = new WeakMap();
|
|
|
828
847
|
_writeTempFile = new WeakSet();
|
|
829
848
|
writeTempFile_fn = async function(index, content) {
|
|
830
849
|
const tempFilePath = path5.join(__privateGet(this, _tempDir), `temp-${index}.mdx`);
|
|
831
|
-
await
|
|
850
|
+
await fs4.writeFile(tempFilePath, content);
|
|
832
851
|
return tempFilePath;
|
|
833
852
|
};
|
|
834
853
|
_generateRouteInfo = new WeakSet();
|
|
@@ -866,15 +885,15 @@ async function initRouteService(options) {
|
|
|
866
885
|
import { RspackVirtualModulePlugin } from "rspack-plugin-virtual-module";
|
|
867
886
|
|
|
868
887
|
// src/node/runtimeModule/globalStyles.ts
|
|
869
|
-
import
|
|
888
|
+
import fs5 from "fs/promises";
|
|
870
889
|
async function globalStylesVMPlugin(context) {
|
|
871
890
|
const { config, pluginDriver } = context;
|
|
872
891
|
const globalStylesByPlugins = pluginDriver.globalStyles();
|
|
873
892
|
if (config.globalStyles) {
|
|
874
893
|
const source = config.globalStyles;
|
|
875
|
-
const styleContent = await
|
|
894
|
+
const styleContent = await fs5.readFile(source, "utf-8");
|
|
876
895
|
const patchedStyleContent = styleContent.replace(/--modern-/g, "--rp-").replace(/\.modern-doc/g, ".rspress").replace(/\.modern-/g, ".rspress-");
|
|
877
|
-
await
|
|
896
|
+
await fs5.writeFile(source, patchedStyleContent, "utf-8");
|
|
878
897
|
}
|
|
879
898
|
const moduleContent = (await Promise.all(
|
|
880
899
|
[config?.globalStyles || "", ...globalStylesByPlugins].filter((source) => source.length > 0).map(async (source) => {
|
|
@@ -969,18 +988,18 @@ async function searchHookVMPlugin(context) {
|
|
|
969
988
|
}
|
|
970
989
|
|
|
971
990
|
// src/node/runtimeModule/siteData/index.ts
|
|
991
|
+
import fs7 from "fs/promises";
|
|
972
992
|
import path8 from "path";
|
|
973
993
|
import { SEARCH_INDEX_NAME } from "@rspress/shared";
|
|
974
|
-
import fs6 from "@rspress/shared/fs-extra";
|
|
975
994
|
import { groupBy } from "lodash-es";
|
|
976
995
|
|
|
977
996
|
// src/node/runtimeModule/siteData/extractPageData.ts
|
|
997
|
+
import fs6 from "fs/promises";
|
|
978
998
|
import path7 from "path";
|
|
979
999
|
import { compile } from "@rspress/mdx-rs";
|
|
980
1000
|
import {
|
|
981
1001
|
MDX_REGEXP as MDX_REGEXP2
|
|
982
1002
|
} from "@rspress/shared";
|
|
983
|
-
import fs5 from "@rspress/shared/fs-extra";
|
|
984
1003
|
import { loadFrontMatter } from "@rspress/shared/node-utils";
|
|
985
1004
|
import { htmlToText } from "html-to-text";
|
|
986
1005
|
function applyReplaceRulesToNestedObject(obj, replaceRules) {
|
|
@@ -993,7 +1012,7 @@ function applyReplaceRulesToNestedObject(obj, replaceRules) {
|
|
|
993
1012
|
}
|
|
994
1013
|
return obj;
|
|
995
1014
|
}
|
|
996
|
-
async function extractPageData(replaceRules, alias, domain, root, routeService2, highlighterLangs) {
|
|
1015
|
+
async function extractPageData(replaceRules, alias, domain, root, routeService2, highlighterLangs, searchCodeBlocks) {
|
|
997
1016
|
const pageData = await Promise.all(
|
|
998
1017
|
routeService2.getRoutes().map(async (route, index) => {
|
|
999
1018
|
const defaultIndexInfo = {
|
|
@@ -1013,7 +1032,7 @@ async function extractPageData(replaceRules, alias, domain, root, routeService2,
|
|
|
1013
1032
|
if (!MDX_REGEXP2.test(route.absolutePath)) {
|
|
1014
1033
|
return defaultIndexInfo;
|
|
1015
1034
|
}
|
|
1016
|
-
let content = await
|
|
1035
|
+
let content = await fs6.readFile(route.absolutePath, "utf8");
|
|
1017
1036
|
const { frontmatter, content: strippedFrontMatter } = loadFrontMatter(
|
|
1018
1037
|
content,
|
|
1019
1038
|
route.absolutePath,
|
|
@@ -1056,7 +1075,7 @@ async function extractPageData(replaceRules, alias, domain, root, routeService2,
|
|
|
1056
1075
|
{
|
|
1057
1076
|
// Skip code blocks
|
|
1058
1077
|
selector: "pre > code",
|
|
1059
|
-
format: "skip"
|
|
1078
|
+
format: searchCodeBlocks ? "block" : "skip"
|
|
1060
1079
|
},
|
|
1061
1080
|
...["h1", "h2", "h3", "h4", "h5", "h6"].map((tag) => ({
|
|
1062
1081
|
selector: tag,
|
|
@@ -1345,14 +1364,17 @@ async function siteDataVMPlugin(context) {
|
|
|
1345
1364
|
}
|
|
1346
1365
|
const highlightLanguages = /* @__PURE__ */ new Set();
|
|
1347
1366
|
const replaceRules = userConfig?.replaceRules || [];
|
|
1348
|
-
const
|
|
1367
|
+
const searchConfig = userConfig?.search || {};
|
|
1368
|
+
const domain = searchConfig?.mode === "remote" ? searchConfig.domain ?? "" : "";
|
|
1369
|
+
const searchCodeBlocks = "codeBlocks" in searchConfig ? searchConfig.codeBlocks : false;
|
|
1349
1370
|
const pages = await extractPageData(
|
|
1350
1371
|
replaceRules,
|
|
1351
1372
|
alias,
|
|
1352
1373
|
domain,
|
|
1353
1374
|
userDocRoot,
|
|
1354
1375
|
routeService2,
|
|
1355
|
-
highlightLanguages
|
|
1376
|
+
highlightLanguages,
|
|
1377
|
+
searchCodeBlocks
|
|
1356
1378
|
);
|
|
1357
1379
|
await pluginDriver.modifySearchIndexData(pages);
|
|
1358
1380
|
const versioned = userConfig.search && userConfig.search.mode !== "remote" && userConfig.search.versioned;
|
|
@@ -1376,8 +1398,8 @@ async function siteDataVMPlugin(context) {
|
|
|
1376
1398
|
const [version, lang] = group.split("###");
|
|
1377
1399
|
const indexVersion = version ? `.${version.replace(".", "_")}` : "";
|
|
1378
1400
|
const indexLang = lang ? `.${lang}` : "";
|
|
1379
|
-
await
|
|
1380
|
-
await
|
|
1401
|
+
await fs7.mkdir(TEMP_DIR, { recursive: true });
|
|
1402
|
+
await fs7.writeFile(
|
|
1381
1403
|
path8.join(
|
|
1382
1404
|
TEMP_DIR,
|
|
1383
1405
|
`${SEARCH_INDEX_NAME}${indexVersion}${indexLang}.${indexHash}.json`
|
|
@@ -1520,18 +1542,21 @@ function rsbuildPluginDocVM(factoryContext) {
|
|
|
1520
1542
|
}
|
|
1521
1543
|
|
|
1522
1544
|
// src/node/searchIndex.ts
|
|
1545
|
+
import { createReadStream } from "fs";
|
|
1546
|
+
import fs8 from "fs/promises";
|
|
1523
1547
|
import path9, { join as join2 } from "path";
|
|
1524
1548
|
import { SEARCH_INDEX_NAME as SEARCH_INDEX_NAME2, isSCM } from "@rspress/shared";
|
|
1525
1549
|
import chalk2 from "@rspress/shared/chalk";
|
|
1526
|
-
import fs7 from "@rspress/shared/fs-extra";
|
|
1527
1550
|
import { logger as logger2 } from "@rspress/shared/logger";
|
|
1528
1551
|
async function writeSearchIndex(config) {
|
|
1529
1552
|
if (config?.search === false) {
|
|
1530
1553
|
return;
|
|
1531
1554
|
}
|
|
1532
1555
|
const cwd = process.cwd();
|
|
1533
|
-
const searchIndexFiles = await
|
|
1556
|
+
const searchIndexFiles = await fs8.readdir(TEMP_DIR);
|
|
1534
1557
|
const outDir = config?.outDir ?? join2(cwd, OUTPUT_DIR);
|
|
1558
|
+
const targetDir = join2(outDir, "static");
|
|
1559
|
+
await fs8.mkdir(targetDir, { recursive: true });
|
|
1535
1560
|
let searchIndexData = "[]";
|
|
1536
1561
|
let scanning = false;
|
|
1537
1562
|
for (const searchIndexFile of searchIndexFiles) {
|
|
@@ -1539,13 +1564,13 @@ async function writeSearchIndex(config) {
|
|
|
1539
1564
|
continue;
|
|
1540
1565
|
}
|
|
1541
1566
|
const source = join2(TEMP_DIR, searchIndexFile);
|
|
1542
|
-
const target = join2(
|
|
1543
|
-
const searchIndex = await
|
|
1567
|
+
const target = join2(targetDir, searchIndexFile);
|
|
1568
|
+
const searchIndex = await fs8.readFile(
|
|
1544
1569
|
join2(TEMP_DIR, searchIndexFile),
|
|
1545
1570
|
"utf-8"
|
|
1546
1571
|
);
|
|
1547
1572
|
searchIndexData = `${searchIndexData.slice(0, -1)}${scanning ? "," : ""}${searchIndex.slice(1)}`;
|
|
1548
|
-
await
|
|
1573
|
+
await fs8.rename(source, target);
|
|
1549
1574
|
scanning = true;
|
|
1550
1575
|
}
|
|
1551
1576
|
if (isProduction() && isSCM() && config?.search?.mode === "remote") {
|
|
@@ -1577,7 +1602,7 @@ function serveSearchIndexMiddleware(config) {
|
|
|
1577
1602
|
if (req.url?.includes(searchIndexRequestMatch)) {
|
|
1578
1603
|
res.setHeader("Content-Type", "application/json");
|
|
1579
1604
|
const searchIndexFile = req.url?.split("/").pop();
|
|
1580
|
-
|
|
1605
|
+
createReadStream(
|
|
1581
1606
|
path9.join(
|
|
1582
1607
|
process.cwd(),
|
|
1583
1608
|
config?.outDir || OUTPUT_DIR,
|
|
@@ -1612,6 +1637,45 @@ var detectCustomIcon = async (customThemeDir) => {
|
|
|
1612
1637
|
return alias;
|
|
1613
1638
|
};
|
|
1614
1639
|
|
|
1640
|
+
// src/node/utils/getSocialIcons.ts
|
|
1641
|
+
var presetIcons = {
|
|
1642
|
+
discord: `<path fill="currentColor" d="M20.317 4.37a19.8 19.8 0 0 0-4.885-1.515a.074.074 0 0 0-.079.037c-.21.375-.444.864-.608 1.25a18.3 18.3 0 0 0-5.487 0a13 13 0 0 0-.617-1.25a.08.08 0 0 0-.079-.037A19.7 19.7 0 0 0 3.677 4.37a.1.1 0 0 0-.032.027C.533 9.046-.32 13.58.099 18.057a.08.08 0 0 0 .031.057a19.9 19.9 0 0 0 5.993 3.03a.08.08 0 0 0 .084-.028a14 14 0 0 0 1.226-1.994a.076.076 0 0 0-.041-.106a13 13 0 0 1-1.872-.892a.077.077 0 0 1-.008-.128a10 10 0 0 0 .372-.292a.07.07 0 0 1 .077-.01c3.928 1.793 8.18 1.793 12.062 0a.07.07 0 0 1 .078.01q.181.149.373.292a.077.077 0 0 1-.006.127a12.3 12.3 0 0 1-1.873.892a.077.077 0 0 0-.041.107c.36.698.772 1.362 1.225 1.993a.08.08 0 0 0 .084.028a19.8 19.8 0 0 0 6.002-3.03a.08.08 0 0 0 .032-.054c.5-5.177-.838-9.674-3.549-13.66a.06.06 0 0 0-.031-.03M8.02 15.33c-1.182 0-2.157-1.085-2.157-2.419c0-1.333.956-2.419 2.157-2.419c1.21 0 2.176 1.096 2.157 2.42c0 1.333-.956 2.418-2.157 2.418m7.975 0c-1.183 0-2.157-1.085-2.157-2.419c0-1.333.955-2.419 2.157-2.419c1.21 0 2.176 1.096 2.157 2.42c0 1.333-.946 2.418-2.157 2.418"/>`,
|
|
1643
|
+
facebook: `<path fill="currentColor" d="M9.101 23.691v-7.98H6.627v-3.667h2.474v-1.58c0-4.085 1.848-5.978 5.858-5.978c.401 0 .955.042 1.468.103a9 9 0 0 1 1.141.195v3.325a9 9 0 0 0-.653-.036a27 27 0 0 0-.733-.009c-.707 0-1.259.096-1.675.309a1.7 1.7 0 0 0-.679.622c-.258.42-.374.995-.374 1.752v1.297h3.919l-.386 2.103l-.287 1.564h-3.246v8.245C19.396 23.238 24 18.179 24 12.044c0-6.627-5.373-12-12-12s-12 5.373-12 12c0 5.628 3.874 10.35 9.101 11.647"/>`,
|
|
1644
|
+
github: `<path fill="currentColor" d="M12 .297c-6.63 0-12 5.373-12 12c0 5.303 3.438 9.8 8.205 11.385c.6.113.82-.258.82-.577c0-.285-.01-1.04-.015-2.04c-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729c1.205.084 1.838 1.236 1.838 1.236c1.07 1.835 2.809 1.305 3.495.998c.108-.776.417-1.305.76-1.605c-2.665-.3-5.466-1.332-5.466-5.93c0-1.31.465-2.38 1.235-3.22c-.135-.303-.54-1.523.105-3.176c0 0 1.005-.322 3.3 1.23c.96-.267 1.98-.399 3-.405c1.02.006 2.04.138 3 .405c2.28-1.552 3.285-1.23 3.285-1.23c.645 1.653.24 2.873.12 3.176c.765.84 1.23 1.91 1.23 3.22c0 4.61-2.805 5.625-5.475 5.92c.42.36.81 1.096.81 2.22c0 1.606-.015 2.896-.015 3.286c0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"/>`,
|
|
1645
|
+
gitlab: `<path fill="currentColor" d="m23.6 9.593l-.033-.086L20.3.98a.85.85 0 0 0-.336-.405a.875.875 0 0 0-1 .054a.9.9 0 0 0-.29.44L16.47 7.818H7.537L5.333 1.07a.86.86 0 0 0-.29-.441a.875.875 0 0 0-1-.054a.86.86 0 0 0-.336.405L.433 9.502l-.032.086a6.066 6.066 0 0 0 2.012 7.01l.01.009l.03.021l4.977 3.727l2.462 1.863l1.5 1.132a1.01 1.01 0 0 0 1.22 0l1.499-1.132l2.461-1.863l5.006-3.75l.013-.01a6.07 6.07 0 0 0 2.01-7.002"/>`,
|
|
1646
|
+
instagram: `<path fill="currentColor" d="M7.03.084c-1.277.06-2.149.264-2.91.563a5.9 5.9 0 0 0-2.124 1.388a5.9 5.9 0 0 0-1.38 2.127C.321 4.926.12 5.8.064 7.076s-.069 1.688-.063 4.947s.021 3.667.083 4.947c.061 1.277.264 2.149.563 2.911c.308.789.72 1.457 1.388 2.123a5.9 5.9 0 0 0 2.129 1.38c.763.295 1.636.496 2.913.552c1.278.056 1.689.069 4.947.063s3.668-.021 4.947-.082c1.28-.06 2.147-.265 2.91-.563a5.9 5.9 0 0 0 2.123-1.388a5.9 5.9 0 0 0 1.38-2.129c.295-.763.496-1.636.551-2.912c.056-1.28.07-1.69.063-4.948c-.006-3.258-.02-3.667-.081-4.947c-.06-1.28-.264-2.148-.564-2.911a5.9 5.9 0 0 0-1.387-2.123a5.9 5.9 0 0 0-2.128-1.38c-.764-.294-1.636-.496-2.914-.55C15.647.009 15.236-.006 11.977 0S8.31.021 7.03.084m.14 21.693c-1.17-.05-1.805-.245-2.228-.408a3.7 3.7 0 0 1-1.382-.895a3.7 3.7 0 0 1-.9-1.378c-.165-.423-.363-1.058-.417-2.228c-.06-1.264-.072-1.644-.08-4.848c-.006-3.204.006-3.583.061-4.848c.05-1.169.246-1.805.408-2.228c.216-.561.477-.96.895-1.382a3.7 3.7 0 0 1 1.379-.9c.423-.165 1.057-.361 2.227-.417c1.265-.06 1.644-.072 4.848-.08c3.203-.006 3.583.006 4.85.062c1.168.05 1.804.244 2.227.408c.56.216.96.475 1.382.895s.681.817.9 1.378c.165.422.362 1.056.417 2.227c.06 1.265.074 1.645.08 4.848c.005 3.203-.006 3.583-.061 4.848c-.051 1.17-.245 1.805-.408 2.23c-.216.56-.477.96-.896 1.38a3.7 3.7 0 0 1-1.378.9c-.422.165-1.058.362-2.226.418c-1.266.06-1.645.072-4.85.079s-3.582-.006-4.848-.06m9.783-16.192a1.44 1.44 0 1 0 1.437-1.442a1.44 1.44 0 0 0-1.437 1.442M5.839 12.012a6.161 6.161 0 1 0 12.323-.024a6.162 6.162 0 0 0-12.323.024M8 12.008A4 4 0 1 1 12.008 16A4 4 0 0 1 8 12.008"/>`,
|
|
1647
|
+
linkedin: `<path fill="currentColor" d="M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037c-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85c3.601 0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433a2.06 2.06 0 0 1-2.063-2.065a2.064 2.064 0 1 1 2.063 2.065m1.782 13.019H3.555V9h3.564zM22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.222 0z"/>`,
|
|
1648
|
+
slack: `<path fill="currentColor" d="M5.042 15.165a2.53 2.53 0 0 1-2.52 2.523A2.53 2.53 0 0 1 0 15.165a2.527 2.527 0 0 1 2.522-2.52h2.52zm1.271 0a2.527 2.527 0 0 1 2.521-2.52a2.527 2.527 0 0 1 2.521 2.52v6.313A2.53 2.53 0 0 1 8.834 24a2.53 2.53 0 0 1-2.521-2.522zM8.834 5.042a2.53 2.53 0 0 1-2.521-2.52A2.53 2.53 0 0 1 8.834 0a2.53 2.53 0 0 1 2.521 2.522v2.52zm0 1.271a2.53 2.53 0 0 1 2.521 2.521a2.53 2.53 0 0 1-2.521 2.521H2.522A2.53 2.53 0 0 1 0 8.834a2.53 2.53 0 0 1 2.522-2.521zm10.122 2.521a2.53 2.53 0 0 1 2.522-2.521A2.53 2.53 0 0 1 24 8.834a2.53 2.53 0 0 1-2.522 2.521h-2.522zm-1.268 0a2.53 2.53 0 0 1-2.523 2.521a2.527 2.527 0 0 1-2.52-2.521V2.522A2.527 2.527 0 0 1 15.165 0a2.53 2.53 0 0 1 2.523 2.522zm-2.523 10.122a2.53 2.53 0 0 1 2.523 2.522A2.53 2.53 0 0 1 15.165 24a2.527 2.527 0 0 1-2.52-2.522v-2.522zm0-1.268a2.527 2.527 0 0 1-2.52-2.523a2.526 2.526 0 0 1 2.52-2.52h6.313A2.527 2.527 0 0 1 24 15.165a2.53 2.53 0 0 1-2.522 2.523z"/>`,
|
|
1649
|
+
youtube: `<path fill="currentColor" d="M23.498 6.186a3.02 3.02 0 0 0-2.122-2.136C19.505 3.545 12 3.545 12 3.545s-7.505 0-9.377.505A3.02 3.02 0 0 0 .502 6.186C0 8.07 0 12 0 12s0 3.93.502 5.814a3.02 3.02 0 0 0 2.122 2.136c1.871.505 9.376.505 9.376.505s7.505 0 9.377-.505a3.02 3.02 0 0 0 2.122-2.136C24 15.93 24 12 24 12s0-3.93-.502-5.814M9.545 15.568V8.432L15.818 12z"/>`,
|
|
1650
|
+
juejin: `<path fill="currentColor" d="m12 14.316l7.454-5.88l-2.022-1.625L12 11.1l-.004.003l-5.432-4.288l-2.02 1.624l7.452 5.88Zm0-7.247l2.89-2.298L12 2.453l-.004-.005l-2.884 2.318l2.884 2.3Zm0 11.266l-.005.002l-9.975-7.87L0 12.088l.194.156l11.803 9.308l7.463-5.885L24 12.085l-2.023-1.624Z"/>`,
|
|
1651
|
+
qq: `<path fill="currentColor" d="M21.395 15.035a40 40 0 0 0-.803-2.264l-1.079-2.695c.001-.032.014-.562.014-.836C19.526 4.632 17.351 0 12 0S4.474 4.632 4.474 9.241c0 .274.013.804.014.836l-1.08 2.695a39 39 0 0 0-.802 2.264c-1.021 3.283-.69 4.643-.438 4.673c.54.065 2.103-2.472 2.103-2.472c0 1.469.756 3.387 2.394 4.771c-.612.188-1.363.479-1.845.835c-.434.32-.379.646-.301.778c.343.578 5.883.369 7.482.189c1.6.18 7.14.389 7.483-.189c.078-.132.132-.458-.301-.778c-.483-.356-1.233-.646-1.846-.836c1.637-1.384 2.393-3.302 2.393-4.771c0 0 1.563 2.537 2.103 2.472c.251-.03.581-1.39-.438-4.673"/>`,
|
|
1652
|
+
wechat: `<path fill="currentColor" d="M8.691 2.188C3.891 2.188 0 5.476 0 9.53c0 2.212 1.17 4.203 3.002 5.55a.59.59 0 0 1 .213.665l-.39 1.48c-.019.07-.048.141-.048.213c0 .163.13.295.29.295a.33.33 0 0 0 .167-.054l1.903-1.114a.86.86 0 0 1 .717-.098a10.2 10.2 0 0 0 2.837.403c.276 0 .543-.027.811-.05c-.857-2.578.157-4.972 1.932-6.446c1.703-1.415 3.882-1.98 5.853-1.838c-.576-3.583-4.196-6.348-8.596-6.348M5.785 5.991c.642 0 1.162.529 1.162 1.18a1.17 1.17 0 0 1-1.162 1.178A1.17 1.17 0 0 1 4.623 7.17c0-.651.52-1.18 1.162-1.18zm5.813 0c.642 0 1.162.529 1.162 1.18a1.17 1.17 0 0 1-1.162 1.178a1.17 1.17 0 0 1-1.162-1.178c0-.651.52-1.18 1.162-1.18m5.34 2.867c-1.797-.052-3.746.512-5.28 1.786c-1.72 1.428-2.687 3.72-1.78 6.22c.942 2.453 3.666 4.229 6.884 4.229c.826 0 1.622-.12 2.361-.336a.72.72 0 0 1 .598.082l1.584.926a.3.3 0 0 0 .14.047c.134 0 .24-.111.24-.247c0-.06-.023-.12-.038-.177l-.327-1.233a.6.6 0 0 1-.023-.156a.49.49 0 0 1 .201-.398C23.024 18.48 24 16.82 24 14.98c0-3.21-2.931-5.837-6.656-6.088V8.89c-.135-.01-.27-.027-.407-.03zm-2.53 3.274c.535 0 .969.44.969.982a.976.976 0 0 1-.969.983a.976.976 0 0 1-.969-.983c0-.542.434-.982.97-.982zm4.844 0c.535 0 .969.44.969.982a.976.976 0 0 1-.969.983a.976.976 0 0 1-.969-.983c0-.542.434-.982.969-.982"/>`,
|
|
1653
|
+
weibo: `<path fill="currentColor" d="M17.525 11.378c1.263.392 2.669 1.336 2.669 3.004c0 2.763-3.98 6.239-9.964 6.239c-4.565 0-9.23-2.213-9.23-5.852c0-1.902 1.204-4.102 3.277-6.177c2.773-2.77 6.004-4.033 7.219-2.816c.537.537.588 1.464.244 2.572c-.178.557.525.25.525.25c2.24-.938 4.196-.994 4.909.027c.38.543.343 1.306-.008 2.19c-.163.407.048.471.36.563zm-7.282 7.939c3.641-.362 6.401-2.592 6.167-4.983c-.237-2.391-3.382-4.038-7.023-3.677c-3.64.36-6.403 2.59-6.167 4.98c.237 2.394 3.382 4.039 7.023 3.68zM6.16 14.438c.754-1.527 2.712-2.39 4.446-1.94c1.793.463 2.707 2.154 1.976 3.8c-.744 1.682-2.882 2.578-4.695 1.993c-1.752-.566-2.493-2.294-1.727-3.853zm1.446 2.587c.568.257 1.325.013 1.676-.55c.346-.568.163-1.217-.407-1.459c-.563-.237-1.291.008-1.64.553c-.354.547-.189 1.202.371 1.456zm2.206-1.808c.219.092.501-.012.628-.231c.123-.22.044-.466-.178-.548c-.216-.084-.486.018-.613.232c-.123.214-.054.458.163.547zM19.873 9.5a.725.725 0 1 1-1.378-.451a1.38 1.38 0 0 0-.288-1.357a1.395 1.395 0 0 0-1.321-.425a.723.723 0 1 1-.303-1.416a2.836 2.836 0 0 1 3.29 3.649zm-3.916-6.575A5.831 5.831 0 0 1 21.5 4.72a5.836 5.836 0 0 1 1.22 5.704a.838.838 0 0 1-1.06.54a.844.844 0 0 1-.542-1.062a4.143 4.143 0 0 0-4.807-5.327a.845.845 0 0 1-.354-1.65z"/>`,
|
|
1654
|
+
zhihu: `<path fill="currentColor" d="M5.721 0C2.251 0 0 2.25 0 5.719V18.28C0 21.751 2.252 24 5.721 24h12.56C21.751 24 24 21.75 24 18.281V5.72C24 2.249 21.75 0 18.281 0zm1.964 4.078q-.408 1.096-.68 2.11h4.587c.545-.006.445 1.168.445 1.171H9.384a58 58 0 0 1-.112 3.797h2.712c.388.023.393 1.251.393 1.266H9.183a9.2 9.2 0 0 1-.408 2.102l.757-.604c.452.456 1.512 1.712 1.906 2.177c.473.681.063 2.081.063 2.081l-2.794-3.382c-.653 2.518-1.845 3.607-1.845 3.607c-.523.468-1.58.82-2.64.516c2.218-1.73 3.44-3.917 3.667-6.497H4.491c0-.015.197-1.243.806-1.266h2.71c.024-.32.086-3.254.086-3.797H6.598c-.136.406-.158.447-.268.753c-.594 1.095-1.603 1.122-1.907 1.155c.906-1.821 1.416-3.6 1.591-4.064c.425-1.124 1.671-1.125 1.671-1.125M13.078 6h6.377v11.33h-2.573l-2.184 1.373l-.401-1.373h-1.219zm1.313 1.219v8.86h.623l.263.937l1.455-.938h1.456v-8.86z"/>`,
|
|
1655
|
+
bilibili: `<path fill="currentColor" d="M17.813 4.653h.854q2.266.08 3.773 1.574Q23.946 7.72 24 9.987v7.36q-.054 2.266-1.56 3.773c-1.506 1.507-2.262 1.524-3.773 1.56H5.333q-2.266-.054-3.773-1.56C.053 19.614.036 18.858 0 17.347v-7.36q.054-2.267 1.56-3.76t3.773-1.574h.774l-1.174-1.12a1.23 1.23 0 0 1-.373-.906q0-.534.373-.907l.027-.027q.4-.373.92-.373t.92.373L9.653 4.44q.107.106.187.213h4.267a.8.8 0 0 1 .16-.213l2.853-2.747q.4-.373.92-.373c.347 0 .662.151.929.4s.391.551.391.907q0 .532-.373.906zM5.333 7.24q-1.12.027-1.88.773q-.76.748-.786 1.894v7.52q.026 1.146.786 1.893t1.88.773h13.334q1.12-.026 1.88-.773t.786-1.893v-7.52q-.026-1.147-.786-1.894t-1.88-.773zM8 11.107q.56 0 .933.373q.375.374.4.96v1.173q-.025.586-.4.96q-.373.375-.933.374c-.56-.001-.684-.125-.933-.374q-.375-.373-.4-.96V12.44q0-.56.386-.947q.387-.386.947-.386m8 0q.56 0 .933.373q.375.374.4.96v1.173q-.025.586-.4.96q-.373.375-.933.374c-.56-.001-.684-.125-.933-.374q-.375-.373-.4-.96V12.44q.025-.586.4-.96q.373-.373.933-.373"/>`,
|
|
1656
|
+
lark: `<path d="M8.813 5.477c1.038.836 2.286 2.045 3.3 3.495.171.23.377.576.457.71l.034.056a8.803 8.803 0 0 0-.922 1.3l-.271-.494C9.655 7.53 6.3 5.477 6.137 5.377a.447.447 0 0 1-.006-.004l-.666-.393-.107-.086a.499.499 0 0 1 .306-.885L6.084 4h7.997c.159.006.318.037.47.092.174.064.317.174.458.308.134.143.272.296.403.448.622.675 1.324 1.688 1.324 1.688-.573.193-1.349.736-1.349.736a5.095 5.095 0 0 0-.348-.54 20.665 20.665 0 0 0-1.037-1.255H8.813Z" fill="currentColor"/>
|
|
1657
|
+
<path d="M18.482 7.507a5.42 5.42 0 0 1 4.04.717c.248.168.788.635.242 1.233-1.7 1.67-2.194 3.225-2.63 4.599-.278.873-.541 1.697-1.066 2.424-1.813 2.508-4.114 4-6.837 4.434-.561.089-1.132.131-1.7.131-3.958 0-7.498-2.035-8.75-2.844h.003l-.161-.107c-.534-.378-.61-.723-.623-.989V7.055a.486.486 0 0 1 .827-.317l.482.589c5.082 6.201 9.126 8.063 11.626 8.53 2.246.424 3.631-.165 4.022-.37.333-.51.534-1.143.764-1.865l.006-.021c.406-1.276.898-2.821 2.322-4.477a3.93 3.93 0 0 0-2.28-.168c-1.761.394-3.403 1.96-4.89 4.643a8.27 8.27 0 0 0-.341.671c-.724-.107-1.334-.65-1.334-.65.128-.269.22-.455.345-.672 1.718-3.125 3.714-4.962 5.933-5.441ZM2.477 16.889c1.145.744 5.341 3.232 9.532 2.563 1.56-.247 2.963-.915 4.196-1.99-2.771.254-7.557-.753-13.728-7.666v7.093Z" fill="currentColor"/>`,
|
|
1658
|
+
x: `<path fill="currentColor" d="M18.901 1.153h3.68l-8.04 9.19L24 22.846h-7.406l-5.8-7.584l-6.638 7.584H.474l8.6-9.83L0 1.154h7.594l5.243 6.932ZM17.61 20.644h2.039L6.486 3.24H4.298Z"/>`,
|
|
1659
|
+
bluesky: `<path fill="currentColor" d="M12 10.8c-1.087-2.114-4.046-6.053-6.798-7.995C2.566.944 1.561 1.266.902 1.565C.139 1.908 0 3.08 0 3.768c0 .69.378 5.65.624 6.479c.815 2.736 3.713 3.66 6.383 3.364q.204-.03.415-.056q-.207.033-.415.056c-3.912.58-7.387 2.005-2.83 7.078c5.013 5.19 6.87-1.113 7.823-4.308c.953 3.195 2.05 9.271 7.733 4.308c4.267-4.308 1.172-6.498-2.74-7.078a9 9 0 0 1-.415-.056q.21.026.415.056c2.67.297 5.568-.628 6.383-3.364c.246-.828.624-5.79.624-6.478c0-.69-.139-1.861-.902-2.206c-.659-.298-1.664-.62-4.3 1.24C16.046 4.748 13.087 8.687 12 10.8"/>`
|
|
1660
|
+
};
|
|
1661
|
+
var formatIconName = (icon) => {
|
|
1662
|
+
const iconLowerCase = icon.toLowerCase();
|
|
1663
|
+
if (iconLowerCase === "twitter") {
|
|
1664
|
+
return "x";
|
|
1665
|
+
}
|
|
1666
|
+
return iconLowerCase;
|
|
1667
|
+
};
|
|
1668
|
+
function getSocialIcons(socialLinks = []) {
|
|
1669
|
+
const icons = {};
|
|
1670
|
+
for (const link of socialLinks) {
|
|
1671
|
+
if (typeof link.icon === "string") {
|
|
1672
|
+
const pathContent = presetIcons[formatIconName(link.icon)];
|
|
1673
|
+
icons[link.icon] = `<svg xmlns="http://www.w3.org/2000/svg" width="100%" viewBox="0 0 24 24">${pathContent}</svg>`;
|
|
1674
|
+
}
|
|
1675
|
+
}
|
|
1676
|
+
return icons;
|
|
1677
|
+
}
|
|
1678
|
+
|
|
1615
1679
|
// src/node/initRsbuild.ts
|
|
1616
1680
|
function isPluginIncluded(config, pluginName) {
|
|
1617
1681
|
return config.builderPlugins?.some((plugin) => plugin.name === pluginName) || config.builderConfig?.plugins?.some(
|
|
@@ -1714,7 +1778,10 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1714
1778
|
include: [PACKAGE_ROOT, path11.join(cwd, "node_modules", RSPRESS_TEMP_DIR2)],
|
|
1715
1779
|
define: {
|
|
1716
1780
|
"process.env.__REACT_GTE_18__": JSON.stringify(reactVersion >= 18),
|
|
1717
|
-
"process.env.TEST": JSON.stringify(process.env.TEST)
|
|
1781
|
+
"process.env.TEST": JSON.stringify(process.env.TEST),
|
|
1782
|
+
"process.env.RSPRESS_SOCIAL_ICONS": JSON.stringify(
|
|
1783
|
+
getSocialIcons(config.themeConfig.socialLinks)
|
|
1784
|
+
)
|
|
1718
1785
|
}
|
|
1719
1786
|
},
|
|
1720
1787
|
performance: {
|
|
@@ -1823,7 +1890,7 @@ async function initRsbuild(rootDir, config, pluginDriver, enableSSG, extraRsbuil
|
|
|
1823
1890
|
const builderPlugins = config?.builderPlugins ?? [];
|
|
1824
1891
|
const runtimeTempDir = path11.join(RSPRESS_TEMP_DIR2, "runtime");
|
|
1825
1892
|
const runtimeAbsTempDir = path11.join(cwd, "node_modules", runtimeTempDir);
|
|
1826
|
-
await
|
|
1893
|
+
await fs9.mkdir(runtimeAbsTempDir, { recursive: true });
|
|
1827
1894
|
const routeService2 = await initRouteService({
|
|
1828
1895
|
config,
|
|
1829
1896
|
runtimeTempDir: runtimeAbsTempDir,
|
|
@@ -1852,14 +1919,14 @@ async function initRsbuild(rootDir, config, pluginDriver, enableSSG, extraRsbuil
|
|
|
1852
1919
|
}
|
|
1853
1920
|
|
|
1854
1921
|
// src/node/utils/checkLanguageParity.ts
|
|
1855
|
-
import
|
|
1922
|
+
import fs10 from "fs/promises";
|
|
1856
1923
|
import path12 from "path";
|
|
1857
1924
|
import { logger as logger3 } from "@rspress/shared/logger";
|
|
1858
1925
|
function normalizePath2(filePath) {
|
|
1859
1926
|
return filePath.split(path12.sep).join("/");
|
|
1860
1927
|
}
|
|
1861
1928
|
async function getAllMarkdownFilesFrom(dirPath) {
|
|
1862
|
-
const files = await
|
|
1929
|
+
const files = await fs10.readdir(dirPath, { withFileTypes: true });
|
|
1863
1930
|
const allFiles = [];
|
|
1864
1931
|
for (const file of files) {
|
|
1865
1932
|
const fullPath = path12.join(dirPath, file.name);
|
|
@@ -1876,7 +1943,7 @@ async function collectModuleFiles(contentPath, lang, includedDir, excludedDirs,
|
|
|
1876
1943
|
const langDirPath = path12.join(contentPath, lang);
|
|
1877
1944
|
const langModuleDir = path12.join(langDirPath, includedDir);
|
|
1878
1945
|
try {
|
|
1879
|
-
const moduleDirStats = await
|
|
1946
|
+
const moduleDirStats = await fs10.stat(langModuleDir);
|
|
1880
1947
|
if (!moduleDirStats.isDirectory())
|
|
1881
1948
|
return fileLangMap;
|
|
1882
1949
|
const files = await getAllMarkdownFilesFrom(langModuleDir);
|
|
@@ -1983,6 +2050,7 @@ async function dev(options) {
|
|
|
1983
2050
|
}
|
|
1984
2051
|
|
|
1985
2052
|
// src/node/build.ts
|
|
2053
|
+
import fs12 from "fs/promises";
|
|
1986
2054
|
import { dirname as dirname2, join as join3 } from "path";
|
|
1987
2055
|
import { pathToFileURL } from "url";
|
|
1988
2056
|
import {
|
|
@@ -1991,16 +2059,15 @@ import {
|
|
|
1991
2059
|
withBase as withBase3
|
|
1992
2060
|
} from "@rspress/shared";
|
|
1993
2061
|
import chalk3 from "@rspress/shared/chalk";
|
|
1994
|
-
import fs10 from "@rspress/shared/fs-extra";
|
|
1995
2062
|
import { logger as logger4 } from "@rspress/shared/logger";
|
|
1996
2063
|
|
|
1997
2064
|
// src/node/utils/renderHead.ts
|
|
1998
|
-
import
|
|
2065
|
+
import fs11 from "fs/promises";
|
|
1999
2066
|
import { loadFrontMatter as loadFrontMatter2 } from "@rspress/shared/node-utils";
|
|
2000
2067
|
async function renderFrontmatterHead(route) {
|
|
2001
2068
|
if (!isRouteMeta(route))
|
|
2002
2069
|
return "";
|
|
2003
|
-
const content = await
|
|
2070
|
+
const content = await fs11.readFile(route.absolutePath, {
|
|
2004
2071
|
encoding: "utf-8"
|
|
2005
2072
|
});
|
|
2006
2073
|
const {
|
|
@@ -2059,13 +2126,15 @@ async function bundle(docDirectory, config, pluginDriver, enableSSG) {
|
|
|
2059
2126
|
await checkLanguageParity(config);
|
|
2060
2127
|
}
|
|
2061
2128
|
}
|
|
2129
|
+
function emptyDir(path13) {
|
|
2130
|
+
return fs12.rm(path13, { force: true, recursive: true });
|
|
2131
|
+
}
|
|
2062
2132
|
async function renderPages(appDirectory, config, pluginDriver, ssgConfig) {
|
|
2063
2133
|
logger4.info("Rendering pages...");
|
|
2064
2134
|
const startTime = Date.now();
|
|
2065
2135
|
const outputPath = config?.outDir ?? join3(appDirectory, OUTPUT_DIR);
|
|
2066
2136
|
const ssrBundlePath = join3(outputPath, "ssr", "main.cjs");
|
|
2067
2137
|
try {
|
|
2068
|
-
const { default: fs11 } = await import("@rspress/shared/fs-extra");
|
|
2069
2138
|
const { version } = await Promise.resolve().then(() => __toESM(require_package()));
|
|
2070
2139
|
let render = null;
|
|
2071
2140
|
if (ssgConfig) {
|
|
@@ -2088,7 +2157,7 @@ async function renderPages(appDirectory, config, pluginDriver, ssgConfig) {
|
|
|
2088
2157
|
const routes = routeService.getRoutes();
|
|
2089
2158
|
const base = config?.base ?? "";
|
|
2090
2159
|
const htmlTemplatePath = join3(outputPath, "index.html");
|
|
2091
|
-
const htmlTemplate = await
|
|
2160
|
+
const htmlTemplate = await fs12.readFile(htmlTemplatePath, "utf-8");
|
|
2092
2161
|
const additionalRoutes = (await pluginDriver.addSSGRoutes()).map((route) => ({
|
|
2093
2162
|
routePath: withBase3(route.path, base)
|
|
2094
2163
|
}));
|
|
@@ -2161,14 +2230,16 @@ async function renderPages(appDirectory, config, pluginDriver, ssgConfig) {
|
|
|
2161
2230
|
return `${path13}.html`.replace(normalizedBase, "");
|
|
2162
2231
|
};
|
|
2163
2232
|
const fileName = normalizeHtmlFilePath(routePath);
|
|
2164
|
-
await
|
|
2165
|
-
|
|
2233
|
+
await fs12.mkdir(join3(outputPath, dirname2(fileName)), {
|
|
2234
|
+
recursive: true
|
|
2235
|
+
});
|
|
2236
|
+
await fs12.writeFile(join3(outputPath, fileName), html);
|
|
2166
2237
|
})
|
|
2167
2238
|
);
|
|
2168
2239
|
if (!isDebugMode2()) {
|
|
2169
|
-
await
|
|
2240
|
+
await emptyDir(join3(outputPath, "ssr"));
|
|
2170
2241
|
}
|
|
2171
|
-
await
|
|
2242
|
+
await emptyDir(join3(outputPath, "html"));
|
|
2172
2243
|
const totalTime = Date.now() - startTime;
|
|
2173
2244
|
logger4.success(`Pages rendered in ${chalk3.yellow(totalTime)} ms.`);
|
|
2174
2245
|
} catch (e) {
|
|
@@ -2183,7 +2254,7 @@ async function build(options) {
|
|
|
2183
2254
|
const modifiedConfig = await pluginDriver.modifyConfig();
|
|
2184
2255
|
await pluginDriver.beforeBuild();
|
|
2185
2256
|
const ssgConfig = modifiedConfig.ssg ?? true;
|
|
2186
|
-
await
|
|
2257
|
+
await emptyDir(TEMP_DIR);
|
|
2187
2258
|
await bundle(docDirectory, modifiedConfig, pluginDriver, Boolean(ssgConfig));
|
|
2188
2259
|
await renderPages(appDirectory, modifiedConfig, pluginDriver, ssgConfig);
|
|
2189
2260
|
await pluginDriver.afterBuild();
|