@rspress/core 1.40.2 → 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 +127 -63
- package/dist/index.js.map +1 -1
- package/dist/loader.js +2 -2
- package/dist/loader.js.map +1 -1
- package/package.json +14 -13
- package/compiled/fast-glob/@nodelib/fs.scandir/out/adapters/fs.d.ts +0 -20
- package/compiled/fast-glob/@nodelib/fs.scandir/out/index.d.ts +0 -12
- package/compiled/fast-glob/@nodelib/fs.scandir/out/providers/async.d.ts +0 -7
- package/compiled/fast-glob/@nodelib/fs.scandir/out/settings.d.ts +0 -20
- package/compiled/fast-glob/@nodelib/fs.scandir/out/types/index.d.ts +0 -20
- package/compiled/fast-glob/@nodelib/fs.stat/out/adapters/fs.d.ts +0 -13
- package/compiled/fast-glob/@nodelib/fs.stat/out/index.d.ts +0 -12
- package/compiled/fast-glob/@nodelib/fs.stat/out/providers/async.d.ts +0 -4
- package/compiled/fast-glob/@nodelib/fs.stat/out/settings.d.ts +0 -16
- package/compiled/fast-glob/@nodelib/fs.stat/out/types/index.d.ts +0 -4
- package/compiled/fast-glob/@nodelib/fs.walk/out/index.d.ts +0 -14
- package/compiled/fast-glob/@nodelib/fs.walk/out/providers/async.d.ts +0 -12
- package/compiled/fast-glob/@nodelib/fs.walk/out/readers/async.d.ts +0 -30
- package/compiled/fast-glob/@nodelib/fs.walk/out/readers/reader.d.ts +0 -6
- package/compiled/fast-glob/@nodelib/fs.walk/out/settings.d.ts +0 -30
- package/compiled/fast-glob/@nodelib/fs.walk/out/types/index.d.ts +0 -8
- package/compiled/fast-glob/index.js +0 -37
- package/compiled/fast-glob/license +0 -21
- package/compiled/fast-glob/out/index.d.ts +0 -27
- package/compiled/fast-glob/out/managers/tasks.d.ts +0 -22
- package/compiled/fast-glob/out/settings.d.ts +0 -164
- package/compiled/fast-glob/out/types/index.d.ts +0 -31
- package/compiled/fast-glob/package.json +0 -1
- package/compiled/globby/index.d.ts +0 -186
- package/compiled/globby/index.js +0 -1
- package/compiled/globby/license +0 -9
- package/compiled/globby/package.json +0 -1
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",
|
|
@@ -154,13 +154,14 @@ var require_package = __commonJS({
|
|
|
154
154
|
remark: "^14.0.3",
|
|
155
155
|
"remark-gfm": "3.0.1",
|
|
156
156
|
"rspack-plugin-virtual-module": "0.1.13",
|
|
157
|
+
tinyglobby: "^0.2.10",
|
|
157
158
|
unified: "^10.1.2",
|
|
158
159
|
"unist-util-visit": "^4.1.2",
|
|
159
160
|
"unist-util-visit-children": "^3.0.0"
|
|
160
161
|
},
|
|
161
162
|
devDependencies: {
|
|
162
|
-
"@modern-js/plugin-tailwindcss": "2.
|
|
163
|
-
"@modern-js/tsconfig": "2.
|
|
163
|
+
"@modern-js/plugin-tailwindcss": "2.64.0",
|
|
164
|
+
"@modern-js/tsconfig": "2.64.0",
|
|
164
165
|
"@types/hast": "3.0.4",
|
|
165
166
|
"@types/html-to-text": "^9.0.4",
|
|
166
167
|
"@types/jest": "~29.5.14",
|
|
@@ -169,14 +170,14 @@ var require_package = __commonJS({
|
|
|
169
170
|
"@types/node": "^18.11.17",
|
|
170
171
|
"@types/react": "^18.3.18",
|
|
171
172
|
"@types/react-dom": "^18.3.5",
|
|
172
|
-
postcss: "8.
|
|
173
|
+
postcss: "8.5.1",
|
|
173
174
|
"rehype-stringify": "^9.0.4",
|
|
174
175
|
"remark-parse": "^10.0.2",
|
|
175
176
|
"remark-rehype": "^10.1.0",
|
|
176
177
|
rimraf: "^3.0.2",
|
|
177
178
|
tailwindcss: "^3.4.17",
|
|
178
179
|
typescript: "^5.5.3",
|
|
179
|
-
vitest: "2.1.
|
|
180
|
+
vitest: "2.1.9"
|
|
180
181
|
},
|
|
181
182
|
engines: {
|
|
182
183
|
node: ">=14.17.6"
|
|
@@ -381,6 +382,7 @@ _plugins = new WeakMap();
|
|
|
381
382
|
_isProd = new WeakMap();
|
|
382
383
|
|
|
383
384
|
// src/node/initRsbuild.ts
|
|
385
|
+
import fs9 from "fs/promises";
|
|
384
386
|
import path11 from "path";
|
|
385
387
|
import { PLUGIN_LESS_NAME, pluginLess } from "@rsbuild/plugin-less";
|
|
386
388
|
import { PLUGIN_REACT_NAME, pluginReact } from "@rsbuild/plugin-react";
|
|
@@ -392,7 +394,6 @@ import {
|
|
|
392
394
|
removeLeadingSlash as removeLeadingSlash2,
|
|
393
395
|
removeTrailingSlash
|
|
394
396
|
} from "@rspress/shared";
|
|
395
|
-
import fs8 from "@rspress/shared/fs-extra";
|
|
396
397
|
|
|
397
398
|
// src/node/constants.ts
|
|
398
399
|
import path from "path";
|
|
@@ -436,13 +437,14 @@ var TEMP_DIR = path.join(
|
|
|
436
437
|
);
|
|
437
438
|
|
|
438
439
|
// src/node/route/RouteService.ts
|
|
440
|
+
import fs4 from "fs/promises";
|
|
439
441
|
import path5 from "path";
|
|
440
442
|
import {
|
|
441
443
|
addLeadingSlash,
|
|
442
444
|
addTrailingSlash,
|
|
443
445
|
withBase
|
|
444
446
|
} from "@rspress/shared";
|
|
445
|
-
import
|
|
447
|
+
import { glob } from "tinyglobby";
|
|
446
448
|
|
|
447
449
|
// src/node/utils/normalizePath.ts
|
|
448
450
|
import os from "os";
|
|
@@ -469,18 +471,37 @@ function createHash(str) {
|
|
|
469
471
|
}
|
|
470
472
|
|
|
471
473
|
// src/node/utils/detectReactVersion.ts
|
|
474
|
+
import fs2 from "fs";
|
|
472
475
|
import path3 from "path";
|
|
473
|
-
import fs from "@rspress/shared/fs-extra";
|
|
474
476
|
import { logger } from "@rspress/shared/logger";
|
|
475
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
|
|
476
495
|
var { CachedInputFileSystem, ResolverFactory } = enhancedResolve;
|
|
477
496
|
var DEFAULT_REACT_VERSION = 18;
|
|
478
497
|
async function detectReactVersion() {
|
|
479
498
|
const cwd = process.cwd();
|
|
480
499
|
const reactPath = path3.join(cwd, "node_modules", "react");
|
|
481
|
-
if (await
|
|
482
|
-
const reactPkg = await
|
|
483
|
-
|
|
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]);
|
|
484
505
|
return version;
|
|
485
506
|
}
|
|
486
507
|
return DEFAULT_REACT_VERSION;
|
|
@@ -499,7 +520,7 @@ async function resolveReactAlias(reactVersion, isSSR) {
|
|
|
499
520
|
}
|
|
500
521
|
const alias = {};
|
|
501
522
|
const resolver2 = ResolverFactory.createResolver({
|
|
502
|
-
fileSystem: new CachedInputFileSystem(
|
|
523
|
+
fileSystem: new CachedInputFileSystem(fs2, 0),
|
|
503
524
|
extensions: [".js"],
|
|
504
525
|
alias,
|
|
505
526
|
conditionNames: isSSR ? ["..."] : ["browser", "..."]
|
|
@@ -531,10 +552,10 @@ async function resolveReactAlias(reactVersion, isSSR) {
|
|
|
531
552
|
}
|
|
532
553
|
|
|
533
554
|
// src/node/utils/flattenMdxContent.ts
|
|
555
|
+
import fs3 from "fs";
|
|
534
556
|
import path4 from "path";
|
|
535
557
|
import { createProcessor } from "@mdx-js/mdx";
|
|
536
558
|
import { MDX_REGEXP } from "@rspress/shared";
|
|
537
|
-
import fs2 from "@rspress/shared/fs-extra";
|
|
538
559
|
import enhancedResolve2 from "enhanced-resolve";
|
|
539
560
|
var resolver;
|
|
540
561
|
var startFlatten = false;
|
|
@@ -543,7 +564,7 @@ var { CachedInputFileSystem: CachedInputFileSystem2, ResolverFactory: ResolverFa
|
|
|
543
564
|
async function resolveDepPath(importPath, importer, alias) {
|
|
544
565
|
if (!resolver) {
|
|
545
566
|
resolver = ResolverFactory2.createResolver({
|
|
546
|
-
fileSystem: new CachedInputFileSystem2(
|
|
567
|
+
fileSystem: new CachedInputFileSystem2(fs3, 0),
|
|
547
568
|
extensions: [".mdx", ".md"],
|
|
548
569
|
alias
|
|
549
570
|
});
|
|
@@ -581,7 +602,7 @@ async function flattenMdxContent(content, basePath, alias) {
|
|
|
581
602
|
}
|
|
582
603
|
if (!startFlatten) {
|
|
583
604
|
resolver = ResolverFactory2.createResolver({
|
|
584
|
-
fileSystem: new CachedInputFileSystem2(
|
|
605
|
+
fileSystem: new CachedInputFileSystem2(fs3, 0),
|
|
585
606
|
extensions: [".mdx", ".md", ".js"],
|
|
586
607
|
alias
|
|
587
608
|
});
|
|
@@ -609,7 +630,7 @@ async function flattenMdxContent(content, basePath, alias) {
|
|
|
609
630
|
continue;
|
|
610
631
|
}
|
|
611
632
|
if (MDX_REGEXP.test(absoluteImportPath)) {
|
|
612
|
-
const importedContent =
|
|
633
|
+
const importedContent = fs3.readFileSync(absoluteImportPath, "utf-8");
|
|
613
634
|
const { flattenContent: replacedValue, deps: subDeps } = await flattenMdxContent(importedContent, absoluteImportPath, alias);
|
|
614
635
|
result = result.replace(
|
|
615
636
|
new RegExp(`import\\s+${id}\\s+from\\s+['"](${importPath})['"];?`),
|
|
@@ -702,12 +723,7 @@ var RouteService = class {
|
|
|
702
723
|
}
|
|
703
724
|
}
|
|
704
725
|
async init() {
|
|
705
|
-
const
|
|
706
|
-
// @ts-expect-error
|
|
707
|
-
// eslint-disable-next-line node/file-extension-in-import
|
|
708
|
-
"../compiled/globby/index.js"
|
|
709
|
-
)).default;
|
|
710
|
-
const files = (await globby([`**/*.{${__privateGet(this, _extensions).join(",")}}`, ...__privateGet(this, _include)], {
|
|
726
|
+
const files = (await glob([`**/*.{${__privateGet(this, _extensions).join(",")}}`, ...__privateGet(this, _include)], {
|
|
711
727
|
cwd: __privateGet(this, _scanDir),
|
|
712
728
|
absolute: true,
|
|
713
729
|
ignore: [
|
|
@@ -831,7 +847,7 @@ _pluginDriver = new WeakMap();
|
|
|
831
847
|
_writeTempFile = new WeakSet();
|
|
832
848
|
writeTempFile_fn = async function(index, content) {
|
|
833
849
|
const tempFilePath = path5.join(__privateGet(this, _tempDir), `temp-${index}.mdx`);
|
|
834
|
-
await
|
|
850
|
+
await fs4.writeFile(tempFilePath, content);
|
|
835
851
|
return tempFilePath;
|
|
836
852
|
};
|
|
837
853
|
_generateRouteInfo = new WeakSet();
|
|
@@ -869,15 +885,15 @@ async function initRouteService(options) {
|
|
|
869
885
|
import { RspackVirtualModulePlugin } from "rspack-plugin-virtual-module";
|
|
870
886
|
|
|
871
887
|
// src/node/runtimeModule/globalStyles.ts
|
|
872
|
-
import
|
|
888
|
+
import fs5 from "fs/promises";
|
|
873
889
|
async function globalStylesVMPlugin(context) {
|
|
874
890
|
const { config, pluginDriver } = context;
|
|
875
891
|
const globalStylesByPlugins = pluginDriver.globalStyles();
|
|
876
892
|
if (config.globalStyles) {
|
|
877
893
|
const source = config.globalStyles;
|
|
878
|
-
const styleContent = await
|
|
894
|
+
const styleContent = await fs5.readFile(source, "utf-8");
|
|
879
895
|
const patchedStyleContent = styleContent.replace(/--modern-/g, "--rp-").replace(/\.modern-doc/g, ".rspress").replace(/\.modern-/g, ".rspress-");
|
|
880
|
-
await
|
|
896
|
+
await fs5.writeFile(source, patchedStyleContent, "utf-8");
|
|
881
897
|
}
|
|
882
898
|
const moduleContent = (await Promise.all(
|
|
883
899
|
[config?.globalStyles || "", ...globalStylesByPlugins].filter((source) => source.length > 0).map(async (source) => {
|
|
@@ -972,18 +988,18 @@ async function searchHookVMPlugin(context) {
|
|
|
972
988
|
}
|
|
973
989
|
|
|
974
990
|
// src/node/runtimeModule/siteData/index.ts
|
|
991
|
+
import fs7 from "fs/promises";
|
|
975
992
|
import path8 from "path";
|
|
976
993
|
import { SEARCH_INDEX_NAME } from "@rspress/shared";
|
|
977
|
-
import fs6 from "@rspress/shared/fs-extra";
|
|
978
994
|
import { groupBy } from "lodash-es";
|
|
979
995
|
|
|
980
996
|
// src/node/runtimeModule/siteData/extractPageData.ts
|
|
997
|
+
import fs6 from "fs/promises";
|
|
981
998
|
import path7 from "path";
|
|
982
999
|
import { compile } from "@rspress/mdx-rs";
|
|
983
1000
|
import {
|
|
984
1001
|
MDX_REGEXP as MDX_REGEXP2
|
|
985
1002
|
} from "@rspress/shared";
|
|
986
|
-
import fs5 from "@rspress/shared/fs-extra";
|
|
987
1003
|
import { loadFrontMatter } from "@rspress/shared/node-utils";
|
|
988
1004
|
import { htmlToText } from "html-to-text";
|
|
989
1005
|
function applyReplaceRulesToNestedObject(obj, replaceRules) {
|
|
@@ -996,7 +1012,7 @@ function applyReplaceRulesToNestedObject(obj, replaceRules) {
|
|
|
996
1012
|
}
|
|
997
1013
|
return obj;
|
|
998
1014
|
}
|
|
999
|
-
async function extractPageData(replaceRules, alias, domain, root, routeService2, highlighterLangs) {
|
|
1015
|
+
async function extractPageData(replaceRules, alias, domain, root, routeService2, highlighterLangs, searchCodeBlocks) {
|
|
1000
1016
|
const pageData = await Promise.all(
|
|
1001
1017
|
routeService2.getRoutes().map(async (route, index) => {
|
|
1002
1018
|
const defaultIndexInfo = {
|
|
@@ -1016,7 +1032,7 @@ async function extractPageData(replaceRules, alias, domain, root, routeService2,
|
|
|
1016
1032
|
if (!MDX_REGEXP2.test(route.absolutePath)) {
|
|
1017
1033
|
return defaultIndexInfo;
|
|
1018
1034
|
}
|
|
1019
|
-
let content = await
|
|
1035
|
+
let content = await fs6.readFile(route.absolutePath, "utf8");
|
|
1020
1036
|
const { frontmatter, content: strippedFrontMatter } = loadFrontMatter(
|
|
1021
1037
|
content,
|
|
1022
1038
|
route.absolutePath,
|
|
@@ -1059,7 +1075,7 @@ async function extractPageData(replaceRules, alias, domain, root, routeService2,
|
|
|
1059
1075
|
{
|
|
1060
1076
|
// Skip code blocks
|
|
1061
1077
|
selector: "pre > code",
|
|
1062
|
-
format: "skip"
|
|
1078
|
+
format: searchCodeBlocks ? "block" : "skip"
|
|
1063
1079
|
},
|
|
1064
1080
|
...["h1", "h2", "h3", "h4", "h5", "h6"].map((tag) => ({
|
|
1065
1081
|
selector: tag,
|
|
@@ -1348,14 +1364,17 @@ async function siteDataVMPlugin(context) {
|
|
|
1348
1364
|
}
|
|
1349
1365
|
const highlightLanguages = /* @__PURE__ */ new Set();
|
|
1350
1366
|
const replaceRules = userConfig?.replaceRules || [];
|
|
1351
|
-
const
|
|
1367
|
+
const searchConfig = userConfig?.search || {};
|
|
1368
|
+
const domain = searchConfig?.mode === "remote" ? searchConfig.domain ?? "" : "";
|
|
1369
|
+
const searchCodeBlocks = "codeBlocks" in searchConfig ? searchConfig.codeBlocks : false;
|
|
1352
1370
|
const pages = await extractPageData(
|
|
1353
1371
|
replaceRules,
|
|
1354
1372
|
alias,
|
|
1355
1373
|
domain,
|
|
1356
1374
|
userDocRoot,
|
|
1357
1375
|
routeService2,
|
|
1358
|
-
highlightLanguages
|
|
1376
|
+
highlightLanguages,
|
|
1377
|
+
searchCodeBlocks
|
|
1359
1378
|
);
|
|
1360
1379
|
await pluginDriver.modifySearchIndexData(pages);
|
|
1361
1380
|
const versioned = userConfig.search && userConfig.search.mode !== "remote" && userConfig.search.versioned;
|
|
@@ -1379,8 +1398,8 @@ async function siteDataVMPlugin(context) {
|
|
|
1379
1398
|
const [version, lang] = group.split("###");
|
|
1380
1399
|
const indexVersion = version ? `.${version.replace(".", "_")}` : "";
|
|
1381
1400
|
const indexLang = lang ? `.${lang}` : "";
|
|
1382
|
-
await
|
|
1383
|
-
await
|
|
1401
|
+
await fs7.mkdir(TEMP_DIR, { recursive: true });
|
|
1402
|
+
await fs7.writeFile(
|
|
1384
1403
|
path8.join(
|
|
1385
1404
|
TEMP_DIR,
|
|
1386
1405
|
`${SEARCH_INDEX_NAME}${indexVersion}${indexLang}.${indexHash}.json`
|
|
@@ -1523,18 +1542,21 @@ function rsbuildPluginDocVM(factoryContext) {
|
|
|
1523
1542
|
}
|
|
1524
1543
|
|
|
1525
1544
|
// src/node/searchIndex.ts
|
|
1545
|
+
import { createReadStream } from "fs";
|
|
1546
|
+
import fs8 from "fs/promises";
|
|
1526
1547
|
import path9, { join as join2 } from "path";
|
|
1527
1548
|
import { SEARCH_INDEX_NAME as SEARCH_INDEX_NAME2, isSCM } from "@rspress/shared";
|
|
1528
1549
|
import chalk2 from "@rspress/shared/chalk";
|
|
1529
|
-
import fs7 from "@rspress/shared/fs-extra";
|
|
1530
1550
|
import { logger as logger2 } from "@rspress/shared/logger";
|
|
1531
1551
|
async function writeSearchIndex(config) {
|
|
1532
1552
|
if (config?.search === false) {
|
|
1533
1553
|
return;
|
|
1534
1554
|
}
|
|
1535
1555
|
const cwd = process.cwd();
|
|
1536
|
-
const searchIndexFiles = await
|
|
1556
|
+
const searchIndexFiles = await fs8.readdir(TEMP_DIR);
|
|
1537
1557
|
const outDir = config?.outDir ?? join2(cwd, OUTPUT_DIR);
|
|
1558
|
+
const targetDir = join2(outDir, "static");
|
|
1559
|
+
await fs8.mkdir(targetDir, { recursive: true });
|
|
1538
1560
|
let searchIndexData = "[]";
|
|
1539
1561
|
let scanning = false;
|
|
1540
1562
|
for (const searchIndexFile of searchIndexFiles) {
|
|
@@ -1542,13 +1564,13 @@ async function writeSearchIndex(config) {
|
|
|
1542
1564
|
continue;
|
|
1543
1565
|
}
|
|
1544
1566
|
const source = join2(TEMP_DIR, searchIndexFile);
|
|
1545
|
-
const target = join2(
|
|
1546
|
-
const searchIndex = await
|
|
1567
|
+
const target = join2(targetDir, searchIndexFile);
|
|
1568
|
+
const searchIndex = await fs8.readFile(
|
|
1547
1569
|
join2(TEMP_DIR, searchIndexFile),
|
|
1548
1570
|
"utf-8"
|
|
1549
1571
|
);
|
|
1550
1572
|
searchIndexData = `${searchIndexData.slice(0, -1)}${scanning ? "," : ""}${searchIndex.slice(1)}`;
|
|
1551
|
-
await
|
|
1573
|
+
await fs8.rename(source, target);
|
|
1552
1574
|
scanning = true;
|
|
1553
1575
|
}
|
|
1554
1576
|
if (isProduction() && isSCM() && config?.search?.mode === "remote") {
|
|
@@ -1580,7 +1602,7 @@ function serveSearchIndexMiddleware(config) {
|
|
|
1580
1602
|
if (req.url?.includes(searchIndexRequestMatch)) {
|
|
1581
1603
|
res.setHeader("Content-Type", "application/json");
|
|
1582
1604
|
const searchIndexFile = req.url?.split("/").pop();
|
|
1583
|
-
|
|
1605
|
+
createReadStream(
|
|
1584
1606
|
path9.join(
|
|
1585
1607
|
process.cwd(),
|
|
1586
1608
|
config?.outDir || OUTPUT_DIR,
|
|
@@ -1598,18 +1620,14 @@ function serveSearchIndexMiddleware(config) {
|
|
|
1598
1620
|
// src/node/utils/detectCustomIcon.ts
|
|
1599
1621
|
import { existsSync } from "fs";
|
|
1600
1622
|
import path10 from "path";
|
|
1623
|
+
import { glob as glob2 } from "tinyglobby";
|
|
1601
1624
|
var detectCustomIcon = async (customThemeDir) => {
|
|
1602
1625
|
const assetsDir = path10.join(customThemeDir, "assets");
|
|
1603
1626
|
const alias = {};
|
|
1604
1627
|
if (!existsSync(assetsDir)) {
|
|
1605
1628
|
return alias;
|
|
1606
1629
|
}
|
|
1607
|
-
const
|
|
1608
|
-
// @ts-expect-error
|
|
1609
|
-
// eslint-disable-next-line node/file-extension-in-import
|
|
1610
|
-
"../compiled/globby/index.js"
|
|
1611
|
-
)).default;
|
|
1612
|
-
const files = await globby("*.svg", {
|
|
1630
|
+
const files = await glob2("*.svg", {
|
|
1613
1631
|
cwd: assetsDir
|
|
1614
1632
|
});
|
|
1615
1633
|
files.forEach((file) => {
|
|
@@ -1619,6 +1637,45 @@ var detectCustomIcon = async (customThemeDir) => {
|
|
|
1619
1637
|
return alias;
|
|
1620
1638
|
};
|
|
1621
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
|
+
|
|
1622
1679
|
// src/node/initRsbuild.ts
|
|
1623
1680
|
function isPluginIncluded(config, pluginName) {
|
|
1624
1681
|
return config.builderPlugins?.some((plugin) => plugin.name === pluginName) || config.builderConfig?.plugins?.some(
|
|
@@ -1721,7 +1778,10 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1721
1778
|
include: [PACKAGE_ROOT, path11.join(cwd, "node_modules", RSPRESS_TEMP_DIR2)],
|
|
1722
1779
|
define: {
|
|
1723
1780
|
"process.env.__REACT_GTE_18__": JSON.stringify(reactVersion >= 18),
|
|
1724
|
-
"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
|
+
)
|
|
1725
1785
|
}
|
|
1726
1786
|
},
|
|
1727
1787
|
performance: {
|
|
@@ -1830,7 +1890,7 @@ async function initRsbuild(rootDir, config, pluginDriver, enableSSG, extraRsbuil
|
|
|
1830
1890
|
const builderPlugins = config?.builderPlugins ?? [];
|
|
1831
1891
|
const runtimeTempDir = path11.join(RSPRESS_TEMP_DIR2, "runtime");
|
|
1832
1892
|
const runtimeAbsTempDir = path11.join(cwd, "node_modules", runtimeTempDir);
|
|
1833
|
-
await
|
|
1893
|
+
await fs9.mkdir(runtimeAbsTempDir, { recursive: true });
|
|
1834
1894
|
const routeService2 = await initRouteService({
|
|
1835
1895
|
config,
|
|
1836
1896
|
runtimeTempDir: runtimeAbsTempDir,
|
|
@@ -1859,14 +1919,14 @@ async function initRsbuild(rootDir, config, pluginDriver, enableSSG, extraRsbuil
|
|
|
1859
1919
|
}
|
|
1860
1920
|
|
|
1861
1921
|
// src/node/utils/checkLanguageParity.ts
|
|
1862
|
-
import
|
|
1922
|
+
import fs10 from "fs/promises";
|
|
1863
1923
|
import path12 from "path";
|
|
1864
1924
|
import { logger as logger3 } from "@rspress/shared/logger";
|
|
1865
1925
|
function normalizePath2(filePath) {
|
|
1866
1926
|
return filePath.split(path12.sep).join("/");
|
|
1867
1927
|
}
|
|
1868
1928
|
async function getAllMarkdownFilesFrom(dirPath) {
|
|
1869
|
-
const files = await
|
|
1929
|
+
const files = await fs10.readdir(dirPath, { withFileTypes: true });
|
|
1870
1930
|
const allFiles = [];
|
|
1871
1931
|
for (const file of files) {
|
|
1872
1932
|
const fullPath = path12.join(dirPath, file.name);
|
|
@@ -1883,7 +1943,7 @@ async function collectModuleFiles(contentPath, lang, includedDir, excludedDirs,
|
|
|
1883
1943
|
const langDirPath = path12.join(contentPath, lang);
|
|
1884
1944
|
const langModuleDir = path12.join(langDirPath, includedDir);
|
|
1885
1945
|
try {
|
|
1886
|
-
const moduleDirStats = await
|
|
1946
|
+
const moduleDirStats = await fs10.stat(langModuleDir);
|
|
1887
1947
|
if (!moduleDirStats.isDirectory())
|
|
1888
1948
|
return fileLangMap;
|
|
1889
1949
|
const files = await getAllMarkdownFilesFrom(langModuleDir);
|
|
@@ -1990,6 +2050,7 @@ async function dev(options) {
|
|
|
1990
2050
|
}
|
|
1991
2051
|
|
|
1992
2052
|
// src/node/build.ts
|
|
2053
|
+
import fs12 from "fs/promises";
|
|
1993
2054
|
import { dirname as dirname2, join as join3 } from "path";
|
|
1994
2055
|
import { pathToFileURL } from "url";
|
|
1995
2056
|
import {
|
|
@@ -1998,16 +2059,15 @@ import {
|
|
|
1998
2059
|
withBase as withBase3
|
|
1999
2060
|
} from "@rspress/shared";
|
|
2000
2061
|
import chalk3 from "@rspress/shared/chalk";
|
|
2001
|
-
import fs10 from "@rspress/shared/fs-extra";
|
|
2002
2062
|
import { logger as logger4 } from "@rspress/shared/logger";
|
|
2003
2063
|
|
|
2004
2064
|
// src/node/utils/renderHead.ts
|
|
2005
|
-
import
|
|
2065
|
+
import fs11 from "fs/promises";
|
|
2006
2066
|
import { loadFrontMatter as loadFrontMatter2 } from "@rspress/shared/node-utils";
|
|
2007
2067
|
async function renderFrontmatterHead(route) {
|
|
2008
2068
|
if (!isRouteMeta(route))
|
|
2009
2069
|
return "";
|
|
2010
|
-
const content = await
|
|
2070
|
+
const content = await fs11.readFile(route.absolutePath, {
|
|
2011
2071
|
encoding: "utf-8"
|
|
2012
2072
|
});
|
|
2013
2073
|
const {
|
|
@@ -2066,13 +2126,15 @@ async function bundle(docDirectory, config, pluginDriver, enableSSG) {
|
|
|
2066
2126
|
await checkLanguageParity(config);
|
|
2067
2127
|
}
|
|
2068
2128
|
}
|
|
2129
|
+
function emptyDir(path13) {
|
|
2130
|
+
return fs12.rm(path13, { force: true, recursive: true });
|
|
2131
|
+
}
|
|
2069
2132
|
async function renderPages(appDirectory, config, pluginDriver, ssgConfig) {
|
|
2070
2133
|
logger4.info("Rendering pages...");
|
|
2071
2134
|
const startTime = Date.now();
|
|
2072
2135
|
const outputPath = config?.outDir ?? join3(appDirectory, OUTPUT_DIR);
|
|
2073
2136
|
const ssrBundlePath = join3(outputPath, "ssr", "main.cjs");
|
|
2074
2137
|
try {
|
|
2075
|
-
const { default: fs11 } = await import("@rspress/shared/fs-extra");
|
|
2076
2138
|
const { version } = await Promise.resolve().then(() => __toESM(require_package()));
|
|
2077
2139
|
let render = null;
|
|
2078
2140
|
if (ssgConfig) {
|
|
@@ -2095,7 +2157,7 @@ async function renderPages(appDirectory, config, pluginDriver, ssgConfig) {
|
|
|
2095
2157
|
const routes = routeService.getRoutes();
|
|
2096
2158
|
const base = config?.base ?? "";
|
|
2097
2159
|
const htmlTemplatePath = join3(outputPath, "index.html");
|
|
2098
|
-
const htmlTemplate = await
|
|
2160
|
+
const htmlTemplate = await fs12.readFile(htmlTemplatePath, "utf-8");
|
|
2099
2161
|
const additionalRoutes = (await pluginDriver.addSSGRoutes()).map((route) => ({
|
|
2100
2162
|
routePath: withBase3(route.path, base)
|
|
2101
2163
|
}));
|
|
@@ -2168,14 +2230,16 @@ async function renderPages(appDirectory, config, pluginDriver, ssgConfig) {
|
|
|
2168
2230
|
return `${path13}.html`.replace(normalizedBase, "");
|
|
2169
2231
|
};
|
|
2170
2232
|
const fileName = normalizeHtmlFilePath(routePath);
|
|
2171
|
-
await
|
|
2172
|
-
|
|
2233
|
+
await fs12.mkdir(join3(outputPath, dirname2(fileName)), {
|
|
2234
|
+
recursive: true
|
|
2235
|
+
});
|
|
2236
|
+
await fs12.writeFile(join3(outputPath, fileName), html);
|
|
2173
2237
|
})
|
|
2174
2238
|
);
|
|
2175
2239
|
if (!isDebugMode2()) {
|
|
2176
|
-
await
|
|
2240
|
+
await emptyDir(join3(outputPath, "ssr"));
|
|
2177
2241
|
}
|
|
2178
|
-
await
|
|
2242
|
+
await emptyDir(join3(outputPath, "html"));
|
|
2179
2243
|
const totalTime = Date.now() - startTime;
|
|
2180
2244
|
logger4.success(`Pages rendered in ${chalk3.yellow(totalTime)} ms.`);
|
|
2181
2245
|
} catch (e) {
|
|
@@ -2190,7 +2254,7 @@ async function build(options) {
|
|
|
2190
2254
|
const modifiedConfig = await pluginDriver.modifyConfig();
|
|
2191
2255
|
await pluginDriver.beforeBuild();
|
|
2192
2256
|
const ssgConfig = modifiedConfig.ssg ?? true;
|
|
2193
|
-
await
|
|
2257
|
+
await emptyDir(TEMP_DIR);
|
|
2194
2258
|
await bundle(docDirectory, modifiedConfig, pluginDriver, Boolean(ssgConfig));
|
|
2195
2259
|
await renderPages(appDirectory, modifiedConfig, pluginDriver, ssgConfig);
|
|
2196
2260
|
await pluginDriver.afterBuild();
|