@rspress/core 2.0.0-rc.1 → 2.0.0-rc.3
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/bin/rspress.js +1 -1
- package/dist/0~7675.723d12b2.js +1794 -0
- package/dist/3521.56e42d70.js +56 -0
- package/dist/4669.12208c6a.js +2 -0
- package/dist/5485.077f14ff.js +98 -0
- package/dist/6289.c67fe0d5.js +5 -0
- package/dist/8813.9da1f210.js +2 -0
- package/dist/9643.f109822d.js +5 -0
- package/dist/_private/react/render.js +17 -4
- package/dist/cli/config/index.js +4 -0
- package/dist/cli/config/loadConfigFile.js +30 -0
- package/dist/cli/index.cb89dbd1.js +3 -0
- package/dist/cli/index.js +122 -0
- package/dist/eject-theme/components/Badge/index.scss +1 -0
- package/dist/eject-theme/components/Banner/index.tsx +6 -5
- package/dist/eject-theme/components/Callout/index.scss +0 -2
- package/dist/eject-theme/components/Callout/index.tsx +8 -2
- package/dist/eject-theme/components/CodeBlock/index.scss +12 -18
- package/dist/eject-theme/components/CodeBlock/index.tsx +10 -1
- package/dist/eject-theme/components/CodeBlockRuntime/index.tsx +50 -11
- package/dist/eject-theme/components/CodeButtonGroup/CopyCodeButton.tsx +1 -3
- package/dist/eject-theme/components/CodeButtonGroup/index.scss +5 -1
- package/dist/eject-theme/components/CodeButtonGroup/index.tsx +1 -3
- package/dist/eject-theme/components/DocContent/doc.scss +27 -7
- package/dist/eject-theme/components/DocContent/docComponents/pre.tsx +2 -1
- package/dist/eject-theme/components/DocContent/docComponents/table.tsx +10 -4
- package/dist/eject-theme/components/DocContent/index.tsx +21 -4
- package/dist/eject-theme/components/DocFooter/index.tsx +1 -6
- package/dist/eject-theme/components/{DocContent/FallbackHeading.tsx → FallbackHeading/index.tsx} +20 -11
- package/dist/eject-theme/components/HoverGroup/index.scss +1 -1
- package/dist/eject-theme/components/LastUpdated/index.tsx +8 -1
- package/dist/eject-theme/components/Link/index.tsx +22 -6
- package/dist/eject-theme/components/Nav/NavMenu.tsx +2 -3
- package/dist/eject-theme/components/NavHamburger/index.tsx +3 -4
- package/dist/eject-theme/components/NavScreen/NavScreenLangs.scss +6 -0
- package/dist/eject-theme/components/NavScreen/NavScreenLangs.tsx +23 -9
- package/dist/eject-theme/components/NavScreen/NavScreenMenuItem.tsx +2 -3
- package/dist/eject-theme/components/NavScreen/NavScreenVersions.scss +6 -0
- package/dist/eject-theme/components/NavScreen/NavScreenVersions.tsx +22 -9
- package/dist/eject-theme/components/Overview/index.tsx +7 -8
- package/dist/eject-theme/components/{Overview/OverviewGroup.scss → OverviewGroup/index.scss} +66 -12
- package/dist/eject-theme/components/{Overview/OverviewGroup.tsx → OverviewGroup/index.tsx} +51 -5
- package/dist/eject-theme/components/PackageManagerTabs/index.tsx +12 -0
- package/dist/eject-theme/components/PrevNextPage/index.tsx +6 -3
- package/dist/eject-theme/components/Root/index.tsx +58 -0
- package/dist/eject-theme/components/Search/NoSearchResult.tsx +2 -3
- package/dist/eject-theme/components/Search/SearchButton.tsx +3 -4
- package/dist/eject-theme/components/Search/SearchPanel.tsx +12 -7
- package/dist/eject-theme/components/Search/SuggestItem.tsx +15 -12
- package/dist/eject-theme/components/Search/logic/util.test.ts +1 -1
- package/dist/eject-theme/components/Sidebar/SidebarGroup.tsx +2 -3
- package/dist/eject-theme/components/Sidebar/SidebarItem.tsx +1 -0
- package/dist/eject-theme/components/SidebarMenu/index.tsx +4 -4
- package/dist/eject-theme/components/SocialLinks/index.tsx +2 -3
- package/dist/eject-theme/components/SourceCode/index.tsx +6 -4
- package/dist/eject-theme/components/SwitchAppearance/index.tsx +3 -5
- package/dist/eject-theme/components/Tabs/index.scss +31 -26
- package/dist/eject-theme/components/Tabs/index.tsx +16 -0
- package/dist/eject-theme/components/Tag/index.tsx +84 -5
- package/dist/eject-theme/components/Toc/TocItem.scss +3 -3
- package/dist/eject-theme/components/Toc/TocItem.tsx +1 -0
- package/dist/index.d.ts +6 -6
- package/dist/index.js +16 -3134
- package/dist/node/PluginDriver.d.ts +1 -1
- package/dist/node/PluginDriver.js +142 -0
- package/dist/node/auto-nav-sidebar/index.js +44 -0
- package/dist/node/auto-nav-sidebar/locales.js +26 -0
- package/dist/node/auto-nav-sidebar/normalize.js +230 -0
- package/dist/node/auto-nav-sidebar/utils.js +68 -0
- package/dist/node/auto-nav-sidebar/walk.js +67 -0
- package/dist/node/build.js +31 -0
- package/dist/node/constants.d.ts +2 -0
- package/dist/node/constants.js +34 -0
- package/dist/node/dev.js +32 -0
- package/dist/node/eject.js +111 -0
- package/dist/node/index.d.ts +5 -5
- package/dist/node/initRsbuild.d.ts +2 -2
- package/dist/node/initRsbuild.js +346 -0
- package/dist/node/last-updated/index.js +28 -0
- package/dist/node/logger/hint.d.ts +1 -1
- package/dist/node/logger/hint.js +85 -0
- package/dist/node/mdx/loader.d.ts +1 -1
- package/dist/node/mdx/loader.e1578c62.js +13 -0
- package/dist/{loader.js → node/mdx/loader.js} +4 -3
- package/dist/node/mdx/options.d.ts +2 -2
- package/dist/node/mdx/options.js +103 -0
- package/dist/node/mdx/processor.d.ts +2 -2
- package/dist/node/mdx/processor.js +71 -0
- package/dist/node/mdx/rehypePlugins/codeMeta.js +10 -0
- package/dist/node/mdx/rehypePlugins/headerAnchor.js +53 -0
- package/dist/node/mdx/rehypePlugins/shiki.js +34 -0
- package/dist/node/mdx/rehypePlugins/transformers/add-lang.js +15 -0
- package/dist/node/mdx/rehypePlugins/transformers/add-line-numbers.js +22 -0
- package/dist/node/mdx/rehypePlugins/transformers/add-title.js +24 -0
- package/dist/node/mdx/rehypePlugins/transformers/add-wrap-code.js +22 -0
- package/dist/node/mdx/rehypePlugins/transformers/index.d.ts +5 -5
- package/dist/node/mdx/rehypePlugins/transformers/index.js +5 -0
- package/dist/node/mdx/rehypePlugins/transformers/meta-highlight.js +41 -0
- package/dist/node/mdx/remarkPlugins/builtin.js +11 -0
- package/dist/node/mdx/remarkPlugins/containerSyntax.js +190 -0
- package/dist/node/mdx/remarkPlugins/fileCodeBlock.js +66 -0
- package/dist/node/mdx/remarkPlugins/image.js +67 -0
- package/dist/node/mdx/remarkPlugins/link.d.ts +1 -1
- package/dist/node/mdx/remarkPlugins/link.js +99 -0
- package/dist/node/mdx/remarkPlugins/toc.js +50 -0
- package/dist/node/mdx/types.d.ts +3 -3
- package/dist/node/medium-zoom/index.d.ts +1 -1
- package/dist/node/medium-zoom/index.js +14 -0
- package/dist/node/route/RoutePage.d.ts +1 -1
- package/dist/node/route/RoutePage.js +61 -0
- package/dist/node/route/RouteService.d.ts +1 -1
- package/dist/node/route/RouteService.js +177 -0
- package/dist/node/route/extractPageData.d.ts +1 -1
- package/dist/node/route/extractPageData.js +112 -0
- package/dist/node/route/normalizeRoutePath.js +54 -0
- package/dist/node/runtimeModule/DEFAULT_I18N_TEXT.d.ts +21 -0
- package/dist/node/runtimeModule/DEFAULT_I18N_TEXT.js +150 -0
- package/dist/node/runtimeModule/globalStyles.d.ts +1 -1
- package/dist/node/runtimeModule/globalStyles.js +12 -0
- package/dist/node/runtimeModule/globalUIComponents.d.ts +1 -1
- package/dist/node/runtimeModule/globalUIComponents.js +25 -0
- package/dist/node/runtimeModule/i18n.d.ts +2 -2
- package/dist/node/runtimeModule/i18n.js +83 -0
- package/dist/node/runtimeModule/pageData/createPageData.d.ts +1 -1
- package/dist/node/runtimeModule/pageData/createPageData.js +64 -0
- package/dist/node/runtimeModule/pageData/rsbuildPlugin.d.ts +1 -1
- package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +51 -0
- package/dist/node/runtimeModule/routeList.d.ts +1 -1
- package/dist/node/runtimeModule/routeList.js +7 -0
- package/dist/node/runtimeModule/searchHooks.d.ts +1 -1
- package/dist/node/runtimeModule/searchHooks.js +11 -0
- package/dist/node/runtimeModule/siteData/createSiteData.js +34 -0
- package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +94 -0
- package/dist/node/runtimeModule/siteData/rsbuildPlugin.d.ts +1 -1
- package/dist/node/runtimeModule/siteData/rsbuildPlugin.js +24 -0
- package/dist/node/runtimeModule/socialLinks.d.ts +1 -1
- package/dist/node/runtimeModule/socialLinks.js +8 -0
- package/dist/node/runtimeModule/types.d.ts +2 -2
- package/dist/node/serve.js +23 -0
- package/dist/node/ssg/renderHtmlTemplate.js +33 -0
- package/dist/node/ssg/renderPage.js +34 -0
- package/dist/node/ssg/renderPageWorker.474f9f73.js +2 -0
- package/dist/node/ssg/renderPageWorker.js +15 -0
- package/dist/node/ssg/renderPages.d.ts +1 -1
- package/dist/node/ssg/renderPages.js +105 -0
- package/dist/node/ssg/renderPages.js.LICENSE.txt +4 -0
- package/dist/node/ssg/rsbuildPluginCSR.d.ts +1 -1
- package/dist/node/ssg/rsbuildPluginCSR.js +27 -0
- package/dist/node/ssg/rsbuildPluginSSG.d.ts +1 -1
- package/dist/node/ssg/rsbuildPluginSSG.js +72 -0
- package/dist/node/ssg/ssgEnv.js +33 -0
- package/dist/node/ssg/ssgEnv.js.LICENSE.txt +5 -0
- package/dist/node/ssg-md/llms/emitLlmsTxt.d.ts +1 -1
- package/dist/node/ssg-md/llms/emitLlmsTxt.js +84 -0
- package/dist/node/ssg-md/llms/llmsTxt.d.ts +1 -1
- package/dist/node/ssg-md/llms/llmsTxt.js +66 -0
- package/dist/node/ssg-md/react/index.d.ts +1 -1
- package/dist/node/ssg-md/remarkSplitMdx.js +244 -0
- package/dist/node/ssg-md/renderPage.js +31 -0
- package/dist/node/ssg-md/renderPages.d.ts +1 -1
- package/dist/node/ssg-md/renderPages.js +27 -0
- package/dist/node/ssg-md/rsbuildPluginSSGMD.d.ts +1 -1
- package/dist/node/ssg-md/rsbuildPluginSSGMD.js +47 -0
- package/dist/node/utils/applyReplaceRules.js +6 -0
- package/dist/node/utils/checkLanguageParity.js +77 -0
- package/dist/node/utils/createHash.js +5 -0
- package/dist/node/utils/error.d.ts +9 -0
- package/dist/node/utils/error.js +10 -0
- package/dist/node/utils/escapeHeadingIds.js +5 -0
- package/dist/node/utils/flattenMdxContent.js +74 -0
- package/dist/node/utils/fs.js +14 -0
- package/dist/node/utils/getImportAstNode.js +63 -0
- package/dist/node/utils/getPageKey.js +6 -0
- package/dist/node/utils/getSocialIcons.js +32 -0
- package/dist/node/utils/index.d.ts +10 -9
- package/dist/node/utils/normalizePath.js +10 -0
- package/dist/node/utils/reactAlias.d.ts +2 -0
- package/dist/node/utils/reactAlias.js +83 -0
- package/dist/rslib-runtime.99091bf6.js +18 -0
- package/dist/runtime/App.js +2 -2
- package/dist/runtime/ClientApp.d.ts +1 -1
- package/dist/runtime/ClientApp.js +0 -4
- package/dist/runtime/initPageData.js +1 -1
- package/dist/runtime/ssrMdServerEntry.js +1 -1
- package/dist/runtime/ssrServerEntry.js +2 -1
- package/dist/runtime.72d450ac.js +1 -0
- package/dist/runtime.js +3 -2
- package/dist/shiki-transformers.d.ts +1 -1
- package/dist/shiki-transformers.js +6 -120
- package/dist/theme/assets/deprecated.js +18 -0
- package/dist/theme/assets/experimental.js +21 -0
- package/dist/theme/components/Badge/index.css +1 -0
- package/dist/theme/components/Banner/index.d.ts +1 -1
- package/dist/theme/components/Banner/index.js +4 -5
- package/dist/theme/components/Callout/index.css +0 -2
- package/dist/theme/components/Callout/index.js +5 -2
- package/dist/theme/components/CodeBlock/index.css +11 -21
- package/dist/theme/components/CodeBlock/index.js +5 -1
- package/dist/theme/components/CodeBlockRuntime/index.d.ts +1 -1
- package/dist/theme/components/CodeBlockRuntime/index.js +38 -8
- package/dist/theme/components/CodeButtonGroup/CopyCodeButton.js +3 -5
- package/dist/theme/components/CodeButtonGroup/index.css +5 -1
- package/dist/theme/components/CodeButtonGroup/index.js +3 -5
- package/dist/theme/components/DocContent/doc.css +28 -7
- package/dist/theme/components/DocContent/docComponents/index.d.ts +3 -3
- package/dist/theme/components/DocContent/docComponents/pre.js +3 -1
- package/dist/theme/components/DocContent/docComponents/table.d.ts +2 -2
- package/dist/theme/components/DocContent/docComponents/table.js +8 -3
- package/dist/theme/components/DocContent/index.d.ts +11 -2
- package/dist/theme/components/DocContent/index.js +6 -6
- package/dist/theme/components/DocFooter/index.js +1 -5
- package/dist/theme/components/{DocContent/FallbackHeading.js → FallbackHeading/index.js} +19 -11
- package/dist/theme/components/HoverGroup/index.css +3 -3
- package/dist/theme/components/HoverGroup/useHoverGroup.d.ts +1 -1
- package/dist/theme/components/LastUpdated/index.d.ts +1 -1
- package/dist/theme/components/LastUpdated/index.js +5 -1
- package/dist/theme/components/Link/index.d.ts +1 -1
- package/dist/theme/components/Link/index.js +17 -7
- package/dist/theme/components/Nav/NavMenu.js +2 -3
- package/dist/theme/components/NavHamburger/index.js +3 -4
- package/dist/theme/components/NavScreen/NavScreenLangs.css +6 -0
- package/dist/theme/components/NavScreen/NavScreenLangs.js +13 -3
- package/dist/theme/components/NavScreen/NavScreenMenuItem.js +2 -3
- package/dist/theme/components/NavScreen/NavScreenVersions.css +6 -0
- package/dist/theme/components/NavScreen/NavScreenVersions.js +12 -3
- package/dist/theme/components/Overview/index.d.ts +0 -1
- package/dist/theme/components/Overview/index.js +2 -3
- package/dist/theme/components/{Overview/OverviewGroup.css → OverviewGroup/index.css} +60 -8
- package/dist/theme/components/{Overview/OverviewGroup.d.ts → OverviewGroup/index.d.ts} +1 -1
- package/dist/theme/components/OverviewGroup/index.js +88 -0
- package/dist/theme/components/PackageManagerTabs/index.d.ts +1 -1
- package/dist/theme/components/PackageManagerTabs/index.js +4 -0
- package/dist/theme/components/PrevNextPage/index.js +3 -4
- package/dist/theme/components/Root/index.d.ts +54 -0
- package/dist/theme/components/Root/index.js +7 -0
- package/dist/theme/components/Search/NoSearchResult.js +2 -3
- package/dist/theme/components/Search/SearchButton.js +3 -4
- package/dist/theme/components/Search/SearchPanel.js +12 -15
- package/dist/theme/components/Search/SuggestItem.d.ts +1 -1
- package/dist/theme/components/Search/SuggestItem.js +7 -11
- package/dist/theme/components/Search/logic/Provider.d.ts +1 -1
- package/dist/theme/components/Search/logic/providers/LocalProvider.d.ts +2 -2
- package/dist/theme/components/Search/logic/search.d.ts +1 -1
- package/dist/theme/components/Search/logic/util.test.js +1 -1
- package/dist/theme/components/Sidebar/SidebarGroup.js +2 -3
- package/dist/theme/components/Sidebar/SidebarItem.js +1 -0
- package/dist/theme/components/SidebarMenu/index.js +3 -5
- package/dist/theme/components/SocialLinks/index.js +2 -3
- package/dist/theme/components/SourceCode/index.js +2 -4
- package/dist/theme/components/SwitchAppearance/index.js +3 -5
- package/dist/theme/components/Tabs/index.css +19 -27
- package/dist/theme/components/Tabs/index.js +9 -0
- package/dist/theme/components/Tag/index.d.ts +3 -0
- package/dist/theme/components/Tag/index.js +63 -8
- package/dist/theme/components/Toc/TocItem.css +2 -3
- package/dist/theme/components/Toc/TocItem.js +1 -0
- package/dist/theme/hooks/useActiveAnchor.js +1 -1
- package/dist/theme/icons.d.ts +27 -0
- package/dist/theme/icons.js +51 -0
- package/dist/theme/index.d.ts +64 -59
- package/dist/theme/index.js +7 -2
- package/dist/theme/layout/DocLayout/index.css +2 -4
- package/dist/theme/layout/Layout/index.js +1 -2
- package/dist/theme/layout/NotFountLayout/index.js +1 -1
- package/dist/theme/logic/useAppearance.js +1 -1
- package/dist/theme/logic/useFullTextSearch.d.ts +1 -1
- package/dist/theme/logic/useMediaQuery.js +1 -1
- package/dist/theme/styles/base.css +1 -0
- package/dist/theme/styles/scrollbar.css +1 -0
- package/dist/theme/styles/shiki.css +9 -3
- package/dist/theme/styles/vars/base-vars.css +7 -5
- package/dist/theme/styles/vars/code-vars.css +2 -0
- package/dist/theme/styles/vars/home-vars.css +2 -1
- package/package.json +22 -23
- package/dist/3~128.js +0 -74
- package/dist/3~517.js +0 -1786
- package/dist/3~894.js +0 -26
- package/dist/cli.js +0 -259
- package/dist/index.js.LICENSE.txt +0 -10
- package/dist/node/auto-nav-sidebar/fixtures/docs/guide/c.d.ts +0 -2
- package/dist/node/auto-nav-sidebar/fixtures/docs-locales/en/guide/c.d.ts +0 -2
- package/dist/node/auto-nav-sidebar/fixtures/docs-locales/zh/guide/c.d.ts +0 -2
- package/dist/node/auto-nav-sidebar/locales.test.d.ts +0 -1
- package/dist/node/auto-nav-sidebar/walk.test.d.ts +0 -1
- package/dist/node/mdx/rehypePlugins/headerAnchor.test.d.ts +0 -1
- package/dist/node/mdx/remarkPlugins/containerSyntax.test.d.ts +0 -1
- package/dist/node/mdx/remarkPlugins/fileCodeBlock.test.d.ts +0 -1
- package/dist/node/mdx/remarkPlugins/image.test.d.ts +0 -1
- package/dist/node/mdx/remarkPlugins/link.test.d.ts +0 -1
- package/dist/node/route/RouteService.test.d.ts +0 -1
- package/dist/node/route/extractPageData.test.d.ts +0 -1
- package/dist/node/route/fixtures/basic/guide/c.d.ts +0 -2
- package/dist/node/route/normalizeRoutePath.test.d.ts +0 -1
- package/dist/node/runtimeModule/i18n.test.d.ts +0 -1
- package/dist/node/ssg-md/remarkSplitMdx.test.d.ts +0 -4
- package/dist/node/utils/checkLanguageParity.test.d.ts +0 -1
- package/dist/node/utils/detectCustomIcon.d.ts +0 -1
- package/dist/node/utils/detectReactVersion.d.ts +0 -3
- package/dist/processor.js +0 -4539
- package/dist/renderPageWorker.js +0 -196
- package/dist/theme/components/Overview/OverviewGroup.js +0 -58
- package/dist/theme/components/Search/logic/util.test.d.ts +0 -1
- /package/dist/cli/{config.d.ts → config/index.d.ts} +0 -0
- /package/dist/eject-theme/components/{Overview → OverviewGroup}/icons/plugin.svg +0 -0
- /package/dist/{shiki-transformers.js.LICENSE.txt → node/mdx/rehypePlugins/transformers/meta-highlight.js.LICENSE.txt} +0 -0
- /package/dist/theme/components/{DocContent/FallbackHeading.d.ts → FallbackHeading/index.d.ts} +0 -0
- /package/dist/theme/components/{Overview → OverviewGroup}/icons/plugin.js +0 -0
package/dist/index.js
CHANGED
|
@@ -1,3134 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
import { compile } from "@rspress/mdx-rs";
|
|
18
|
-
import { htmlToText } from "html-to-text";
|
|
19
|
-
import { createProcessor } from "@mdx-js/mdx";
|
|
20
|
-
import { mergeRsbuildConfig as core_mergeRsbuildConfig, rspack as core_rspack } from "@rsbuild/core";
|
|
21
|
-
import { createHash } from "node:crypto";
|
|
22
|
-
import { createHead, transformHtmlTemplate } from "@unhead/react/server";
|
|
23
|
-
import { visit } from "unist-util-visit";
|
|
24
|
-
var __webpack_modules__ = {
|
|
25
|
-
"@rspress/shared": function(module) {
|
|
26
|
-
module.exports = __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__;
|
|
27
|
-
},
|
|
28
|
-
"node:fs": function(module) {
|
|
29
|
-
module.exports = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__;
|
|
30
|
-
},
|
|
31
|
-
"node:os": function(module) {
|
|
32
|
-
module.exports = __WEBPACK_EXTERNAL_MODULE_node_os_74b4b876__;
|
|
33
|
-
},
|
|
34
|
-
"node:path": function(module) {
|
|
35
|
-
module.exports = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__;
|
|
36
|
-
},
|
|
37
|
-
"node:url": function(module) {
|
|
38
|
-
module.exports = __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__;
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
var __webpack_module_cache__ = {};
|
|
42
|
-
function __webpack_require__(moduleId) {
|
|
43
|
-
var cachedModule = __webpack_module_cache__[moduleId];
|
|
44
|
-
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
45
|
-
var module = __webpack_module_cache__[moduleId] = {
|
|
46
|
-
exports: {}
|
|
47
|
-
};
|
|
48
|
-
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
49
|
-
return module.exports;
|
|
50
|
-
}
|
|
51
|
-
__webpack_require__.m = __webpack_modules__;
|
|
52
|
-
(()=>{
|
|
53
|
-
__webpack_require__.d = (exports, definition)=>{
|
|
54
|
-
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) Object.defineProperty(exports, key, {
|
|
55
|
-
enumerable: true,
|
|
56
|
-
get: definition[key]
|
|
57
|
-
});
|
|
58
|
-
};
|
|
59
|
-
})();
|
|
60
|
-
(()=>{
|
|
61
|
-
__webpack_require__.f = {};
|
|
62
|
-
__webpack_require__.e = (chunkId)=>Promise.all(Object.keys(__webpack_require__.f).reduce((promises, key)=>{
|
|
63
|
-
__webpack_require__.f[key](chunkId, promises);
|
|
64
|
-
return promises;
|
|
65
|
-
}, []));
|
|
66
|
-
})();
|
|
67
|
-
(()=>{
|
|
68
|
-
__webpack_require__.u = (chunkId)=>"3~" + chunkId + ".js";
|
|
69
|
-
})();
|
|
70
|
-
(()=>{
|
|
71
|
-
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
72
|
-
})();
|
|
73
|
-
(()=>{
|
|
74
|
-
var installedChunks = {
|
|
75
|
-
410: 0
|
|
76
|
-
};
|
|
77
|
-
var installChunk = (data)=>{
|
|
78
|
-
var __webpack_ids__ = data.__webpack_ids__;
|
|
79
|
-
var __webpack_modules__ = data.__webpack_modules__;
|
|
80
|
-
var __webpack_runtime__ = data.__webpack_runtime__;
|
|
81
|
-
var moduleId, chunkId, i = 0;
|
|
82
|
-
for(moduleId in __webpack_modules__)if (__webpack_require__.o(__webpack_modules__, moduleId)) __webpack_require__.m[moduleId] = __webpack_modules__[moduleId];
|
|
83
|
-
if (__webpack_runtime__) __webpack_runtime__(__webpack_require__);
|
|
84
|
-
for(; i < __webpack_ids__.length; i++){
|
|
85
|
-
chunkId = __webpack_ids__[i];
|
|
86
|
-
if (__webpack_require__.o(installedChunks, chunkId) && installedChunks[chunkId]) installedChunks[chunkId][0]();
|
|
87
|
-
installedChunks[__webpack_ids__[i]] = 0;
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
__webpack_require__.f.j = function(chunkId, promises) {
|
|
91
|
-
var installedChunkData = __webpack_require__.o(installedChunks, chunkId) ? installedChunks[chunkId] : void 0;
|
|
92
|
-
if (0 !== installedChunkData) if (installedChunkData) promises.push(installedChunkData[1]);
|
|
93
|
-
else {
|
|
94
|
-
var promise = import("./" + __webpack_require__.u(chunkId)).then(installChunk, (e)=>{
|
|
95
|
-
if (0 !== installedChunks[chunkId]) installedChunks[chunkId] = void 0;
|
|
96
|
-
throw e;
|
|
97
|
-
});
|
|
98
|
-
var promise = Promise.race([
|
|
99
|
-
promise,
|
|
100
|
-
new Promise((resolve)=>{
|
|
101
|
-
installedChunkData = installedChunks[chunkId] = [
|
|
102
|
-
resolve
|
|
103
|
-
];
|
|
104
|
-
})
|
|
105
|
-
]);
|
|
106
|
-
promises.push(installedChunkData[1] = promise);
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
})();
|
|
110
|
-
var shared_ = __webpack_require__("@rspress/shared");
|
|
111
|
-
function defineConfig(config) {
|
|
112
|
-
return config;
|
|
113
|
-
}
|
|
114
|
-
var external_node_path_ = __webpack_require__("node:path");
|
|
115
|
-
async function pathExists(path) {
|
|
116
|
-
try {
|
|
117
|
-
await node_fs_promises.access(path);
|
|
118
|
-
return true;
|
|
119
|
-
} catch {
|
|
120
|
-
return false;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
async function readJson(path) {
|
|
124
|
-
const raw = await node_fs_promises.readFile(path, 'utf8');
|
|
125
|
-
return JSON.parse(raw);
|
|
126
|
-
}
|
|
127
|
-
const THEME_DEFAULT_EXPORT_PATTERN = /export\s+default\s+\{/;
|
|
128
|
-
async function hintThemeBreakingChange(customThemeDir) {
|
|
129
|
-
const fileList = [
|
|
130
|
-
'index.ts',
|
|
131
|
-
'index.tsx',
|
|
132
|
-
'index.js',
|
|
133
|
-
'index.mjs'
|
|
134
|
-
];
|
|
135
|
-
let useDefaultExportFilePath = null;
|
|
136
|
-
for (const file of fileList){
|
|
137
|
-
const filePath = (0, external_node_path_.join)(customThemeDir, file);
|
|
138
|
-
if (await pathExists(filePath)) {
|
|
139
|
-
const content = await readFile(filePath, {
|
|
140
|
-
encoding: 'utf-8'
|
|
141
|
-
});
|
|
142
|
-
if (THEME_DEFAULT_EXPORT_PATTERN.test(content)) useDefaultExportFilePath = filePath;
|
|
143
|
-
break;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
if (useDefaultExportFilePath) logger.warn(`[Rspress v2] Breaking Change: The "theme/index.tsx" is now using named export instead of default export, please update ${picocolors.greenBright(useDefaultExportFilePath)} (https://github.com/web-infra-dev/rspress/discussions/1891#discussioncomment-12422737).\n`, picocolors.redBright(`
|
|
147
|
-
- import Theme from '@rspress/core/theme';
|
|
148
|
-
- export default {
|
|
149
|
-
- ...Theme,
|
|
150
|
-
- Layout,
|
|
151
|
-
- };
|
|
152
|
-
- export * from '@rspress/core/theme';`) + picocolors.greenBright(`
|
|
153
|
-
+ import { Layout } from '@rspress/core/theme';
|
|
154
|
-
|
|
155
|
-
+ export { Layout };
|
|
156
|
-
+ export * from '@rspress/core/theme';
|
|
157
|
-
`));
|
|
158
|
-
}
|
|
159
|
-
function hintBuilderPluginsBreakingChange(config) {
|
|
160
|
-
if ('builderPlugins' in config && Array.isArray(config.builderPlugins) && config.builderPlugins.length > 0) {
|
|
161
|
-
logger.error(`[Rspress v2] The "builderPlugins" option has been renamed to "builderConfig.plugins", please update your config accordingly (https://rspress.rs/api/config/config-build#builderconfigplugins).\n`, `
|
|
162
|
-
export default defineConfig({
|
|
163
|
-
${picocolors.redBright(` builderPlugins: [
|
|
164
|
-
pluginFoo()
|
|
165
|
-
],`)}
|
|
166
|
-
${picocolors.greenBright(` builderConfig: {
|
|
167
|
-
plugins: [
|
|
168
|
-
pluginFoo()
|
|
169
|
-
],
|
|
170
|
-
},`)}
|
|
171
|
-
});`);
|
|
172
|
-
process.exit(1);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
function hintSSGFailed() {
|
|
176
|
-
logger.info(`[Rspress v2] \`ssg: true\` requires the source code to support SSR. If the code is not compatible to SSR, the build process will fail. You can try:
|
|
177
|
-
1. Fix code to make it SSR-compatible.
|
|
178
|
-
2. Set \`ssg: false\` if the code in node_modules may be difficult to fix, but the SSG feature will be lost.`);
|
|
179
|
-
}
|
|
180
|
-
function hintSSGFalse() {
|
|
181
|
-
logger.info('`ssg: false` detected, SSG will be disabled.');
|
|
182
|
-
}
|
|
183
|
-
function hintReactVersion() {
|
|
184
|
-
logger.info('[Rspress v2] Rspress support React 18 and 19, please confirm that both react and react-dom are installed in package.json with the same version. ');
|
|
185
|
-
}
|
|
186
|
-
function hintNavJsonChangeThenPanic(metaJson, metaJsonDir, docsDir) {
|
|
187
|
-
if (metaJson.some((i)=>'object' == typeof i && ('activeMatch' in i || 'text' in i || 'link' in i || 'items' in i || 'icon' in i || 'ariaLabel' in i || 'target' in i))) {
|
|
188
|
-
const error = new Error('[Rspress v2] Detected that you are still using top level `_meta.json` to configure the nav, but it has been changed to `_nav.json` in Rspress v2. Please rename the top level `_meta.json` to `_nav.json` accordingly.');
|
|
189
|
-
logger.error(error);
|
|
190
|
-
const dir = (0, external_node_path_.relative)(docsDir, metaJsonDir);
|
|
191
|
-
logger.info(`Please rename "${picocolors.greenBright((0, external_node_path_.join)(dir, '_meta.json'))}" to "${picocolors.greenBright((0, external_node_path_.join)(dir, '_nav.json'))}".`);
|
|
192
|
-
process.exit(1);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
let isLogged = false;
|
|
196
|
-
function hintRelativeMarkdownLink() {
|
|
197
|
-
if (isLogged) return;
|
|
198
|
-
isLogged = true;
|
|
199
|
-
logger.info('[Rspress v2] Markdown links without "./" prefix are now relative links, e.g: [](guide/getting-started) is equal to [](./guide/getting-started). You can rewrite it to [](/guide/getting-started) to always use absolute links, or use [](./getting-started.md)');
|
|
200
|
-
}
|
|
201
|
-
function getPageKey(route) {
|
|
202
|
-
const cleanRoute = (0, shared_.removeLeadingSlash)(route);
|
|
203
|
-
return cleanRoute.replace(/\//g, '_').replace(/\.[^.]+$/, '') || 'index';
|
|
204
|
-
}
|
|
205
|
-
var external_node_os_ = __webpack_require__("node:os");
|
|
206
|
-
const isWindows = 'win32' === external_node_os_["default"].platform();
|
|
207
|
-
function slash(p) {
|
|
208
|
-
return p.replace(/\\/g, '/');
|
|
209
|
-
}
|
|
210
|
-
function normalizePath(id) {
|
|
211
|
-
return external_node_path_["default"].posix.normalize(isWindows ? slash(id) : id);
|
|
212
|
-
}
|
|
213
|
-
var external_node_url_ = __webpack_require__("node:url");
|
|
214
|
-
var package_namespaceObject = {
|
|
215
|
-
rE: "2.0.0-rc.1"
|
|
216
|
-
};
|
|
217
|
-
const RSPRESS_VERSION = package_namespaceObject.rE;
|
|
218
|
-
const APPEARANCE_KEY = 'rspress-theme-appearance';
|
|
219
|
-
const isProduction = ()=>'production' === process.env.NODE_ENV;
|
|
220
|
-
const importStatementRegex = /import\s+(.*?)\s+from\s+(['"])(.*?)(?:"|');?/gm;
|
|
221
|
-
const inlineThemeScript = `{
|
|
222
|
-
const saved = localStorage.getItem('${APPEARANCE_KEY}')
|
|
223
|
-
const preferDark = window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
224
|
-
const isDark = !saved || saved === 'auto' ? preferDark : saved === 'dark'
|
|
225
|
-
document.documentElement.classList.toggle('dark', isDark)
|
|
226
|
-
document.documentElement.classList.toggle('rp-dark', isDark)
|
|
227
|
-
document.documentElement.style.colorScheme = isDark ? 'dark' : 'light'
|
|
228
|
-
}`.replace(/\n/g, ';').replace(/\s{2,}/g, '');
|
|
229
|
-
const dirname = external_node_path_["default"].dirname((0, external_node_url_.fileURLToPath)(new URL(import.meta.url)));
|
|
230
|
-
const PACKAGE_ROOT = external_node_path_["default"].join(dirname, '..');
|
|
231
|
-
const TEMPLATE_PATH = external_node_path_["default"].join(PACKAGE_ROOT, 'index.html');
|
|
232
|
-
const CSR_CLIENT_ENTRY = external_node_path_["default"].join(PACKAGE_ROOT, 'dist', 'runtime', 'csrClientEntry.js');
|
|
233
|
-
const SSR_CLIENT_ENTRY = external_node_path_["default"].join(PACKAGE_ROOT, 'dist', 'runtime', 'ssrClientEntry.js');
|
|
234
|
-
const SSR_SERVER_ENTRY = external_node_path_["default"].join(PACKAGE_ROOT, 'dist', 'runtime', 'ssrServerEntry.js');
|
|
235
|
-
const SSG_MD_SERVER_ENTRY = external_node_path_["default"].join(PACKAGE_ROOT, 'dist', 'runtime', 'ssrMdServerEntry.js');
|
|
236
|
-
const OUTPUT_DIR = 'doc_build';
|
|
237
|
-
const APP_HTML_MARKER = '<!--<?- DOC_CONTENT ?>-->';
|
|
238
|
-
const HEAD_MARKER = '<!--<?- HEAD ?>-->';
|
|
239
|
-
const META_GENERATOR = '<!--<?- GENERATOR ?>-->';
|
|
240
|
-
const DEFAULT_TITLE = 'Rspress';
|
|
241
|
-
const PUBLIC_DIR = 'public';
|
|
242
|
-
const NODE_SSG_BUNDLE_FOLDER = '__ssg__';
|
|
243
|
-
const NODE_SSG_BUNDLE_NAME = 'rspress-ssg-entry.cjs';
|
|
244
|
-
const NODE_SSG_MD_BUNDLE_FOLDER = '__ssg_md__';
|
|
245
|
-
const NODE_SSG_MD_BUNDLE_NAME = 'rspress-ssg-md-entry.cjs';
|
|
246
|
-
const getRoutePathParts = (relativePath, lang, version, langs, versions)=>{
|
|
247
|
-
const [versionPart, langPart, purePath] = splitRoutePathParts(relativePath, lang, version, langs, versions);
|
|
248
|
-
return [
|
|
249
|
-
versionPart === version ? '' : versionPart,
|
|
250
|
-
langPart === lang ? '' : langPart,
|
|
251
|
-
purePath
|
|
252
|
-
];
|
|
253
|
-
};
|
|
254
|
-
const splitRoutePathParts = (relativePath, lang, version, langs, versions)=>{
|
|
255
|
-
const hasTrailSlash = relativePath.endsWith('/');
|
|
256
|
-
let versionPart = '';
|
|
257
|
-
let langPart = '';
|
|
258
|
-
let purePathPart = '';
|
|
259
|
-
const parts = relativePath.split('/').filter(Boolean);
|
|
260
|
-
if (version) {
|
|
261
|
-
const versionToMatch = parts[0];
|
|
262
|
-
if (versions.includes(versionToMatch)) versionPart = parts.shift() ?? '';
|
|
263
|
-
}
|
|
264
|
-
if (lang) {
|
|
265
|
-
const langToMatch = parts[0];
|
|
266
|
-
if (langs.includes(langToMatch)) langPart = parts.shift() ?? '';
|
|
267
|
-
}
|
|
268
|
-
purePathPart = parts.join('/');
|
|
269
|
-
return [
|
|
270
|
-
versionPart,
|
|
271
|
-
langPart,
|
|
272
|
-
hasTrailSlash ? (0, shared_.addTrailingSlash)(purePathPart) : purePathPart
|
|
273
|
-
];
|
|
274
|
-
};
|
|
275
|
-
const normalizeRoutePath = (relativePath, lang, version, langs, versions, extensions = DEFAULT_PAGE_EXTENSIONS)=>{
|
|
276
|
-
const extensionsWithoutDot = extensions.map((i)=>i.slice(1));
|
|
277
|
-
const cleanExtensionPattern = new RegExp(`\\.(${extensionsWithoutDot.join('|')})$`, 'i');
|
|
278
|
-
let routePath = relativePath.replace(cleanExtensionPattern, '').replace(/\.html$/, '');
|
|
279
|
-
if (routePath.endsWith('/')) routePath = `${routePath}index`;
|
|
280
|
-
const [versionPart, langPart, purePathPart] = getRoutePathParts(routePath, lang, version, langs, versions);
|
|
281
|
-
routePath = purePathPart.replace(/\/index$/, '/');
|
|
282
|
-
if ('index' === routePath) routePath = '';
|
|
283
|
-
const normalizedRoutePath = (0, shared_.addLeadingSlash)([
|
|
284
|
-
...[
|
|
285
|
-
versionPart,
|
|
286
|
-
langPart
|
|
287
|
-
].filter(Boolean),
|
|
288
|
-
routePath
|
|
289
|
-
].join('/'));
|
|
290
|
-
return {
|
|
291
|
-
pureRoutePath: `/${routePath}`,
|
|
292
|
-
routePath: normalizedRoutePath,
|
|
293
|
-
lang: langPart || lang,
|
|
294
|
-
version: versionPart || version
|
|
295
|
-
};
|
|
296
|
-
};
|
|
297
|
-
class RouteService {
|
|
298
|
-
routeData = new Map();
|
|
299
|
-
#scanDir;
|
|
300
|
-
#defaultLang;
|
|
301
|
-
#defaultVersion;
|
|
302
|
-
#extensions;
|
|
303
|
-
#langs;
|
|
304
|
-
#versions;
|
|
305
|
-
#include;
|
|
306
|
-
#exclude;
|
|
307
|
-
#excludeConvention;
|
|
308
|
-
#tempDir;
|
|
309
|
-
#externalPages;
|
|
310
|
-
static __instance__ = null;
|
|
311
|
-
static getInstance() {
|
|
312
|
-
return RouteService.__instance__;
|
|
313
|
-
}
|
|
314
|
-
static async create(options) {
|
|
315
|
-
const { scanDir, config, externalPages } = options;
|
|
316
|
-
const runtimeAbsTempDir = external_node_path_["default"].join(process.cwd(), 'node_modules', shared_.RSPRESS_TEMP_DIR, 'runtime');
|
|
317
|
-
await node_fs_promises.mkdir(runtimeAbsTempDir, {
|
|
318
|
-
recursive: true
|
|
319
|
-
});
|
|
320
|
-
const routeService = new RouteService(scanDir, config, externalPages || [], runtimeAbsTempDir);
|
|
321
|
-
RouteService.__instance__ = routeService;
|
|
322
|
-
await routeService.#init();
|
|
323
|
-
return routeService;
|
|
324
|
-
}
|
|
325
|
-
static async createSimple() {
|
|
326
|
-
return new RouteService('', {}, [], '');
|
|
327
|
-
}
|
|
328
|
-
constructor(scanDir, userConfig, externalPages, runtimeAbsTempDir){
|
|
329
|
-
const routeOptions = userConfig?.route || {};
|
|
330
|
-
this.#scanDir = scanDir;
|
|
331
|
-
this.#extensions = routeOptions.extensions || DEFAULT_PAGE_EXTENSIONS;
|
|
332
|
-
this.#include = routeOptions.include || [];
|
|
333
|
-
this.#exclude = routeOptions.exclude || [];
|
|
334
|
-
this.#excludeConvention = routeOptions.excludeConvention || [
|
|
335
|
-
'**/_[^_]*'
|
|
336
|
-
];
|
|
337
|
-
this.#defaultLang = userConfig?.lang || '';
|
|
338
|
-
this.#langs = (userConfig?.locales ?? userConfig?.themeConfig?.locales ?? []).map((item)=>item.lang);
|
|
339
|
-
this.#tempDir = runtimeAbsTempDir;
|
|
340
|
-
this.#externalPages = externalPages;
|
|
341
|
-
if (userConfig.multiVersion) {
|
|
342
|
-
this.#defaultVersion = userConfig.multiVersion.default || '';
|
|
343
|
-
this.#versions = userConfig.multiVersion.versions || [];
|
|
344
|
-
} else {
|
|
345
|
-
this.#defaultVersion = '';
|
|
346
|
-
this.#versions = [];
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
get extensions() {
|
|
350
|
-
return this.#extensions;
|
|
351
|
-
}
|
|
352
|
-
async #init() {
|
|
353
|
-
const extensions = this.#extensions.map((i)=>i.slice(1));
|
|
354
|
-
const files = (await glob([
|
|
355
|
-
`**/*.{${extensions.join(',')}}`,
|
|
356
|
-
...this.#include
|
|
357
|
-
], {
|
|
358
|
-
cwd: this.#scanDir,
|
|
359
|
-
absolute: true,
|
|
360
|
-
onlyFiles: true,
|
|
361
|
-
ignore: [
|
|
362
|
-
...this.#exclude,
|
|
363
|
-
...this.#excludeConvention,
|
|
364
|
-
'**/node_modules/**',
|
|
365
|
-
'**/.eslintrc.js',
|
|
366
|
-
'**/.nx/**',
|
|
367
|
-
`./${PUBLIC_DIR}/**`,
|
|
368
|
-
'**/*.d.ts'
|
|
369
|
-
]
|
|
370
|
-
})).sort();
|
|
371
|
-
files.forEach((filePath)=>{
|
|
372
|
-
const routePage = RoutePage.create(filePath, this.#scanDir);
|
|
373
|
-
this.addRoute(routePage);
|
|
374
|
-
});
|
|
375
|
-
const externalPages = this.#externalPages;
|
|
376
|
-
await Promise.all(externalPages.map(async (route, index)=>{
|
|
377
|
-
const { routePath, content, filepath } = route;
|
|
378
|
-
if (filepath) {
|
|
379
|
-
const routePage = RoutePage.createFromExternal(routePath, filepath, this.#scanDir);
|
|
380
|
-
this.addRoute(routePage);
|
|
381
|
-
return;
|
|
382
|
-
}
|
|
383
|
-
if (content) {
|
|
384
|
-
const filepath = await this.#writeTempFile(index, content);
|
|
385
|
-
const routePage = RoutePage.createFromExternal(routePath, filepath, this.#scanDir);
|
|
386
|
-
this.addRoute(routePage);
|
|
387
|
-
}
|
|
388
|
-
}));
|
|
389
|
-
}
|
|
390
|
-
async addRoute(routePage) {
|
|
391
|
-
const { routeMeta: { routePath } } = routePage;
|
|
392
|
-
if (this.routeData.has(routePath)) throw new Error(`routePath ${routePath} has already been added`);
|
|
393
|
-
this.routeData.set(routePath, routePage);
|
|
394
|
-
}
|
|
395
|
-
getRoutes() {
|
|
396
|
-
return Array.from(this.routeData.values()).map((i)=>i.routeMeta);
|
|
397
|
-
}
|
|
398
|
-
getRoutePages() {
|
|
399
|
-
return Array.from(this.routeData.values());
|
|
400
|
-
}
|
|
401
|
-
isExistRoute(link) {
|
|
402
|
-
function linkToRoutePath(routePath) {
|
|
403
|
-
return decodeURIComponent(routePath.split('#')[0]).replace(/\.html$/, '').replace(/\/index$/, '/');
|
|
404
|
-
}
|
|
405
|
-
const cleanLinkPath = linkToRoutePath(link);
|
|
406
|
-
if (!this.routeData.has((0, shared_.removeTrailingSlash)(cleanLinkPath)) && !this.routeData.has((0, shared_.addTrailingSlash)(cleanLinkPath))) return false;
|
|
407
|
-
return true;
|
|
408
|
-
}
|
|
409
|
-
generateRoutesCode() {
|
|
410
|
-
return this.generateRoutesCodeByRouteMeta(this.getRoutes());
|
|
411
|
-
}
|
|
412
|
-
generateRoutesCodeByRouteMeta(routeMeta) {
|
|
413
|
-
return `
|
|
414
|
-
import React from 'react';
|
|
415
|
-
import { lazyWithPreload } from "react-lazy-with-preload";
|
|
416
|
-
${routeMeta.map((route, index)=>`const Route${index} = lazyWithPreload(() => import('${route.absolutePath}'))`).join('\n')}
|
|
417
|
-
export const routes = [
|
|
418
|
-
${routeMeta.map((route, index)=>{
|
|
419
|
-
const preload = `async () => {
|
|
420
|
-
await Route${index}.preload();
|
|
421
|
-
return import("${route.absolutePath}");
|
|
422
|
-
}`;
|
|
423
|
-
const component = `Route${index}`;
|
|
424
|
-
return `{ path: '${route.routePath}', element: React.createElement(${component}), filePath: '${route.relativePath}', preload: ${preload}, lang: '${route.lang}', version: '${route.version}' }`;
|
|
425
|
-
}).join(',\n')}
|
|
426
|
-
];
|
|
427
|
-
`;
|
|
428
|
-
}
|
|
429
|
-
getRoutePathParts(relativePath) {
|
|
430
|
-
return getRoutePathParts(relativePath, this.#defaultLang, this.#defaultVersion, this.#langs, this.#versions);
|
|
431
|
-
}
|
|
432
|
-
splitRoutePathParts(relativePath) {
|
|
433
|
-
return splitRoutePathParts(relativePath, this.#defaultLang, this.#defaultVersion, this.#langs, this.#versions);
|
|
434
|
-
}
|
|
435
|
-
normalizeRoutePath(relativePath) {
|
|
436
|
-
return normalizeRoutePath(relativePath, this.#defaultLang, this.#defaultVersion, this.#langs, this.#versions, this.#extensions);
|
|
437
|
-
}
|
|
438
|
-
absolutePathToRoutePath(absolutePath) {
|
|
439
|
-
return absolutePathToRoutePath(absolutePath, this.#scanDir, this);
|
|
440
|
-
}
|
|
441
|
-
isInDocsDir(absolutePath) {
|
|
442
|
-
const relativePath = external_node_path_["default"].relative(this.#scanDir, absolutePath);
|
|
443
|
-
return !relativePath.startsWith('..') && !external_node_path_["default"].isAbsolute(relativePath);
|
|
444
|
-
}
|
|
445
|
-
absolutePathToRelativePath(absolutePath) {
|
|
446
|
-
return absolutePathToRelativePath(absolutePath, this.#scanDir);
|
|
447
|
-
}
|
|
448
|
-
async #writeTempFile(index, content) {
|
|
449
|
-
const tempFilePath = external_node_path_["default"].join(this.#tempDir, `temp-${index}.mdx`);
|
|
450
|
-
await node_fs_promises.writeFile(tempFilePath, content);
|
|
451
|
-
return tempFilePath;
|
|
452
|
-
}
|
|
453
|
-
getRoutePageByRoutePath(routePath) {
|
|
454
|
-
return this.routeData.get(routePath);
|
|
455
|
-
}
|
|
456
|
-
getDocsDir() {
|
|
457
|
-
return this.#scanDir;
|
|
458
|
-
}
|
|
459
|
-
getLangs() {
|
|
460
|
-
return this.#langs;
|
|
461
|
-
}
|
|
462
|
-
getDefaultLang() {
|
|
463
|
-
return this.#defaultLang;
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
class RoutePage {
|
|
467
|
-
routeMeta;
|
|
468
|
-
#docDir;
|
|
469
|
-
static create(absolutePath, docsDir) {
|
|
470
|
-
const routeMeta = absolutePathToRouteMeta(absolutePath, docsDir, RouteService.getInstance());
|
|
471
|
-
return new RoutePage(routeMeta, docsDir);
|
|
472
|
-
}
|
|
473
|
-
static createFromExternal(routePath, filepath, docDir) {
|
|
474
|
-
const routeMeta = RoutePage.generateRouteMeta(routePath, filepath, docDir);
|
|
475
|
-
return new RoutePage(routeMeta, external_node_path_["default"].dirname(filepath));
|
|
476
|
-
}
|
|
477
|
-
constructor(routeMeta, docDir){
|
|
478
|
-
this.routeMeta = routeMeta;
|
|
479
|
-
this.#docDir = docDir;
|
|
480
|
-
}
|
|
481
|
-
static generateRouteMeta(routePath, filepath, docDir) {
|
|
482
|
-
const routeService = RouteService.getInstance();
|
|
483
|
-
const { routePath: normalizedPath, lang, version } = routeService.normalizeRoutePath(routePath);
|
|
484
|
-
return {
|
|
485
|
-
routePath: normalizedPath,
|
|
486
|
-
absolutePath: normalizePath(filepath),
|
|
487
|
-
relativePath: absolutePathToRelativePath(filepath, docDir),
|
|
488
|
-
pageName: getPageKey(routePath),
|
|
489
|
-
lang,
|
|
490
|
-
version
|
|
491
|
-
};
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
function absolutePathToRelativePath(absolutePath, docsDir) {
|
|
495
|
-
return slash(external_node_path_["default"].relative(docsDir, absolutePath));
|
|
496
|
-
}
|
|
497
|
-
function absolutePathToRouteMeta(absolutePath, docsDir, routeService = RouteService.getInstance()) {
|
|
498
|
-
const relativePath = absolutePathToRelativePath(absolutePath, docsDir);
|
|
499
|
-
const { lang, routePath, version } = routeService.normalizeRoutePath(relativePath);
|
|
500
|
-
return {
|
|
501
|
-
pageName: getPageKey(relativePath),
|
|
502
|
-
absolutePath,
|
|
503
|
-
lang,
|
|
504
|
-
version,
|
|
505
|
-
routePath,
|
|
506
|
-
relativePath
|
|
507
|
-
};
|
|
508
|
-
}
|
|
509
|
-
function absolutePathToRoutePath(absolutePath, docsDir, routeService = RouteService.getInstance()) {
|
|
510
|
-
return absolutePathToRouteMeta(absolutePath, docsDir, routeService).routePath;
|
|
511
|
-
}
|
|
512
|
-
function absolutePathToRoutePrefix(absolutePath, docsDir) {
|
|
513
|
-
const relativePath = slash(external_node_path_["default"].relative(docsDir, absolutePath.replace(external_node_path_["default"].extname(absolutePath), '')));
|
|
514
|
-
const routeService = RouteService.getInstance();
|
|
515
|
-
const [versionPrefix, langPrefix] = routeService.getRoutePathParts(relativePath);
|
|
516
|
-
return `${versionPrefix ? `/${versionPrefix}` : ''}${langPrefix ? `/${langPrefix}` : ''}`;
|
|
517
|
-
}
|
|
518
|
-
function addRoutePrefix(workDir, docsDir, link) {
|
|
519
|
-
const routePrefix = absolutePathToRoutePrefix(workDir, docsDir);
|
|
520
|
-
return `${routePrefix.replace(/\/$/, '')}/${link.replace(/^\//, '')}`;
|
|
521
|
-
}
|
|
522
|
-
async function utils_pathExists(path) {
|
|
523
|
-
try {
|
|
524
|
-
await node_fs_promises.access(path);
|
|
525
|
-
return true;
|
|
526
|
-
} catch {
|
|
527
|
-
return false;
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
async function utils_readJson(path) {
|
|
531
|
-
const raw = await node_fs_promises.readFile(path, 'utf8');
|
|
532
|
-
return JSON.parse(raw);
|
|
533
|
-
}
|
|
534
|
-
async function extractInfoFromFrontmatterWithAbsolutePath(absolutePath, rootDir) {
|
|
535
|
-
const fileHandle = await node_fs_promises.open(absolutePath, 'r');
|
|
536
|
-
try {
|
|
537
|
-
const buffer = Buffer.alloc(2048);
|
|
538
|
-
let content = '';
|
|
539
|
-
let bytesRead = 0;
|
|
540
|
-
let hasFrontmatter = false;
|
|
541
|
-
let frontmatterEnd = -1;
|
|
542
|
-
let h1Match = null;
|
|
543
|
-
let frontmatter = {};
|
|
544
|
-
do {
|
|
545
|
-
const result = await fileHandle.read(buffer, 0, buffer.length, bytesRead);
|
|
546
|
-
if (0 === result.bytesRead) break;
|
|
547
|
-
content += buffer.subarray(0, result.bytesRead).toString('utf-8');
|
|
548
|
-
bytesRead += result.bytesRead;
|
|
549
|
-
if (bytesRead <= buffer.length) if (content.startsWith('---')) {
|
|
550
|
-
hasFrontmatter = true;
|
|
551
|
-
const secondDelimiter = content.indexOf('\n---\n', 4);
|
|
552
|
-
if (-1 !== secondDelimiter) {
|
|
553
|
-
frontmatterEnd = secondDelimiter + 5;
|
|
554
|
-
const { frontmatter: fm } = loadFrontMatter(content.slice(0, frontmatterEnd + 100), absolutePath, rootDir);
|
|
555
|
-
frontmatter = fm;
|
|
556
|
-
}
|
|
557
|
-
} else hasFrontmatter = false;
|
|
558
|
-
if (!h1Match) {
|
|
559
|
-
const searchStart = hasFrontmatter && frontmatterEnd > -1 ? frontmatterEnd : 0;
|
|
560
|
-
const h1RegExp = /^#\s+(.*?)\n$/m;
|
|
561
|
-
h1Match = content.slice(searchStart).match(h1RegExp);
|
|
562
|
-
}
|
|
563
|
-
if (hasFrontmatter && frontmatterEnd > -1 && h1Match) break;
|
|
564
|
-
if (!hasFrontmatter && h1Match) break;
|
|
565
|
-
if (hasFrontmatter && frontmatterEnd > -1 && bytesRead > 16384) break;
|
|
566
|
-
}while (bytesRead < 65536);
|
|
567
|
-
if (hasFrontmatter && -1 === frontmatterEnd) {
|
|
568
|
-
const { frontmatter: fm } = loadFrontMatter(content, absolutePath, rootDir);
|
|
569
|
-
frontmatter = fm;
|
|
570
|
-
}
|
|
571
|
-
if (!h1Match) {
|
|
572
|
-
const h1RegExp = /^#\s+(.*)$/m;
|
|
573
|
-
h1Match = content.match(h1RegExp);
|
|
574
|
-
}
|
|
575
|
-
const fileNameWithoutExt = external_node_path_["default"].basename(absolutePath, external_node_path_["default"].extname(absolutePath));
|
|
576
|
-
return {
|
|
577
|
-
title: extractTextAndId(frontmatter.title || h1Match?.[1] || fileNameWithoutExt)[0],
|
|
578
|
-
overviewHeaders: frontmatter.overviewHeaders,
|
|
579
|
-
context: frontmatter.context,
|
|
580
|
-
tag: frontmatter.tag,
|
|
581
|
-
description: frontmatter.description
|
|
582
|
-
};
|
|
583
|
-
} finally{
|
|
584
|
-
await fileHandle.close();
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
function getFileKey(realPath, docsDir) {
|
|
588
|
-
return realPath ? (0, shared_.slash)((0, external_node_path_.relative)(docsDir, realPath).replace((0, external_node_path_.extname)(realPath), '')) : '';
|
|
589
|
-
}
|
|
590
|
-
async function fsDirToMetaItems(workDir, docsDir, extensions) {
|
|
591
|
-
let subItems;
|
|
592
|
-
try {
|
|
593
|
-
subItems = await readdir(workDir);
|
|
594
|
-
} catch (e) {
|
|
595
|
-
logger.error(`Failed to read directory: ${workDir}, maybe it does not exist. Please check it in "_meta.json".`);
|
|
596
|
-
throw e;
|
|
597
|
-
}
|
|
598
|
-
subItems = subItems.filter((item)=>{
|
|
599
|
-
const hasExtension = extensions.some((ext)=>item.endsWith(ext));
|
|
600
|
-
const hasSameBaseName = subItems.some((elem)=>{
|
|
601
|
-
const baseName = elem.replace(/\.[^/.]+$/, '');
|
|
602
|
-
return baseName === item.replace(/\.[^/.]+$/, '') && elem !== item;
|
|
603
|
-
});
|
|
604
|
-
return !(hasExtension && hasSameBaseName);
|
|
605
|
-
});
|
|
606
|
-
const sideMeta = (await Promise.all(subItems.map(async (item)=>{
|
|
607
|
-
if ('_meta.json' === item) return null;
|
|
608
|
-
const stat = await promises_stat((0, external_node_path_.join)(workDir, item));
|
|
609
|
-
if (stat.isDirectory()) {
|
|
610
|
-
if ('public' === item && workDir === docsDir) return null;
|
|
611
|
-
return {
|
|
612
|
-
type: 'dir',
|
|
613
|
-
name: item
|
|
614
|
-
};
|
|
615
|
-
}
|
|
616
|
-
return extensions.some((ext)=>item.endsWith(ext)) ? item : null;
|
|
617
|
-
}))).filter(Boolean);
|
|
618
|
-
return sideMeta;
|
|
619
|
-
}
|
|
620
|
-
async function metaItemToSidebarItem(metaItem, workDir, docsDir, extensions, metaFileSet, mdFileSet) {
|
|
621
|
-
if ('string' == typeof metaItem) return metaFileItemToSidebarItem(metaItem, workDir, docsDir, extensions, mdFileSet);
|
|
622
|
-
const { type } = metaItem;
|
|
623
|
-
if ('file' === type) return metaFileItemToSidebarItem(metaItem, workDir, docsDir, extensions, mdFileSet);
|
|
624
|
-
if ('dir' === type) return metaDirItemToSidebarItem(metaItem, workDir, docsDir, extensions, metaFileSet, mdFileSet, false);
|
|
625
|
-
if ('dir-section-header' === type) return metaDirSectionHeaderItemToSidebarItem(metaItem, workDir, docsDir, extensions, metaFileSet, mdFileSet);
|
|
626
|
-
if ('custom-link' === type) return metaCustomLinkItemToSidebarItem(metaItem, workDir, docsDir);
|
|
627
|
-
if ('divider' === type) return metaDividerToSidebarItem(metaItem);
|
|
628
|
-
if ('section-header' === type) return metaSectionHeaderToSidebarItem(metaItem);
|
|
629
|
-
throw new Error(`Unknown meta item type: ${metaItem.type}, please check it in "${(0, external_node_path_.join)(workDir, '_meta.json')}".`);
|
|
630
|
-
}
|
|
631
|
-
async function detectFilePath(absolutePath, extensions) {
|
|
632
|
-
const ext = (0, external_node_path_.extname)(absolutePath);
|
|
633
|
-
if (ext && extensions.includes(ext)) return absolutePath;
|
|
634
|
-
for (const extension of extensions){
|
|
635
|
-
const realPath = absolutePath + extension;
|
|
636
|
-
if (await utils_pathExists(realPath)) return realPath;
|
|
637
|
-
}
|
|
638
|
-
throw new Error(`The file extension "${ext}" is not supported, please use one of the following extensions: ${extensions.join(', ')}`);
|
|
639
|
-
}
|
|
640
|
-
async function metaFileItemToSidebarItem(metaItemRaw, workDir, docsDir, extensions, mdFileSet) {
|
|
641
|
-
let metaItem = null;
|
|
642
|
-
metaItem = 'string' == typeof metaItemRaw ? {
|
|
643
|
-
name: metaItemRaw,
|
|
644
|
-
type: 'file'
|
|
645
|
-
} : metaItemRaw;
|
|
646
|
-
const { name, context, label, overviewHeaders, tag } = metaItem;
|
|
647
|
-
if ('string' != typeof name) throw new Error(`The file name "${name}" is not a string, please check it in "${(0, external_node_path_.join)(workDir, '_meta.json')}".`);
|
|
648
|
-
const absolutePath = (0, external_node_path_.join)(workDir, name);
|
|
649
|
-
let absolutePathWithExt;
|
|
650
|
-
try {
|
|
651
|
-
absolutePathWithExt = await detectFilePath(absolutePath, extensions);
|
|
652
|
-
} catch {
|
|
653
|
-
throw new Error(`The file "${absolutePath}" does not exist, please check it in "${(0, external_node_path_.join)(workDir, '_meta.json')}".`);
|
|
654
|
-
}
|
|
655
|
-
const link = absolutePathToRoutePath(absolutePathWithExt, docsDir);
|
|
656
|
-
const info = await extractInfoFromFrontmatterWithAbsolutePath(absolutePathWithExt, docsDir);
|
|
657
|
-
const title = label || info.title;
|
|
658
|
-
mdFileSet.add(absolutePathWithExt);
|
|
659
|
-
return {
|
|
660
|
-
text: title,
|
|
661
|
-
link,
|
|
662
|
-
tag: info.tag || tag,
|
|
663
|
-
overviewHeaders: info.overviewHeaders || overviewHeaders,
|
|
664
|
-
context: info.context || context,
|
|
665
|
-
_fileKey: getFileKey(absolutePathWithExt, docsDir)
|
|
666
|
-
};
|
|
667
|
-
}
|
|
668
|
-
async function metaDirItemToSidebarItem(metaItem, workDir, docsDir, extensions, metaFileSet, mdFileSet, forceIndexFileAsItem) {
|
|
669
|
-
const { name, label, collapsible, collapsed, tag: metaJsonTag, context: metaJsonContext, overviewHeaders: metaJsonOverviewHeaders } = metaItem;
|
|
670
|
-
const dirAbsolutePath = (0, external_node_path_.join)(workDir, name);
|
|
671
|
-
const dirMetaJsonPath = (0, external_node_path_.join)(dirAbsolutePath, '_meta.json');
|
|
672
|
-
const isMetaJsonExist = await utils_pathExists(dirMetaJsonPath);
|
|
673
|
-
let dirMetaJson = [];
|
|
674
|
-
if (isMetaJsonExist) {
|
|
675
|
-
metaFileSet.add(dirMetaJsonPath);
|
|
676
|
-
dirMetaJson = await utils_readJson(dirMetaJsonPath);
|
|
677
|
-
} else dirMetaJson = await fsDirToMetaItems(dirAbsolutePath, docsDir, extensions);
|
|
678
|
-
async function getItems(withoutIndex = false) {
|
|
679
|
-
const items = await Promise.all((withoutIndex ? dirMetaJson.filter((i)=>{
|
|
680
|
-
let name;
|
|
681
|
-
if ('object' == typeof i && 'type' in i && 'file' === i.type) name = i.name;
|
|
682
|
-
else {
|
|
683
|
-
if ('string' != typeof i) return true;
|
|
684
|
-
name = i;
|
|
685
|
-
}
|
|
686
|
-
return 'index.md' !== name && 'index.mdx' !== i && 'index' !== i;
|
|
687
|
-
}) : dirMetaJson).map((item)=>metaItemToSidebarItem(item, dirAbsolutePath, docsDir, extensions, metaFileSet, mdFileSet)));
|
|
688
|
-
return items.flat();
|
|
689
|
-
}
|
|
690
|
-
try {
|
|
691
|
-
const sameNameFile = await metaFileItemToSidebarItem(name, workDir, docsDir, extensions, mdFileSet);
|
|
692
|
-
const { link, text, _fileKey, context, overviewHeaders, tag } = sameNameFile;
|
|
693
|
-
return {
|
|
694
|
-
text: label || text || name,
|
|
695
|
-
collapsible,
|
|
696
|
-
collapsed,
|
|
697
|
-
items: await getItems(),
|
|
698
|
-
link,
|
|
699
|
-
tag: metaJsonTag || tag,
|
|
700
|
-
overviewHeaders: metaJsonOverviewHeaders || overviewHeaders,
|
|
701
|
-
context: metaJsonContext || context,
|
|
702
|
-
_fileKey
|
|
703
|
-
};
|
|
704
|
-
} catch (e) {
|
|
705
|
-
logger.debug(e);
|
|
706
|
-
const isIndexInMetaJsonIndex = dirMetaJson.find((i)=>{
|
|
707
|
-
if ('string' == typeof i) return 'index' === i.replace((0, external_node_path_.extname)(i), '');
|
|
708
|
-
return false;
|
|
709
|
-
});
|
|
710
|
-
const isIndexFileExists = await utils_pathExists((0, external_node_path_.join)(dirAbsolutePath, 'index.mdx')) || await utils_pathExists((0, external_node_path_.join)(dirAbsolutePath, 'index.md'));
|
|
711
|
-
if (isMetaJsonExist && isIndexInMetaJsonIndex || !isIndexFileExists) return {
|
|
712
|
-
text: label || name,
|
|
713
|
-
collapsible,
|
|
714
|
-
collapsed,
|
|
715
|
-
items: await getItems(),
|
|
716
|
-
overviewHeaders: metaJsonOverviewHeaders,
|
|
717
|
-
context: metaJsonContext,
|
|
718
|
-
_fileKey: getFileKey(dirAbsolutePath, docsDir)
|
|
719
|
-
};
|
|
720
|
-
{
|
|
721
|
-
const indexFile = await metaFileItemToSidebarItem('index', dirAbsolutePath, docsDir, extensions, mdFileSet);
|
|
722
|
-
const { link, text, _fileKey, context, overviewHeaders, tag } = indexFile;
|
|
723
|
-
return {
|
|
724
|
-
text: label || text || name,
|
|
725
|
-
collapsible,
|
|
726
|
-
collapsed,
|
|
727
|
-
items: await getItems(!forceIndexFileAsItem),
|
|
728
|
-
link,
|
|
729
|
-
tag: metaJsonTag || tag,
|
|
730
|
-
overviewHeaders: metaJsonOverviewHeaders || overviewHeaders,
|
|
731
|
-
context: metaJsonContext || context,
|
|
732
|
-
_fileKey
|
|
733
|
-
};
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
async function metaDirSectionHeaderItemToSidebarItem(metaItem, workDir, docsDir, extensions, metaFileSet, mdFileSet) {
|
|
738
|
-
const fakeDirMetaItem = {
|
|
739
|
-
...metaItem,
|
|
740
|
-
type: 'dir'
|
|
741
|
-
};
|
|
742
|
-
const fakeSectionHeaderMetaItem = {
|
|
743
|
-
label: metaItem.label,
|
|
744
|
-
tag: metaItem.tag,
|
|
745
|
-
type: 'section-header'
|
|
746
|
-
};
|
|
747
|
-
const dirSideGroup = await metaDirItemToSidebarItem(fakeDirMetaItem, workDir, docsDir, extensions, metaFileSet, mdFileSet, true);
|
|
748
|
-
const sectionHeaderSideItem = metaSectionHeaderToSidebarItem(fakeSectionHeaderMetaItem);
|
|
749
|
-
return [
|
|
750
|
-
sectionHeaderSideItem,
|
|
751
|
-
...dirSideGroup.items.length >= 1 ? dirSideGroup.items : []
|
|
752
|
-
];
|
|
753
|
-
}
|
|
754
|
-
function metaCustomLinkItemToSidebarItem(metaItem, workDir, docsDir) {
|
|
755
|
-
if ('items' in metaItem && Array.isArray(metaItem.items) && metaItem.items.length > 0) {
|
|
756
|
-
const { label, link, context, items, tag, collapsed, collapsible, overviewHeaders } = metaItem;
|
|
757
|
-
return {
|
|
758
|
-
text: label ?? link,
|
|
759
|
-
context,
|
|
760
|
-
tag,
|
|
761
|
-
link,
|
|
762
|
-
items: items.map((subItem)=>metaCustomLinkItemToSidebarItem(Object.assign(subItem, {
|
|
763
|
-
type: 'custom-link'
|
|
764
|
-
}), workDir, docsDir)),
|
|
765
|
-
collapsed,
|
|
766
|
-
collapsible,
|
|
767
|
-
overviewHeaders
|
|
768
|
-
};
|
|
769
|
-
}
|
|
770
|
-
if ('link' in metaItem && 'string' == typeof metaItem.link) {
|
|
771
|
-
const { label, link, context, tag } = metaItem;
|
|
772
|
-
if ((0, shared_.isExternalUrl)(link)) return {
|
|
773
|
-
text: label ?? link,
|
|
774
|
-
link,
|
|
775
|
-
tag,
|
|
776
|
-
context
|
|
777
|
-
};
|
|
778
|
-
return {
|
|
779
|
-
text: label ?? link,
|
|
780
|
-
link: addRoutePrefix(workDir, docsDir, link),
|
|
781
|
-
tag,
|
|
782
|
-
context
|
|
783
|
-
};
|
|
784
|
-
}
|
|
785
|
-
const { label } = metaItem;
|
|
786
|
-
throw new Error(`The custom link "${label}" does not have a link, please check it in "${(0, external_node_path_.join)(workDir, '_meta.json')}".`);
|
|
787
|
-
}
|
|
788
|
-
function metaDividerToSidebarItem(metaItem) {
|
|
789
|
-
const { dashed } = metaItem;
|
|
790
|
-
return {
|
|
791
|
-
dividerType: dashed ? 'dashed' : 'solid'
|
|
792
|
-
};
|
|
793
|
-
}
|
|
794
|
-
function metaSectionHeaderToSidebarItem(metaItem) {
|
|
795
|
-
const { label, tag } = metaItem;
|
|
796
|
-
return {
|
|
797
|
-
sectionHeaderText: label ?? '',
|
|
798
|
-
tag
|
|
799
|
-
};
|
|
800
|
-
}
|
|
801
|
-
async function scanSideMeta(workDir, docsDir, extensions, metaFileSet, mdFileSet) {
|
|
802
|
-
const dir = await metaDirItemToSidebarItem({
|
|
803
|
-
type: 'dir',
|
|
804
|
-
name: ''
|
|
805
|
-
}, workDir, docsDir, extensions, metaFileSet, mdFileSet, true);
|
|
806
|
-
return dir.items;
|
|
807
|
-
}
|
|
808
|
-
async function scanNav(workDir, docsDir, metaFileSet) {
|
|
809
|
-
let navConfig;
|
|
810
|
-
const rootNavJson = external_node_path_["default"].resolve(workDir, '_nav.json');
|
|
811
|
-
try {
|
|
812
|
-
navConfig = await utils_readJson(rootNavJson);
|
|
813
|
-
metaFileSet.add(rootNavJson);
|
|
814
|
-
} catch (_e) {
|
|
815
|
-
logger.error('[auto-nav-sidebar]', `Generate nav meta error: ${rootNavJson} failed`);
|
|
816
|
-
navConfig = [];
|
|
817
|
-
}
|
|
818
|
-
navConfig.forEach((navItem)=>{
|
|
819
|
-
if ('items' in navItem) navItem.items.forEach((item)=>{
|
|
820
|
-
if ('link' in item && !(0, shared_.isExternalUrl)(item.link)) item.link = addRoutePrefix(workDir, docsDir, item.link);
|
|
821
|
-
});
|
|
822
|
-
if ('link' in navItem && !(0, shared_.isExternalUrl)(navItem.link)) navItem.link = addRoutePrefix(workDir, docsDir, navItem.link);
|
|
823
|
-
});
|
|
824
|
-
return navConfig;
|
|
825
|
-
}
|
|
826
|
-
async function walk(workDir, docsDir, extensions, metaFileSet, mdFileSet) {
|
|
827
|
-
const rootNavJson = external_node_path_["default"].resolve(workDir, '_nav.json');
|
|
828
|
-
const rootMetaJson = external_node_path_["default"].resolve(workDir, '_meta.json');
|
|
829
|
-
const isRootNavJsonExist = await pathExists(rootNavJson);
|
|
830
|
-
const isRootMetaJsonExist = await pathExists(rootMetaJson);
|
|
831
|
-
if (isRootMetaJsonExist) {
|
|
832
|
-
const metaConfig = await utils_readJson(rootMetaJson);
|
|
833
|
-
hintNavJsonChangeThenPanic(metaConfig, workDir, docsDir);
|
|
834
|
-
}
|
|
835
|
-
if (isRootMetaJsonExist && isRootNavJsonExist) {
|
|
836
|
-
const navConfig = await scanNav(workDir, docsDir, metaFileSet);
|
|
837
|
-
return {
|
|
838
|
-
nav: navConfig,
|
|
839
|
-
sidebar: {
|
|
840
|
-
'/': await scanSideMeta(workDir, docsDir, extensions, metaFileSet, mdFileSet)
|
|
841
|
-
}
|
|
842
|
-
};
|
|
843
|
-
}
|
|
844
|
-
if (isRootNavJsonExist) {
|
|
845
|
-
const navConfig = await scanNav(workDir, docsDir, metaFileSet);
|
|
846
|
-
const subDirs = (await Promise.all((await node_fs_promises.readdir(workDir)).map((v)=>node_fs_promises.stat(external_node_path_["default"].join(workDir, v)).then((s)=>{
|
|
847
|
-
if (s.isDirectory() && 'node_modules' !== v) return v;
|
|
848
|
-
return false;
|
|
849
|
-
})))).filter(Boolean);
|
|
850
|
-
const sidebarConfig = {};
|
|
851
|
-
await Promise.all(subDirs.map(async (subDir)=>{
|
|
852
|
-
const sidebarGroupKey = addRoutePrefix(workDir, docsDir, subDir);
|
|
853
|
-
sidebarConfig[sidebarGroupKey] = await scanSideMeta(external_node_path_["default"].join(workDir, subDir), docsDir, extensions, metaFileSet, mdFileSet);
|
|
854
|
-
}));
|
|
855
|
-
return {
|
|
856
|
-
nav: navConfig,
|
|
857
|
-
sidebar: sidebarConfig
|
|
858
|
-
};
|
|
859
|
-
}
|
|
860
|
-
return {
|
|
861
|
-
nav: [],
|
|
862
|
-
sidebar: {
|
|
863
|
-
'/': await scanSideMeta(workDir, docsDir, extensions, metaFileSet, mdFileSet)
|
|
864
|
-
}
|
|
865
|
-
};
|
|
866
|
-
}
|
|
867
|
-
function combineWalkResult(walks, versions) {
|
|
868
|
-
return walks.reduce((acc, cur, curIndex)=>({
|
|
869
|
-
nav: {
|
|
870
|
-
...acc.nav,
|
|
871
|
-
[versions[curIndex] || 'default']: cur.nav
|
|
872
|
-
},
|
|
873
|
-
sidebar: {
|
|
874
|
-
...acc.sidebar,
|
|
875
|
-
...cur.sidebar
|
|
876
|
-
}
|
|
877
|
-
}), {
|
|
878
|
-
nav: {},
|
|
879
|
-
sidebar: {}
|
|
880
|
-
});
|
|
881
|
-
}
|
|
882
|
-
function processLocales(langs, versions, root, extensions, metaFileSet, mdFileSet) {
|
|
883
|
-
return Promise.all(langs.map(async (lang)=>{
|
|
884
|
-
const walks = versions.length ? await Promise.all(versions.map((version)=>walk(external_node_path_["default"].join(root, version, lang), root, extensions, metaFileSet, mdFileSet))) : [
|
|
885
|
-
await walk(external_node_path_["default"].join(root, lang), root, extensions, metaFileSet, mdFileSet)
|
|
886
|
-
];
|
|
887
|
-
return combineWalkResult(walks, versions);
|
|
888
|
-
}));
|
|
889
|
-
}
|
|
890
|
-
async function runAutoNavSide(config, metaFileSet, mdFileSet) {
|
|
891
|
-
config.themeConfig = config.themeConfig || {};
|
|
892
|
-
config.themeConfig.locales = config.themeConfig.locales || config.locales || [];
|
|
893
|
-
const langs = config.themeConfig.locales.map((locale)=>locale.lang);
|
|
894
|
-
const hasLocales = langs.length > 0;
|
|
895
|
-
const versions = config.multiVersion?.versions || [];
|
|
896
|
-
const { extensions = DEFAULT_PAGE_EXTENSIONS } = config?.route || {};
|
|
897
|
-
if (hasLocales) {
|
|
898
|
-
const metaInfo = await processLocales(langs, versions, config.root, extensions, metaFileSet, mdFileSet);
|
|
899
|
-
return metaInfo;
|
|
900
|
-
}
|
|
901
|
-
const walks = versions.length ? await Promise.all(versions.map((version)=>walk(external_node_path_["default"].join(config.root, version), config.root, extensions, metaFileSet, mdFileSet))) : [
|
|
902
|
-
await walk(config.root, config.root, extensions, metaFileSet, mdFileSet)
|
|
903
|
-
];
|
|
904
|
-
const combined = combineWalkResult(walks, versions);
|
|
905
|
-
return combined;
|
|
906
|
-
}
|
|
907
|
-
function auto_nav_sidebar_haveNavSidebarConfig(config) {
|
|
908
|
-
const themeConfig = config.themeConfig || {};
|
|
909
|
-
const haveNavSidebarConfig = themeConfig.nav || themeConfig.sidebar || themeConfig.locales?.[0]?.nav || themeConfig.locales?.[0]?.sidebar;
|
|
910
|
-
return Boolean(haveNavSidebarConfig);
|
|
911
|
-
}
|
|
912
|
-
async function modifyConfigWithAutoNavSide(config, metaFileSet = new Set(), mdFileSet = new Set(), force = false) {
|
|
913
|
-
if (auto_nav_sidebar_haveNavSidebarConfig(config) && !force) return;
|
|
914
|
-
const autoNavSide = await runAutoNavSide(config, metaFileSet, mdFileSet);
|
|
915
|
-
if (null === autoNavSide) return;
|
|
916
|
-
if (Array.isArray(autoNavSide)) {
|
|
917
|
-
config.themeConfig = config.themeConfig || {};
|
|
918
|
-
config.themeConfig.locales = config.themeConfig.locales || [];
|
|
919
|
-
config.themeConfig.locales = config.themeConfig.locales.map((item, index)=>({
|
|
920
|
-
...item,
|
|
921
|
-
...autoNavSide[index]
|
|
922
|
-
}));
|
|
923
|
-
return;
|
|
924
|
-
}
|
|
925
|
-
config.themeConfig = config.themeConfig || {};
|
|
926
|
-
config.themeConfig.nav = autoNavSide.nav;
|
|
927
|
-
config.themeConfig.sidebar = autoNavSide.sidebar;
|
|
928
|
-
}
|
|
929
|
-
const PLUGIN_VIRTUAL_MODULE_NAME = 'rsbuild:virtual-module';
|
|
930
|
-
const pluginVirtualModule = (pluginOptions = {})=>({
|
|
931
|
-
name: PLUGIN_VIRTUAL_MODULE_NAME,
|
|
932
|
-
async setup (api) {
|
|
933
|
-
const { virtualModules = {}, tempDir: virtualFolderName = '.rsbuild-virtual-module' } = pluginOptions;
|
|
934
|
-
const TEMP_DIR = (0, external_node_path_.join)(api.context.rootPath, virtualFolderName);
|
|
935
|
-
const virtualFileAbsolutePaths = Object.keys(virtualModules).map((i)=>{
|
|
936
|
-
let absolutePath = (0, external_node_path_.join)(TEMP_DIR, i);
|
|
937
|
-
if (!(0, external_node_path_.extname)(absolutePath)) absolutePath = `${absolutePath}.js`;
|
|
938
|
-
return [
|
|
939
|
-
i,
|
|
940
|
-
absolutePath
|
|
941
|
-
];
|
|
942
|
-
});
|
|
943
|
-
api.modifyBundlerChain((chain, { rspack })=>{
|
|
944
|
-
const pluginId = 'RSBUILD_VIRTUAL_MODULE_PLUGIN';
|
|
945
|
-
const virtualModules = Object.fromEntries(virtualFileAbsolutePaths.map((i)=>[
|
|
946
|
-
i[1],
|
|
947
|
-
''
|
|
948
|
-
]));
|
|
949
|
-
if (chain.plugins.has(pluginId)) chain.plugin(pluginId).tap((options)=>{
|
|
950
|
-
const existingPaths = new Set(Object.keys(options[0] ?? {}));
|
|
951
|
-
const conflictPath = virtualFileAbsolutePaths.find(([, path])=>existingPaths.has(path));
|
|
952
|
-
if (conflictPath) throw new Error(`Virtual module name conflicted: ${conflictPath[0]}`);
|
|
953
|
-
return [
|
|
954
|
-
{
|
|
955
|
-
...options[0],
|
|
956
|
-
...virtualModules
|
|
957
|
-
}
|
|
958
|
-
];
|
|
959
|
-
});
|
|
960
|
-
else chain.plugin(pluginId).use(rspack.experiments.VirtualModulesPlugin, [
|
|
961
|
-
virtualModules
|
|
962
|
-
]);
|
|
963
|
-
chain.resolve.alias.merge(Object.fromEntries(virtualFileAbsolutePaths));
|
|
964
|
-
});
|
|
965
|
-
for (const [moduleName, absolutePath] of virtualFileAbsolutePaths){
|
|
966
|
-
const handler = virtualModules[moduleName];
|
|
967
|
-
if (handler) api.transform({
|
|
968
|
-
test: absolutePath
|
|
969
|
-
}, handler);
|
|
970
|
-
}
|
|
971
|
-
}
|
|
972
|
-
});
|
|
973
|
-
const globalStylesVMPlugin = (context)=>({
|
|
974
|
-
["virtual-global-styles"]: ()=>{
|
|
975
|
-
const { config, pluginDriver } = context;
|
|
976
|
-
const globalStylesByPlugins = pluginDriver.globalStyles();
|
|
977
|
-
const moduleContent = [
|
|
978
|
-
config?.globalStyles,
|
|
979
|
-
...globalStylesByPlugins
|
|
980
|
-
].filter(Boolean).map((source)=>`import ${JSON.stringify(source)};`).join('');
|
|
981
|
-
return moduleContent;
|
|
982
|
-
}
|
|
983
|
-
});
|
|
984
|
-
const globalUIComponentsVMPlugin = (context)=>({
|
|
985
|
-
["virtual-global-components"]: ()=>{
|
|
986
|
-
const { config, pluginDriver } = context;
|
|
987
|
-
let index = 0;
|
|
988
|
-
const globalUIComponentsByPlugins = pluginDriver.globalUIComponents();
|
|
989
|
-
const globalComponents = [
|
|
990
|
-
...config?.globalUIComponents || [],
|
|
991
|
-
...globalUIComponentsByPlugins
|
|
992
|
-
];
|
|
993
|
-
const moduleContent = globalComponents.map((source)=>{
|
|
994
|
-
const name = `Comp_${index}`;
|
|
995
|
-
if (Array.isArray(source)) return `import ${name} from ${JSON.stringify(source[0])};
|
|
996
|
-
const Props_${index++} = ${JSON.stringify(source[1])};\n`;
|
|
997
|
-
index++;
|
|
998
|
-
return `import ${name} from ${JSON.stringify(source)};\n`;
|
|
999
|
-
}).concat(`export default [${Array.from({
|
|
1000
|
-
length: index
|
|
1001
|
-
}, (_, i)=>{
|
|
1002
|
-
if (Array.isArray(globalComponents[i])) return `[Comp_${i}, Props_${i}]`;
|
|
1003
|
-
return `Comp_${i}`;
|
|
1004
|
-
}).join(', ')}];`).join('');
|
|
1005
|
-
return moduleContent;
|
|
1006
|
-
}
|
|
1007
|
-
});
|
|
1008
|
-
const DEFAULT_I18N_TEXT = {
|
|
1009
|
-
languagesText: {
|
|
1010
|
-
zh: '语言',
|
|
1011
|
-
en: 'Languages',
|
|
1012
|
-
ja: '言語',
|
|
1013
|
-
ko: '언어'
|
|
1014
|
-
},
|
|
1015
|
-
themeText: {
|
|
1016
|
-
zh: '主题',
|
|
1017
|
-
en: 'Theme',
|
|
1018
|
-
ja: 'テーマ',
|
|
1019
|
-
ko: '테마'
|
|
1020
|
-
},
|
|
1021
|
-
versionsText: {
|
|
1022
|
-
zh: '版本',
|
|
1023
|
-
en: 'Versions',
|
|
1024
|
-
ja: 'バージョン',
|
|
1025
|
-
ko: '버전'
|
|
1026
|
-
},
|
|
1027
|
-
menuTitle: {
|
|
1028
|
-
zh: '菜单',
|
|
1029
|
-
en: 'Menu',
|
|
1030
|
-
ja: 'メニュー',
|
|
1031
|
-
ko: '사이드바 메뉴'
|
|
1032
|
-
},
|
|
1033
|
-
outlineTitle: {
|
|
1034
|
-
zh: '目录',
|
|
1035
|
-
en: 'ON THIS PAGE',
|
|
1036
|
-
ja: '目次',
|
|
1037
|
-
ko: '이 페이지 목차'
|
|
1038
|
-
},
|
|
1039
|
-
scrollToTopText: {
|
|
1040
|
-
en: 'Back to top',
|
|
1041
|
-
zh: '回到顶部',
|
|
1042
|
-
ja: 'トップに戻る',
|
|
1043
|
-
ko: '맨 위로'
|
|
1044
|
-
},
|
|
1045
|
-
lastUpdatedText: {
|
|
1046
|
-
en: 'Last Updated',
|
|
1047
|
-
zh: '最后更新于',
|
|
1048
|
-
ja: '最終更新',
|
|
1049
|
-
ko: '업데이트 날짜'
|
|
1050
|
-
},
|
|
1051
|
-
prevPageText: {
|
|
1052
|
-
en: 'Previous page',
|
|
1053
|
-
zh: '上一页',
|
|
1054
|
-
ja: '前のページ',
|
|
1055
|
-
ko: '이전 페이지'
|
|
1056
|
-
},
|
|
1057
|
-
nextPageText: {
|
|
1058
|
-
en: 'Next page',
|
|
1059
|
-
zh: '下一页',
|
|
1060
|
-
ja: '次のページ',
|
|
1061
|
-
ko: '다음 페이지'
|
|
1062
|
-
},
|
|
1063
|
-
sourceCodeText: {
|
|
1064
|
-
en: 'Source Code',
|
|
1065
|
-
zh: '源码',
|
|
1066
|
-
ja: 'ソースコード',
|
|
1067
|
-
ko: '소스 코드'
|
|
1068
|
-
},
|
|
1069
|
-
searchPlaceholderText: {
|
|
1070
|
-
en: 'Search',
|
|
1071
|
-
zh: '搜索',
|
|
1072
|
-
ja: '検索',
|
|
1073
|
-
ko: '검색'
|
|
1074
|
-
},
|
|
1075
|
-
searchPanelCancelText: {
|
|
1076
|
-
en: 'Cancel',
|
|
1077
|
-
zh: '取消',
|
|
1078
|
-
ja: 'キャンセル',
|
|
1079
|
-
ko: '취소'
|
|
1080
|
-
},
|
|
1081
|
-
searchNoResultsText: {
|
|
1082
|
-
en: 'No matching results',
|
|
1083
|
-
zh: '未找到与之匹配的结果',
|
|
1084
|
-
ja: '一致する結果が見つかりません',
|
|
1085
|
-
ko: '일치하는 결과가 없습니다'
|
|
1086
|
-
},
|
|
1087
|
-
searchSuggestedQueryText: {
|
|
1088
|
-
en: 'Try searching for different keywords',
|
|
1089
|
-
zh: '试试搜索不同关键词',
|
|
1090
|
-
ja: '別のキーワードで検索してみてください',
|
|
1091
|
-
ko: '다른 키워드로 검색해 보세요'
|
|
1092
|
-
},
|
|
1093
|
-
'overview.filterNameText': {
|
|
1094
|
-
en: 'Filter',
|
|
1095
|
-
zh: '筛选',
|
|
1096
|
-
ja: 'フィルター',
|
|
1097
|
-
ko: '필터'
|
|
1098
|
-
},
|
|
1099
|
-
'overview.filterPlaceholderText': {
|
|
1100
|
-
en: 'Search API',
|
|
1101
|
-
zh: '搜索 API',
|
|
1102
|
-
ja: 'API を検索',
|
|
1103
|
-
ko: 'API 검색'
|
|
1104
|
-
},
|
|
1105
|
-
'overview.filterNoResultText': {
|
|
1106
|
-
en: 'No matching API found',
|
|
1107
|
-
zh: '未找到匹配的 API',
|
|
1108
|
-
ja: '一致する API が見つかりません',
|
|
1109
|
-
ko: '일치하는 API가 없습니다'
|
|
1110
|
-
},
|
|
1111
|
-
editLinkText: {
|
|
1112
|
-
en: '📝 Edit this page',
|
|
1113
|
-
zh: '📝 编辑此页面',
|
|
1114
|
-
ja: '📝 このページを編集',
|
|
1115
|
-
ko: '📝 이 페이지 편집'
|
|
1116
|
-
},
|
|
1117
|
-
codeButtonGroupCopyButtonText: {
|
|
1118
|
-
en: 'Copy code',
|
|
1119
|
-
zh: '复制代码',
|
|
1120
|
-
ja: 'コードをコピー',
|
|
1121
|
-
ko: '코드 복사'
|
|
1122
|
-
},
|
|
1123
|
-
notFoundText: {
|
|
1124
|
-
en: 'PAGE NOT FOUND',
|
|
1125
|
-
zh: '页面未找到',
|
|
1126
|
-
ja: 'ページが見つかりません',
|
|
1127
|
-
ko: '페이지를 찾을 수 없음'
|
|
1128
|
-
},
|
|
1129
|
-
takeMeHomeText: {
|
|
1130
|
-
en: 'Take me home',
|
|
1131
|
-
zh: '返回首页',
|
|
1132
|
-
ja: 'ホームに連れてって',
|
|
1133
|
-
ko: '홈으로 이동'
|
|
1134
|
-
}
|
|
1135
|
-
};
|
|
1136
|
-
const i18n_require = createRequire(import.meta.url);
|
|
1137
|
-
const DEFAULT_I18N_SOURCE_PATH = (0, external_node_path_.join)(process.cwd(), 'i18n.json');
|
|
1138
|
-
function mergeI18nData(...sources) {
|
|
1139
|
-
const result = {};
|
|
1140
|
-
for (const source of sources)for(const key in source){
|
|
1141
|
-
if (!result[key]) result[key] = {};
|
|
1142
|
-
Object.assign(result[key], source[key]);
|
|
1143
|
-
}
|
|
1144
|
-
return result;
|
|
1145
|
-
}
|
|
1146
|
-
const logPrefix = '[i18n]';
|
|
1147
|
-
const logKeys = new Set();
|
|
1148
|
-
let logged = false;
|
|
1149
|
-
async function getI18nData(docConfig, pluginDriver) {
|
|
1150
|
-
const { i18nSourcePath = DEFAULT_I18N_SOURCE_PATH, i18nSource = {}, themeConfig, locales } = docConfig;
|
|
1151
|
-
let langs = (locales ?? themeConfig?.locales)?.map((locale)=>locale.lang) ?? [];
|
|
1152
|
-
if (0 === langs.length) langs = [
|
|
1153
|
-
docConfig.lang ?? 'en'
|
|
1154
|
-
];
|
|
1155
|
-
let i18nSourceFull = JSON.parse(JSON.stringify(DEFAULT_I18N_TEXT));
|
|
1156
|
-
const i18nSourceFromPlugin = await pluginDriver?.i18nSource(i18nSourceFull);
|
|
1157
|
-
if (i18nSourceFromPlugin) i18nSourceFull = i18nSourceFromPlugin;
|
|
1158
|
-
let i18nSourceFromJson = {};
|
|
1159
|
-
try {
|
|
1160
|
-
delete i18n_require.cache[i18nSourcePath];
|
|
1161
|
-
i18nSourceFromJson = i18n_require(i18nSourcePath);
|
|
1162
|
-
} catch (e) {
|
|
1163
|
-
logger.debug('getI18nData from i18n.json Failed: \n', e);
|
|
1164
|
-
}
|
|
1165
|
-
i18nSourceFull = mergeI18nData(i18nSourceFull, i18nSourceFromJson);
|
|
1166
|
-
if ('function' == typeof i18nSource) try {
|
|
1167
|
-
i18nSourceFull = await i18nSource(i18nSourceFull);
|
|
1168
|
-
} catch (e) {
|
|
1169
|
-
logger.error(`${logPrefix} getI18nData Failed to execute \`i18nSource\` function in \`rspress.config.ts\`: \n`, e);
|
|
1170
|
-
throw e;
|
|
1171
|
-
}
|
|
1172
|
-
else i18nSourceFull = mergeI18nData(i18nSourceFull, i18nSource);
|
|
1173
|
-
const cyan = picocolors.cyan;
|
|
1174
|
-
const filteredI18nSource = {};
|
|
1175
|
-
for(const key in i18nSourceFull){
|
|
1176
|
-
filteredI18nSource[key] = {};
|
|
1177
|
-
for (const lang of langs)if (i18nSourceFull[key][lang]) filteredI18nSource[key][lang] = i18nSourceFull[key][lang];
|
|
1178
|
-
else {
|
|
1179
|
-
const enText = i18nSourceFull[key].en;
|
|
1180
|
-
logKeys.add(key);
|
|
1181
|
-
if (enText) filteredI18nSource[key][lang] = enText;
|
|
1182
|
-
else {
|
|
1183
|
-
logger.error(`${logPrefix} i18n key ${cyan(key)} has no text for lang ${cyan(lang)}, and no fallback ${cyan('en')} text either.`);
|
|
1184
|
-
throw new Error(`i18n text missing for ${picocolors.cyan(key)}`);
|
|
1185
|
-
}
|
|
1186
|
-
}
|
|
1187
|
-
}
|
|
1188
|
-
if (logKeys.size > 0 && !logged) {
|
|
1189
|
-
logger.warn(`${logPrefix} The following i18n keys are missing for some languages and have fallen back to 'en':
|
|
1190
|
-
${picocolors.gray(JSON.stringify(Object.fromEntries([
|
|
1191
|
-
...logKeys.keys()
|
|
1192
|
-
].map((i)=>[
|
|
1193
|
-
i,
|
|
1194
|
-
'...'
|
|
1195
|
-
])), null, 2))}`);
|
|
1196
|
-
logged = true;
|
|
1197
|
-
}
|
|
1198
|
-
return filteredI18nSource;
|
|
1199
|
-
}
|
|
1200
|
-
const i18nVMPlugin = (context)=>{
|
|
1201
|
-
const { config, pluginDriver } = context;
|
|
1202
|
-
return {
|
|
1203
|
-
["virtual-i18n-text"]: async ({ addDependency, addMissingDependency })=>{
|
|
1204
|
-
const configPath = config.i18nSourcePath || DEFAULT_I18N_SOURCE_PATH;
|
|
1205
|
-
const isExist = await pathExists(configPath);
|
|
1206
|
-
if (isExist) addDependency(configPath);
|
|
1207
|
-
else addMissingDependency(configPath);
|
|
1208
|
-
const i18nData = await getI18nData(config, pluginDriver);
|
|
1209
|
-
return `export default ${JSON.stringify(i18nData, null, 2)}`;
|
|
1210
|
-
}
|
|
1211
|
-
};
|
|
1212
|
-
};
|
|
1213
|
-
var external_node_fs_ = __webpack_require__("node:fs");
|
|
1214
|
-
const RspackResolveFactory = core_rspack.experiments.resolver.ResolverFactory;
|
|
1215
|
-
let startFlatten = false;
|
|
1216
|
-
let flattenMdxContent_resolver;
|
|
1217
|
-
const processor = createProcessor();
|
|
1218
|
-
async function resolveDepPath(moduleSpecifier, importer, alias) {
|
|
1219
|
-
if (!flattenMdxContent_resolver) flattenMdxContent_resolver = new RspackResolveFactory({
|
|
1220
|
-
extensions: [
|
|
1221
|
-
'.mdx',
|
|
1222
|
-
'.md'
|
|
1223
|
-
],
|
|
1224
|
-
alias
|
|
1225
|
-
});
|
|
1226
|
-
const resolved = await flattenMdxContent_resolver.async(importer, moduleSpecifier);
|
|
1227
|
-
if (resolved.path) return resolved.path;
|
|
1228
|
-
throw new Error(`Empty result when resolving ${moduleSpecifier} from ${importer}`);
|
|
1229
|
-
}
|
|
1230
|
-
async function flattenMdxContent(content, basePath, alias) {
|
|
1231
|
-
const deps = [];
|
|
1232
|
-
const regex = new RegExp(importStatementRegex);
|
|
1233
|
-
if (!regex.test(content)) return {
|
|
1234
|
-
flattenContent: content,
|
|
1235
|
-
deps
|
|
1236
|
-
};
|
|
1237
|
-
if (!startFlatten) {
|
|
1238
|
-
flattenMdxContent_resolver = new RspackResolveFactory({
|
|
1239
|
-
extensions: [
|
|
1240
|
-
'.mdx',
|
|
1241
|
-
'.md',
|
|
1242
|
-
'.js'
|
|
1243
|
-
],
|
|
1244
|
-
alias
|
|
1245
|
-
});
|
|
1246
|
-
startFlatten = true;
|
|
1247
|
-
}
|
|
1248
|
-
let ast;
|
|
1249
|
-
let result = content;
|
|
1250
|
-
try {
|
|
1251
|
-
ast = processor.parse(content);
|
|
1252
|
-
} catch (e) {
|
|
1253
|
-
logger.debug('flattenMdxContent parse failed: \n', e);
|
|
1254
|
-
return {
|
|
1255
|
-
flattenContent: content,
|
|
1256
|
-
deps
|
|
1257
|
-
};
|
|
1258
|
-
}
|
|
1259
|
-
const importNodes = ast.children.filter((node)=>'mdxjsEsm' === node.type).flatMap((node)=>node.data?.estree?.body || []).filter((node)=>'ImportDeclaration' === node.type);
|
|
1260
|
-
for (const importNode of importNodes){
|
|
1261
|
-
const id = importNode.specifiers[0].local.name;
|
|
1262
|
-
const importPath = importNode.source.value;
|
|
1263
|
-
let absoluteImportPath;
|
|
1264
|
-
try {
|
|
1265
|
-
absoluteImportPath = await resolveDepPath(importPath, external_node_path_["default"].dirname(basePath), alias);
|
|
1266
|
-
} catch (_e) {
|
|
1267
|
-
continue;
|
|
1268
|
-
}
|
|
1269
|
-
if (shared_.MDX_OR_MD_REGEXP.test(absoluteImportPath)) {
|
|
1270
|
-
const importedContent = external_node_fs_["default"].readFileSync(absoluteImportPath, 'utf-8');
|
|
1271
|
-
const { flattenContent: replacedValue, deps: subDeps } = await flattenMdxContent(importedContent, absoluteImportPath, alias);
|
|
1272
|
-
result = result.replace(new RegExp(`import\\s+${id}\\s+from\\s+['"](${importPath})['"];?`), '').replace(new RegExp(`<${id}\\s*/>`, 'g'), ()=>replacedValue);
|
|
1273
|
-
deps.push(...subDeps, absoluteImportPath);
|
|
1274
|
-
}
|
|
1275
|
-
}
|
|
1276
|
-
return {
|
|
1277
|
-
flattenContent: result,
|
|
1278
|
-
deps
|
|
1279
|
-
};
|
|
1280
|
-
}
|
|
1281
|
-
function applyReplaceRules(code = '', replaceRules = []) {
|
|
1282
|
-
let result = code;
|
|
1283
|
-
for (const rule of replaceRules)result = result.replace(rule.search, rule.replace);
|
|
1284
|
-
return result;
|
|
1285
|
-
}
|
|
1286
|
-
function applyReplaceRulesToNestedObject(obj, replaceRules) {
|
|
1287
|
-
for(const key in obj)if ('string' == typeof obj[key]) obj[key] = applyReplaceRules(obj[key], replaceRules);
|
|
1288
|
-
else if ('object' == typeof obj[key] && null !== obj[key]) obj[key] = applyReplaceRulesToNestedObject(obj[key], replaceRules);
|
|
1289
|
-
return obj;
|
|
1290
|
-
}
|
|
1291
|
-
async function getPageIndexInfoByRoute(route, options) {
|
|
1292
|
-
const { alias, replaceRules, root, searchCodeBlocks } = options;
|
|
1293
|
-
const defaultIndexInfo = {
|
|
1294
|
-
title: '',
|
|
1295
|
-
content: '',
|
|
1296
|
-
_html: '',
|
|
1297
|
-
_flattenContent: '',
|
|
1298
|
-
routePath: route.routePath,
|
|
1299
|
-
lang: route.lang,
|
|
1300
|
-
toc: [],
|
|
1301
|
-
frontmatter: {},
|
|
1302
|
-
version: route.version,
|
|
1303
|
-
_filepath: route.absolutePath,
|
|
1304
|
-
_relativePath: external_node_path_["default"].relative(root, route.absolutePath).split(external_node_path_["default"].sep).join('/')
|
|
1305
|
-
};
|
|
1306
|
-
if (!shared_.MDX_OR_MD_REGEXP.test(route.absolutePath)) return defaultIndexInfo;
|
|
1307
|
-
let content = await node_fs_promises.readFile(route.absolutePath, 'utf8');
|
|
1308
|
-
const { frontmatter, content: contentWithoutFrontMatter } = loadFrontMatter(content, route.absolutePath, root);
|
|
1309
|
-
applyReplaceRulesToNestedObject(frontmatter, replaceRules);
|
|
1310
|
-
const { flattenContent } = await flattenMdxContent(applyReplaceRules(contentWithoutFrontMatter, replaceRules), route.absolutePath, alias);
|
|
1311
|
-
content = flattenContent.replace(importStatementRegex, '');
|
|
1312
|
-
const { html: rawHtml, title, toc: rawToc } = await compile({
|
|
1313
|
-
value: content,
|
|
1314
|
-
filepath: route.absolutePath,
|
|
1315
|
-
development: 'production' !== process.env.NODE_ENV,
|
|
1316
|
-
root
|
|
1317
|
-
});
|
|
1318
|
-
function encodeHtml(html) {
|
|
1319
|
-
return html.replace(/<code>([\s\S]*?)<\/\s?code>/gm, function(_match, innerContent) {
|
|
1320
|
-
return `<code>${innerContent.replace(/&/g, '&').replace(/"/g, '"').replace(/'/g, ''').replace(/</g, '<').replace(/>/g, '>')}</code>`;
|
|
1321
|
-
});
|
|
1322
|
-
}
|
|
1323
|
-
const html = encodeHtml(String(rawHtml));
|
|
1324
|
-
content = htmlToText(html, {
|
|
1325
|
-
wordwrap: 80,
|
|
1326
|
-
selectors: [
|
|
1327
|
-
{
|
|
1328
|
-
selector: 'a',
|
|
1329
|
-
options: {
|
|
1330
|
-
ignoreHref: true
|
|
1331
|
-
}
|
|
1332
|
-
},
|
|
1333
|
-
{
|
|
1334
|
-
selector: 'img',
|
|
1335
|
-
format: 'skip'
|
|
1336
|
-
},
|
|
1337
|
-
{
|
|
1338
|
-
selector: 'pre > code',
|
|
1339
|
-
format: searchCodeBlocks ? 'block' : 'skip'
|
|
1340
|
-
},
|
|
1341
|
-
...[
|
|
1342
|
-
'h1',
|
|
1343
|
-
'h2',
|
|
1344
|
-
'h3',
|
|
1345
|
-
'h4',
|
|
1346
|
-
'h5',
|
|
1347
|
-
'h6'
|
|
1348
|
-
].map((tag)=>({
|
|
1349
|
-
selector: tag,
|
|
1350
|
-
options: {
|
|
1351
|
-
uppercase: false
|
|
1352
|
-
}
|
|
1353
|
-
}))
|
|
1354
|
-
],
|
|
1355
|
-
tables: true,
|
|
1356
|
-
longWordSplit: {
|
|
1357
|
-
forceWrapOnLimit: true
|
|
1358
|
-
}
|
|
1359
|
-
});
|
|
1360
|
-
if (content.startsWith(title)) content = content.slice(title.length);
|
|
1361
|
-
const toc = rawToc.map((item)=>{
|
|
1362
|
-
const match = item.id.match(/-(\d+)$/);
|
|
1363
|
-
let position = -1;
|
|
1364
|
-
if (match) for(let i = 0; i < Number(match[1]); i++){
|
|
1365
|
-
position = content.indexOf(`\n${item.text}#\n\n`, position + 1);
|
|
1366
|
-
if (-1 === position) break;
|
|
1367
|
-
}
|
|
1368
|
-
return {
|
|
1369
|
-
...item,
|
|
1370
|
-
charIndex: content.indexOf(`\n${item.text}#\n\n`, position + 1)
|
|
1371
|
-
};
|
|
1372
|
-
});
|
|
1373
|
-
return {
|
|
1374
|
-
...defaultIndexInfo,
|
|
1375
|
-
title: frontmatter.title || title,
|
|
1376
|
-
toc,
|
|
1377
|
-
content,
|
|
1378
|
-
_html: html,
|
|
1379
|
-
_flattenContent: flattenContent,
|
|
1380
|
-
frontmatter: {
|
|
1381
|
-
...frontmatter,
|
|
1382
|
-
__content: void 0
|
|
1383
|
-
}
|
|
1384
|
-
};
|
|
1385
|
-
}
|
|
1386
|
-
async function extractPageData(routeService, options) {
|
|
1387
|
-
const pageData = await Promise.all(routeService.getRoutes().map((routeMeta)=>getPageIndexInfoByRoute(routeMeta, options)));
|
|
1388
|
-
return pageData;
|
|
1389
|
-
}
|
|
1390
|
-
function createHash_createHash(str) {
|
|
1391
|
-
return createHash('sha256').update(str).digest('hex').slice(0, 8);
|
|
1392
|
-
}
|
|
1393
|
-
function deletePrivateField(obj) {
|
|
1394
|
-
if ('object' != typeof obj || null === obj) return obj;
|
|
1395
|
-
const newObj = {
|
|
1396
|
-
...obj
|
|
1397
|
-
};
|
|
1398
|
-
for(const key in newObj)if (key.startsWith('_')) delete newObj[key];
|
|
1399
|
-
return newObj;
|
|
1400
|
-
}
|
|
1401
|
-
async function createPageData(context) {
|
|
1402
|
-
const { config, alias, userDocRoot, routeService, pluginDriver } = context;
|
|
1403
|
-
const userConfig = config;
|
|
1404
|
-
const tempSearchObj = Object.assign({}, userConfig.search);
|
|
1405
|
-
if (tempSearchObj) tempSearchObj.searchHooks = void 0;
|
|
1406
|
-
const replaceRules = userConfig?.replaceRules || [];
|
|
1407
|
-
const searchConfig = userConfig?.search || {};
|
|
1408
|
-
const searchCodeBlocks = 'codeBlocks' in searchConfig ? Boolean(searchConfig.codeBlocks) : true;
|
|
1409
|
-
const pages = await extractPageData(routeService, {
|
|
1410
|
-
replaceRules,
|
|
1411
|
-
alias,
|
|
1412
|
-
root: userDocRoot,
|
|
1413
|
-
searchCodeBlocks
|
|
1414
|
-
});
|
|
1415
|
-
await pluginDriver.modifySearchIndexData(pages);
|
|
1416
|
-
const versioned = 'boolean' != typeof userConfig.search && userConfig.search?.versioned;
|
|
1417
|
-
const groupedPages = groupBy(pages, (page)=>{
|
|
1418
|
-
if (page.frontmatter?.pageType === 'home') return 'noindex';
|
|
1419
|
-
const version = versioned ? page.version : '';
|
|
1420
|
-
const lang = page.lang || '';
|
|
1421
|
-
return `${version}###${lang}`;
|
|
1422
|
-
});
|
|
1423
|
-
delete groupedPages.noindex;
|
|
1424
|
-
const indexHashByGroup = {};
|
|
1425
|
-
const searchIndex = {};
|
|
1426
|
-
await Promise.all(Object.keys(groupedPages).map(async (group)=>{
|
|
1427
|
-
const stringifiedIndex = JSON.stringify(groupedPages[group].map(deletePrivateField));
|
|
1428
|
-
const indexHash = createHash_createHash(stringifiedIndex);
|
|
1429
|
-
indexHashByGroup[group] = indexHash;
|
|
1430
|
-
const [version, lang] = group.split('###');
|
|
1431
|
-
const indexVersion = version ? `.${version.replace('.', '_')}` : '';
|
|
1432
|
-
const indexLang = lang ? `.${lang}` : '';
|
|
1433
|
-
const filename = `${shared_.SEARCH_INDEX_NAME}${indexVersion}${indexLang}.${indexHash}.json`;
|
|
1434
|
-
searchIndex[filename] = stringifiedIndex;
|
|
1435
|
-
}));
|
|
1436
|
-
await Promise.all(pages.map(async (pageData)=>pluginDriver.extendPageData(pageData)));
|
|
1437
|
-
const filepaths = [];
|
|
1438
|
-
const pageData = {
|
|
1439
|
-
pages: pages.map((page)=>{
|
|
1440
|
-
const { content: _content, _filepath, _html, _flattenContent, ...rest } = page;
|
|
1441
|
-
filepaths.push(_filepath);
|
|
1442
|
-
return rest;
|
|
1443
|
-
})
|
|
1444
|
-
};
|
|
1445
|
-
return {
|
|
1446
|
-
filepaths,
|
|
1447
|
-
pageData,
|
|
1448
|
-
searchIndex,
|
|
1449
|
-
indexHashByGroup
|
|
1450
|
-
};
|
|
1451
|
-
}
|
|
1452
|
-
const rsbuildPluginDocVM = async ({ config, userDocRoot, routeService, pluginDriver })=>{
|
|
1453
|
-
const ref = {
|
|
1454
|
-
pageData: null,
|
|
1455
|
-
searchIndex: null,
|
|
1456
|
-
indexHashByGroup: null,
|
|
1457
|
-
filepaths: []
|
|
1458
|
-
};
|
|
1459
|
-
const searchIndexRsbuildPlugin = {
|
|
1460
|
-
name: 'rsbuild-plugin-searchIndex',
|
|
1461
|
-
async setup (api) {
|
|
1462
|
-
api.modifyBundlerChain(async (bundlerChain)=>{
|
|
1463
|
-
const alias = bundlerChain.resolve.alias.entries();
|
|
1464
|
-
const { pageData, indexHashByGroup, searchIndex, filepaths } = await createPageData({
|
|
1465
|
-
config,
|
|
1466
|
-
alias: alias,
|
|
1467
|
-
userDocRoot,
|
|
1468
|
-
routeService,
|
|
1469
|
-
pluginDriver
|
|
1470
|
-
});
|
|
1471
|
-
ref.pageData = pageData;
|
|
1472
|
-
ref.searchIndex = searchIndex;
|
|
1473
|
-
ref.indexHashByGroup = indexHashByGroup;
|
|
1474
|
-
ref.filepaths = filepaths;
|
|
1475
|
-
api.processAssets({
|
|
1476
|
-
stage: 'report',
|
|
1477
|
-
environments: [
|
|
1478
|
-
'web'
|
|
1479
|
-
]
|
|
1480
|
-
}, ({ compilation, compiler })=>{
|
|
1481
|
-
for (const [filename, stringifiedIndex] of Object.entries(searchIndex))compilation.emitAsset(`static/${filename}`, new compiler.webpack.sources.RawSource(stringifiedIndex));
|
|
1482
|
-
});
|
|
1483
|
-
});
|
|
1484
|
-
}
|
|
1485
|
-
};
|
|
1486
|
-
return [
|
|
1487
|
-
searchIndexRsbuildPlugin,
|
|
1488
|
-
pluginVirtualModule({
|
|
1489
|
-
tempDir: '.rspress',
|
|
1490
|
-
virtualModules: {
|
|
1491
|
-
["virtual-page-data"]: async ({ addDependency })=>{
|
|
1492
|
-
for (const file of ref.filepaths)addDependency(file);
|
|
1493
|
-
return `export const pageData = ${JSON.stringify(ref.pageData, null, 2)};
|
|
1494
|
-
export const searchIndexHash = ${JSON.stringify(ref.indexHashByGroup, null, 2)};`;
|
|
1495
|
-
}
|
|
1496
|
-
}
|
|
1497
|
-
})
|
|
1498
|
-
];
|
|
1499
|
-
};
|
|
1500
|
-
const routeListVMPlugin = (context)=>{
|
|
1501
|
-
const { routeService } = context;
|
|
1502
|
-
return {
|
|
1503
|
-
["virtual-routes"]: ()=>routeService.generateRoutesCode()
|
|
1504
|
-
};
|
|
1505
|
-
};
|
|
1506
|
-
const searchHookVMPlugin = (context)=>({
|
|
1507
|
-
["virtual-search-hooks"]: ()=>{
|
|
1508
|
-
const { config } = context;
|
|
1509
|
-
let content = 'export const onSearch = () => {};';
|
|
1510
|
-
const searchHooks = 'object' == typeof config.search && config.search?.searchHooks;
|
|
1511
|
-
if (searchHooks) content = `export * from ${JSON.stringify(external_node_path_["default"].posix.normalize(searchHooks))}`;
|
|
1512
|
-
return content;
|
|
1513
|
-
}
|
|
1514
|
-
});
|
|
1515
|
-
async function normalizeThemeConfig(docConfig) {
|
|
1516
|
-
const { locales: siteLocales, lang, replaceRules = [], multiVersion } = docConfig;
|
|
1517
|
-
const { versions = [] } = multiVersion || {};
|
|
1518
|
-
const hasMultiVersion = versions.length > 0;
|
|
1519
|
-
docConfig.themeConfig = docConfig.themeConfig || {};
|
|
1520
|
-
const { themeConfig } = docConfig;
|
|
1521
|
-
const locales = siteLocales ?? (themeConfig?.locales || []);
|
|
1522
|
-
const i18nTextData = await getI18nData(docConfig);
|
|
1523
|
-
const normalizeLinkPrefix = (link, currentLang)=>{
|
|
1524
|
-
const normalizedLink = (0, shared_.slash)(link);
|
|
1525
|
-
if (!currentLang || !link || normalizedLink.startsWith(`/${currentLang}`) || (0, shared_.isExternalUrl)(normalizedLink) || hasMultiVersion) return normalizedLink;
|
|
1526
|
-
return lang === currentLang ? normalizedLink : `/${currentLang}${(0, shared_.addLeadingSlash)(normalizedLink)}`;
|
|
1527
|
-
};
|
|
1528
|
-
const getI18nText = (key, currentLang)=>{
|
|
1529
|
-
const text = i18nTextData[key]?.[currentLang];
|
|
1530
|
-
return text || key;
|
|
1531
|
-
};
|
|
1532
|
-
const cleanUrls = false;
|
|
1533
|
-
const transformLink = (link, currentLang)=>(0, shared_.normalizeHref)(normalizeLinkPrefix(link, currentLang), cleanUrls);
|
|
1534
|
-
const textReplace = (text, currentLang)=>applyReplaceRules(getI18nText(text, currentLang), replaceRules);
|
|
1535
|
-
const normalizeSidebar = (sidebar, currentLang)=>{
|
|
1536
|
-
const normalizedSidebar = {};
|
|
1537
|
-
if (!sidebar) return {};
|
|
1538
|
-
const normalizeSidebarItem = (item)=>{
|
|
1539
|
-
if ('object' == typeof item && 'dividerType' in item) return item;
|
|
1540
|
-
if ('object' == typeof item && 'sectionHeaderText' in item) {
|
|
1541
|
-
item.sectionHeaderText = textReplace(item.sectionHeaderText, currentLang);
|
|
1542
|
-
return item;
|
|
1543
|
-
}
|
|
1544
|
-
if ('object' == typeof item && 'items' in item) return {
|
|
1545
|
-
...item,
|
|
1546
|
-
text: textReplace(item.text, currentLang),
|
|
1547
|
-
...'link' in item && item.link ? {
|
|
1548
|
-
link: transformLink(item.link, currentLang)
|
|
1549
|
-
} : {},
|
|
1550
|
-
collapsed: item.collapsed ?? false,
|
|
1551
|
-
collapsible: item.collapsible ?? true,
|
|
1552
|
-
items: item.items.map((subItem)=>normalizeSidebarItem(subItem))
|
|
1553
|
-
};
|
|
1554
|
-
return {
|
|
1555
|
-
...item,
|
|
1556
|
-
text: textReplace(item.text, currentLang),
|
|
1557
|
-
link: transformLink(item.link, currentLang)
|
|
1558
|
-
};
|
|
1559
|
-
};
|
|
1560
|
-
const normalizeSidebar = (sidebar)=>{
|
|
1561
|
-
Object.keys(sidebar).forEach((key)=>{
|
|
1562
|
-
const value = sidebar[key];
|
|
1563
|
-
normalizedSidebar[key] = value.map(normalizeSidebarItem);
|
|
1564
|
-
});
|
|
1565
|
-
};
|
|
1566
|
-
normalizeSidebar(sidebar);
|
|
1567
|
-
return normalizedSidebar;
|
|
1568
|
-
};
|
|
1569
|
-
const normalizeNav = (nav, currentLang)=>{
|
|
1570
|
-
if (!nav) return [];
|
|
1571
|
-
const transformNavItem = (navItem)=>({
|
|
1572
|
-
...navItem,
|
|
1573
|
-
...navItem.text ? {
|
|
1574
|
-
text: textReplace(navItem.text, currentLang)
|
|
1575
|
-
} : {},
|
|
1576
|
-
...'link' in navItem ? {
|
|
1577
|
-
link: transformLink(navItem.link, currentLang)
|
|
1578
|
-
} : {},
|
|
1579
|
-
...'items' in navItem ? {
|
|
1580
|
-
items: navItem.items.map((item)=>transformNavItem(item))
|
|
1581
|
-
} : {}
|
|
1582
|
-
});
|
|
1583
|
-
if (Array.isArray(nav)) return nav.map(transformNavItem);
|
|
1584
|
-
return Object.entries(nav).reduce((acc, [key, value])=>{
|
|
1585
|
-
acc[key] = value.map(transformNavItem);
|
|
1586
|
-
return acc;
|
|
1587
|
-
}, {});
|
|
1588
|
-
};
|
|
1589
|
-
if (locales.length) themeConfig.locales = locales.map(({ lang: currentLang, label })=>{
|
|
1590
|
-
const localeInThemeConfig = themeConfig.locales?.find((locale)=>locale.lang === currentLang);
|
|
1591
|
-
return {
|
|
1592
|
-
lang: currentLang,
|
|
1593
|
-
label,
|
|
1594
|
-
...localeInThemeConfig,
|
|
1595
|
-
sidebar: normalizeSidebar(localeInThemeConfig?.sidebar ?? themeConfig.sidebar, currentLang),
|
|
1596
|
-
nav: normalizeNav(localeInThemeConfig?.nav ?? themeConfig.nav, currentLang)
|
|
1597
|
-
};
|
|
1598
|
-
});
|
|
1599
|
-
else {
|
|
1600
|
-
themeConfig.sidebar = normalizeSidebar(themeConfig?.sidebar, '');
|
|
1601
|
-
themeConfig.nav = normalizeNav(themeConfig?.nav, '');
|
|
1602
|
-
}
|
|
1603
|
-
return themeConfig;
|
|
1604
|
-
}
|
|
1605
|
-
async function createSiteData(userConfig) {
|
|
1606
|
-
const tempSearchObj = Object.assign({}, userConfig.search);
|
|
1607
|
-
if (tempSearchObj) tempSearchObj.searchHooks = void 0;
|
|
1608
|
-
const siteData = {
|
|
1609
|
-
base: userConfig.base ?? '/',
|
|
1610
|
-
title: userConfig?.title || '',
|
|
1611
|
-
description: userConfig?.description || '',
|
|
1612
|
-
icon: getIconUrlPath(userConfig?.icon) || '',
|
|
1613
|
-
route: userConfig?.route || {},
|
|
1614
|
-
themeConfig: await normalizeThemeConfig(userConfig),
|
|
1615
|
-
lang: userConfig?.lang || '',
|
|
1616
|
-
locales: userConfig?.locales || userConfig.themeConfig?.locales || [],
|
|
1617
|
-
logo: userConfig?.logo || '',
|
|
1618
|
-
logoText: userConfig?.logoText || '',
|
|
1619
|
-
multiVersion: {
|
|
1620
|
-
default: userConfig?.multiVersion?.default || '',
|
|
1621
|
-
versions: userConfig?.multiVersion?.versions || []
|
|
1622
|
-
},
|
|
1623
|
-
search: tempSearchObj ?? {
|
|
1624
|
-
mode: 'local'
|
|
1625
|
-
},
|
|
1626
|
-
markdown: {
|
|
1627
|
-
showLineNumbers: userConfig?.markdown?.showLineNumbers ?? false,
|
|
1628
|
-
defaultWrapCode: userConfig?.markdown?.defaultWrapCode ?? false,
|
|
1629
|
-
shiki: {}
|
|
1630
|
-
}
|
|
1631
|
-
};
|
|
1632
|
-
return {
|
|
1633
|
-
siteData
|
|
1634
|
-
};
|
|
1635
|
-
}
|
|
1636
|
-
const siteDataVMPlugin = (context)=>{
|
|
1637
|
-
const { config, pluginDriver } = context;
|
|
1638
|
-
return {
|
|
1639
|
-
["virtual-site-data"]: async ({ addDependency })=>{
|
|
1640
|
-
const force = !pluginDriver.haveNavSidebarConfig;
|
|
1641
|
-
const metaFileSet = new Set();
|
|
1642
|
-
const mdFileSet = new Set();
|
|
1643
|
-
const now = performance.now();
|
|
1644
|
-
try {
|
|
1645
|
-
await modifyConfigWithAutoNavSide(config, metaFileSet, mdFileSet, force);
|
|
1646
|
-
} finally{
|
|
1647
|
-
for (const metaFile of metaFileSet)addDependency(metaFile);
|
|
1648
|
-
for (const mdFile of mdFileSet)addDependency(mdFile);
|
|
1649
|
-
logger.debug(`modifyConfigWithAutoNavSide - size: ${mdFileSet.size} cost: ${performance.now() - now}ms`);
|
|
1650
|
-
}
|
|
1651
|
-
const { siteData } = await createSiteData(config);
|
|
1652
|
-
return `export default ${JSON.stringify(siteData, null, 2)}`;
|
|
1653
|
-
}
|
|
1654
|
-
};
|
|
1655
|
-
};
|
|
1656
|
-
const presetIcons = {
|
|
1657
|
-
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"/>',
|
|
1658
|
-
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"/>',
|
|
1659
|
-
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"/>',
|
|
1660
|
-
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"/>',
|
|
1661
|
-
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"/>',
|
|
1662
|
-
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"/>',
|
|
1663
|
-
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"/>',
|
|
1664
|
-
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"/>',
|
|
1665
|
-
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"/>',
|
|
1666
|
-
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"/>',
|
|
1667
|
-
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"/>',
|
|
1668
|
-
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"/>',
|
|
1669
|
-
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"/>',
|
|
1670
|
-
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"/>',
|
|
1671
|
-
lark: '<path d="M6.14 3.8a28.88 28.88 0 0 1 6.6 7.63l1.7-1.67a8.37 8.37 0 0 1 2.82-1.83 12.23 12.23 0 0 0-2.32-4.28.67.67 0 0 0-.53-.25H6.28c-.21 0-.3.27-.14.4Z" fill="currentColor"></path><path d="m20.57 14.2.01-.02.04-.07-.05.08Z" fill="currentColor"></path><path d="M11.04 14.56c1.23.52 2.34.97 3.65 1.32a4.75 4.75 0 0 0 5.63-2.4l1.32-2.63c.3-.64.67-1.23 1.12-1.78a6.2 6.2 0 0 0-2.3-.44c-1.9 0-3.7.73-5.06 2.06l-2.02 2c-.72.7-1.5 1.33-2.34 1.87Z" fill="currentColor"></path><path d="M20.8 13.78v-.02l.01-.01s0 .02-.02.03Z" fill="currentColor"></path><path d="M1.63 9.75a.23.23 0 0 0-.4.16v7.96c0 .23.12.44.3.56a12.95 12.95 0 0 0 14.08.2c.78-.5 1.39-.92 2.04-1.55-1.05.3-2.2.33-3.37.01A28.99 28.99 0 0 1 1.63 9.75Z" fill="currentColor"></path>',
|
|
1672
|
-
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"/>',
|
|
1673
|
-
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"/>',
|
|
1674
|
-
npm: '<path fill="currentColor" d="M1.763 0C.786 0 0 .786 0 1.763v20.474C0 23.214.786 24 1.763 24h20.474c.977 0 1.763-.786 1.763-1.763V1.763C24 .786 23.214 0 22.237 0zM5.13 5.323l13.837.019l-.009 13.836h-3.464l.01-10.382h-3.456L12.04 19.17H5.113z"/>'
|
|
1675
|
-
};
|
|
1676
|
-
const formatIconName = (icon)=>icon.toLowerCase();
|
|
1677
|
-
function getSocialIcons(socialLinks = []) {
|
|
1678
|
-
const icons = {};
|
|
1679
|
-
for (const link of socialLinks)if ('string' == typeof link.icon) {
|
|
1680
|
-
const pathContent = presetIcons[formatIconName(link.icon)];
|
|
1681
|
-
if (!pathContent) throw new Error(`Icon "${link.icon}" not found in preset icons.`);
|
|
1682
|
-
icons[link.icon] = `<svg xmlns="http://www.w3.org/2000/svg" width="100%" viewBox="0 0 24 24">${pathContent}</svg>`;
|
|
1683
|
-
}
|
|
1684
|
-
return icons;
|
|
1685
|
-
}
|
|
1686
|
-
const socialLinksVMPlugin = (context)=>{
|
|
1687
|
-
const { config } = context;
|
|
1688
|
-
return {
|
|
1689
|
-
["virtual-social-links"]: ()=>`export default ${JSON.stringify(getSocialIcons(config.themeConfig?.socialLinks), null, 2)}`
|
|
1690
|
-
};
|
|
1691
|
-
};
|
|
1692
|
-
async function pMap(iterable, mapper, { concurrency = 1 / 0, stopOnError = true, signal } = {}) {
|
|
1693
|
-
return new Promise((resolve_, reject_)=>{
|
|
1694
|
-
if (void 0 === iterable[Symbol.iterator] && void 0 === iterable[Symbol.asyncIterator]) throw new TypeError(`Expected \`input\` to be either an \`Iterable\` or \`AsyncIterable\`, got (${typeof iterable})`);
|
|
1695
|
-
if ('function' != typeof mapper) throw new TypeError('Mapper function is required');
|
|
1696
|
-
if (!(Number.isSafeInteger(concurrency) && concurrency >= 1 || concurrency === 1 / 0)) throw new TypeError(`Expected \`concurrency\` to be an integer from 1 and up or \`Infinity\`, got \`${concurrency}\` (${typeof concurrency})`);
|
|
1697
|
-
const result = [];
|
|
1698
|
-
const errors = [];
|
|
1699
|
-
const skippedIndexesMap = new Map();
|
|
1700
|
-
let isRejected = false;
|
|
1701
|
-
let isResolved = false;
|
|
1702
|
-
let isIterableDone = false;
|
|
1703
|
-
let resolvingCount = 0;
|
|
1704
|
-
let currentIndex = 0;
|
|
1705
|
-
const iterator = void 0 === iterable[Symbol.iterator] ? iterable[Symbol.asyncIterator]() : iterable[Symbol.iterator]();
|
|
1706
|
-
const signalListener = ()=>{
|
|
1707
|
-
reject(signal.reason);
|
|
1708
|
-
};
|
|
1709
|
-
const cleanup = ()=>{
|
|
1710
|
-
signal?.removeEventListener('abort', signalListener);
|
|
1711
|
-
};
|
|
1712
|
-
const resolve = (value)=>{
|
|
1713
|
-
resolve_(value);
|
|
1714
|
-
cleanup();
|
|
1715
|
-
};
|
|
1716
|
-
const reject = (reason)=>{
|
|
1717
|
-
isRejected = true;
|
|
1718
|
-
isResolved = true;
|
|
1719
|
-
reject_(reason);
|
|
1720
|
-
cleanup();
|
|
1721
|
-
};
|
|
1722
|
-
if (signal) {
|
|
1723
|
-
if (signal.aborted) reject(signal.reason);
|
|
1724
|
-
signal.addEventListener('abort', signalListener, {
|
|
1725
|
-
once: true
|
|
1726
|
-
});
|
|
1727
|
-
}
|
|
1728
|
-
const next = async ()=>{
|
|
1729
|
-
if (isResolved) return;
|
|
1730
|
-
const nextItem = await iterator.next();
|
|
1731
|
-
const index = currentIndex;
|
|
1732
|
-
currentIndex++;
|
|
1733
|
-
if (nextItem.done) {
|
|
1734
|
-
isIterableDone = true;
|
|
1735
|
-
if (0 === resolvingCount && !isResolved) {
|
|
1736
|
-
if (!stopOnError && errors.length > 0) return void reject(new AggregateError(errors));
|
|
1737
|
-
isResolved = true;
|
|
1738
|
-
if (0 === skippedIndexesMap.size) return void resolve(result);
|
|
1739
|
-
const pureResult = [];
|
|
1740
|
-
for (const [index, value] of result.entries())if (skippedIndexesMap.get(index) !== pMapSkip) pureResult.push(value);
|
|
1741
|
-
resolve(pureResult);
|
|
1742
|
-
}
|
|
1743
|
-
return;
|
|
1744
|
-
}
|
|
1745
|
-
resolvingCount++;
|
|
1746
|
-
(async ()=>{
|
|
1747
|
-
try {
|
|
1748
|
-
const element = await nextItem.value;
|
|
1749
|
-
if (isResolved) return;
|
|
1750
|
-
const value = await mapper(element, index);
|
|
1751
|
-
if (value === pMapSkip) skippedIndexesMap.set(index, value);
|
|
1752
|
-
result[index] = value;
|
|
1753
|
-
resolvingCount--;
|
|
1754
|
-
await next();
|
|
1755
|
-
} catch (error) {
|
|
1756
|
-
if (stopOnError) reject(error);
|
|
1757
|
-
else {
|
|
1758
|
-
errors.push(error);
|
|
1759
|
-
resolvingCount--;
|
|
1760
|
-
try {
|
|
1761
|
-
await next();
|
|
1762
|
-
} catch (error) {
|
|
1763
|
-
reject(error);
|
|
1764
|
-
}
|
|
1765
|
-
}
|
|
1766
|
-
}
|
|
1767
|
-
})();
|
|
1768
|
-
};
|
|
1769
|
-
(async ()=>{
|
|
1770
|
-
for(let index = 0; index < concurrency; index++){
|
|
1771
|
-
try {
|
|
1772
|
-
await next();
|
|
1773
|
-
} catch (error) {
|
|
1774
|
-
reject(error);
|
|
1775
|
-
break;
|
|
1776
|
-
}
|
|
1777
|
-
if (isIterableDone || isRejected) break;
|
|
1778
|
-
}
|
|
1779
|
-
})();
|
|
1780
|
-
});
|
|
1781
|
-
}
|
|
1782
|
-
const pMapSkip = Symbol('skip');
|
|
1783
|
-
async function renderConfigHead(head, route) {
|
|
1784
|
-
if (!isRouteMeta(route)) return '';
|
|
1785
|
-
if (!head || 0 === head.length) return '';
|
|
1786
|
-
return head.map((head)=>{
|
|
1787
|
-
if ('string' == typeof head) return head;
|
|
1788
|
-
if ('function' == typeof head) {
|
|
1789
|
-
const resultHead = head(route);
|
|
1790
|
-
if (!resultHead) return '';
|
|
1791
|
-
if ('string' == typeof resultHead) return resultHead;
|
|
1792
|
-
return `<${resultHead[0]} ${renderAttrs(resultHead[1])}>`;
|
|
1793
|
-
}
|
|
1794
|
-
return `<${head[0]} ${renderAttrs(head[1])}>`;
|
|
1795
|
-
}).join('');
|
|
1796
|
-
}
|
|
1797
|
-
async function renderHtmlTemplate(htmlTemplate, head, route, appHtml = '') {
|
|
1798
|
-
const replacedHtmlTemplate = htmlTemplate.replace(APP_HTML_MARKER, ()=>appHtml).replace(META_GENERATOR, ()=>`<meta name="generator" content="Rspress v${RSPRESS_VERSION}">`).replace(HEAD_MARKER, [
|
|
1799
|
-
await renderConfigHead(head, route)
|
|
1800
|
-
].join(''));
|
|
1801
|
-
return replacedHtmlTemplate;
|
|
1802
|
-
}
|
|
1803
|
-
function renderAttrs(attrs) {
|
|
1804
|
-
return Object.entries(attrs).map(([key, value])=>{
|
|
1805
|
-
if ('boolean' == typeof value) return key;
|
|
1806
|
-
if ('string' == typeof value || 'number' == typeof value) return `${key}="${value}"`;
|
|
1807
|
-
throw new Error(`Invalid value for attribute ${key}:${JSON.stringify(value)}`);
|
|
1808
|
-
}).join('');
|
|
1809
|
-
}
|
|
1810
|
-
function isRouteMeta(route) {
|
|
1811
|
-
return !!route && 'object' == typeof route && 'routePath' in route && 'absolutePath' in route;
|
|
1812
|
-
}
|
|
1813
|
-
async function renderPage(route, htmlTemplate, configHead, ssrBundlePath) {
|
|
1814
|
-
let render;
|
|
1815
|
-
try {
|
|
1816
|
-
const { default: ssrExports } = await import((0, external_node_url_.pathToFileURL)(ssrBundlePath).toString());
|
|
1817
|
-
render = await ssrExports.render;
|
|
1818
|
-
} catch (e) {
|
|
1819
|
-
if (e instanceof Error) {
|
|
1820
|
-
logger.error(`Failed to load SSG bundle: ${picocolors.yellow(ssrBundlePath)}: ${e.message}`);
|
|
1821
|
-
logger.debug(e);
|
|
1822
|
-
hintSSGFailed();
|
|
1823
|
-
}
|
|
1824
|
-
throw e;
|
|
1825
|
-
}
|
|
1826
|
-
const head = createHead();
|
|
1827
|
-
const { routePath, absolutePath } = route;
|
|
1828
|
-
let appHtml = '';
|
|
1829
|
-
if (render) try {
|
|
1830
|
-
({ appHtml } = await render(routePath, head));
|
|
1831
|
-
} catch (e) {
|
|
1832
|
-
if (e instanceof Error) {
|
|
1833
|
-
logger.error(`Page "${picocolors.yellow(routePath)}" SSG rendering failed.
|
|
1834
|
-
${absolutePath ? picocolors.gray(` File: ${absolutePath}\n`) : ''} ${picocolors.gray(e.toString())}`);
|
|
1835
|
-
throw e;
|
|
1836
|
-
}
|
|
1837
|
-
}
|
|
1838
|
-
const replacedHtmlTemplate = await renderHtmlTemplate(htmlTemplate, configHead, route, appHtml);
|
|
1839
|
-
const html = await transformHtmlTemplate(head, replacedHtmlTemplate);
|
|
1840
|
-
return html;
|
|
1841
|
-
}
|
|
1842
|
-
/**
|
|
1843
|
-
* these codes are copied from
|
|
1844
|
-
* @link https://github.com/facebook/docusaurus/blob/45065e8d2b5831117b8d69fec1be28f5520cf105/packages/docusaurus/src/ssg/ssgEnv.ts#L11
|
|
1845
|
-
* @license MIT
|
|
1846
|
-
*/ function SSGWorkerThreadTaskSize() {
|
|
1847
|
-
return process.env.RSPRESS_SSG_WORKER_THREAD_TASK_SIZE ? Number.parseInt(process.env.RSPRESS_SSG_WORKER_THREAD_TASK_SIZE, 10) : 10;
|
|
1848
|
-
}
|
|
1849
|
-
function SSGWorkerThreadRecyclerMaxMemory() {
|
|
1850
|
-
return process.env.RSPRESS_SSG_WORKER_THREAD_RECYCLER_MAX_MEMORY ? Number.parseInt(process.env.RSPRESS_SSG_WORKER_THREAD_RECYCLER_MAX_MEMORY, 10) : 1000000000;
|
|
1851
|
-
}
|
|
1852
|
-
function inferNumberOfThreads({ pageCount, cpuCount, minPagesPerCpu }) {
|
|
1853
|
-
const threadsByWorkload = Math.ceil(pageCount / minPagesPerCpu);
|
|
1854
|
-
return Math.max(1, Math.min(threadsByWorkload, cpuCount));
|
|
1855
|
-
}
|
|
1856
|
-
function SSGWorkerThreadCount() {
|
|
1857
|
-
return process.env.RSPRESS_SSG_WORKER_THREAD_COUNT ? Number.parseInt(process.env.RSPRESS_SSG_WORKER_THREAD_COUNT, 10) : void 0;
|
|
1858
|
-
}
|
|
1859
|
-
function getNumberOfThreads(pathnamesLength) {
|
|
1860
|
-
const workerCount = SSGWorkerThreadCount();
|
|
1861
|
-
if (void 0 !== workerCount) return workerCount;
|
|
1862
|
-
const cpuCount = 'function' == typeof external_node_os_["default"].availableParallelism ? external_node_os_["default"].availableParallelism() : external_node_os_["default"].cpus().length;
|
|
1863
|
-
return inferNumberOfThreads({
|
|
1864
|
-
pageCount: pathnamesLength,
|
|
1865
|
-
cpuCount,
|
|
1866
|
-
minPagesPerCpu: 100
|
|
1867
|
-
});
|
|
1868
|
-
}
|
|
1869
|
-
function SSGConcurrency() {
|
|
1870
|
-
return process.env.RSPRESS_SSG_CONCURRENCY ? Number.parseInt(process.env.RSPRESS_SSG_CONCURRENCY, 10) : 32;
|
|
1871
|
-
}
|
|
1872
|
-
const routePath2HtmlFileName = (routePath)=>{
|
|
1873
|
-
let fileName = routePath;
|
|
1874
|
-
fileName = fileName.endsWith('/') ? `${routePath}index.html` : `${routePath}.html`;
|
|
1875
|
-
return fileName.replace(/^\/+/, '');
|
|
1876
|
-
};
|
|
1877
|
-
async function renderPages(routeService, config, ssrBundlePath, htmlTemplate, emitAsset) {
|
|
1878
|
-
logger.info('Rendering pages...');
|
|
1879
|
-
const startTime = Date.now();
|
|
1880
|
-
const ssg = config.ssg || true;
|
|
1881
|
-
try {
|
|
1882
|
-
const routes = routeService.getRoutes();
|
|
1883
|
-
if (!routeService.isExistRoute('/404')) routes.push({
|
|
1884
|
-
routePath: '/404'
|
|
1885
|
-
});
|
|
1886
|
-
if ('object' == typeof ssg && Array.isArray(ssg?.experimentalExcludeRoutePaths) && ssg.experimentalExcludeRoutePaths.length > 0) {
|
|
1887
|
-
const shouldIgnoreRoutePaths = new Set();
|
|
1888
|
-
const shouldIgnoreRoutePathsRegExp = [];
|
|
1889
|
-
for (const routePath of ssg.experimentalExcludeRoutePaths)if ('string' == typeof routePath) shouldIgnoreRoutePaths.add(routePath);
|
|
1890
|
-
else if (routePath instanceof RegExp) shouldIgnoreRoutePathsRegExp.push(routePath);
|
|
1891
|
-
const promiseList = [];
|
|
1892
|
-
const csrRoutes = [];
|
|
1893
|
-
const ssgRoutes = [];
|
|
1894
|
-
for (const route of routes)if (shouldIgnoreRoutePaths.has(route.routePath) || shouldIgnoreRoutePathsRegExp.some((reg)=>reg.test(route.routePath))) {
|
|
1895
|
-
csrRoutes.push(route);
|
|
1896
|
-
promiseList.push(renderCSRPage(config.head, route, htmlTemplate, emitAsset));
|
|
1897
|
-
} else ssgRoutes.push(route);
|
|
1898
|
-
if (csrRoutes.length > 0) {
|
|
1899
|
-
logger.warn(`Some routes are ignored in SSG and fallback to CSR via \`ssg.experimentalExcludeRoutePaths\`: ${picocolors.yellow(csrRoutes.map((r)=>r.routePath).join(', '))}`);
|
|
1900
|
-
await Promise.all(promiseList);
|
|
1901
|
-
routes.length = 0;
|
|
1902
|
-
routes.push(...ssgRoutes);
|
|
1903
|
-
}
|
|
1904
|
-
}
|
|
1905
|
-
if ('object' == typeof ssg && ssg?.experimentalWorker) {
|
|
1906
|
-
const numberOfThreads = getNumberOfThreads(routes.length);
|
|
1907
|
-
const Tinypool = await import("tinypool").then((m)=>m.default);
|
|
1908
|
-
const pool = new Tinypool({
|
|
1909
|
-
filename: new URL('./renderPageWorker.js', import.meta.url).href,
|
|
1910
|
-
concurrentTasksPerWorker: 1,
|
|
1911
|
-
minThreads: numberOfThreads,
|
|
1912
|
-
maxThreads: numberOfThreads,
|
|
1913
|
-
/**
|
|
1914
|
-
* https://github.com/facebook/docusaurus/blob/0306d182407bb98f140cd5ec7481fa9608fe0297/packages/docusaurus/src/ssg/ssgExecutor.ts#L123
|
|
1915
|
-
* @license MIT
|
|
1916
|
-
*/ maxMemoryLimitBeforeRecycle: SSGWorkerThreadRecyclerMaxMemory(),
|
|
1917
|
-
isolateWorkers: false,
|
|
1918
|
-
workerData: {
|
|
1919
|
-
params: {
|
|
1920
|
-
htmlTemplate,
|
|
1921
|
-
head: config.head,
|
|
1922
|
-
ssrBundlePath
|
|
1923
|
-
}
|
|
1924
|
-
}
|
|
1925
|
-
});
|
|
1926
|
-
await Promise.all(chunk(routes, SSGWorkerThreadTaskSize()).map(async (routes)=>{
|
|
1927
|
-
const htmlList = await pool.run({
|
|
1928
|
-
routes
|
|
1929
|
-
});
|
|
1930
|
-
for(let i = 0; i < routes.length; i++){
|
|
1931
|
-
const route = routes[i];
|
|
1932
|
-
const html = htmlList[i];
|
|
1933
|
-
const fileName = routePath2HtmlFileName(route.routePath);
|
|
1934
|
-
emitAsset(fileName, html);
|
|
1935
|
-
}
|
|
1936
|
-
}));
|
|
1937
|
-
await pool.destroy();
|
|
1938
|
-
} else await pMap(routes, async (route)=>{
|
|
1939
|
-
const html = await renderPage(route, htmlTemplate, config.head, ssrBundlePath);
|
|
1940
|
-
const fileName = routePath2HtmlFileName(route.routePath);
|
|
1941
|
-
emitAsset(fileName, html);
|
|
1942
|
-
}, {
|
|
1943
|
-
concurrency: SSGConcurrency()
|
|
1944
|
-
});
|
|
1945
|
-
const totalTime = Date.now() - startTime;
|
|
1946
|
-
logger.success(`Pages rendered in ${picocolors.yellow(totalTime)} ms.`);
|
|
1947
|
-
} catch (e) {
|
|
1948
|
-
if (e instanceof Error) {
|
|
1949
|
-
logger.error(`Pages render error: ${e.message}`);
|
|
1950
|
-
logger.debug(e);
|
|
1951
|
-
hintSSGFailed();
|
|
1952
|
-
}
|
|
1953
|
-
throw e;
|
|
1954
|
-
}
|
|
1955
|
-
}
|
|
1956
|
-
async function renderCSRPage(head, route, htmlTemplate, emitAsset) {
|
|
1957
|
-
const html = await renderHtmlTemplate(htmlTemplate, head, route, '');
|
|
1958
|
-
const fileName = routePath2HtmlFileName(route.routePath);
|
|
1959
|
-
emitAsset(fileName, html);
|
|
1960
|
-
}
|
|
1961
|
-
async function renderCSRPages(routeService, config, htmlTemplate, emitAsset) {
|
|
1962
|
-
const routes = routeService.getRoutes();
|
|
1963
|
-
if (!routeService.isExistRoute('/404')) routes.push({
|
|
1964
|
-
routePath: '/404'
|
|
1965
|
-
});
|
|
1966
|
-
await Promise.all(routes.map((route)=>renderCSRPage(config.head, route, htmlTemplate, emitAsset)));
|
|
1967
|
-
}
|
|
1968
|
-
const rsbuildPluginCSR = ({ routeService, config })=>({
|
|
1969
|
-
name: 'rspress-inner-rsbuild-plugin-csr',
|
|
1970
|
-
async setup (api) {
|
|
1971
|
-
api.onBeforeBuild(()=>{
|
|
1972
|
-
api.processAssets({
|
|
1973
|
-
stage: 'report',
|
|
1974
|
-
environments: [
|
|
1975
|
-
'web'
|
|
1976
|
-
]
|
|
1977
|
-
}, async ({ assets, compilation, compiler })=>{
|
|
1978
|
-
if (compilation.errors.length > 0) return;
|
|
1979
|
-
const emitAsset = (assetName, content)=>{
|
|
1980
|
-
compilation.emitAsset(assetName, new compiler.webpack.sources.RawSource(content));
|
|
1981
|
-
};
|
|
1982
|
-
let htmlTemplate = '';
|
|
1983
|
-
for (const [assetName, assetSource] of Object.entries(assets))if ('index.html' === assetName) {
|
|
1984
|
-
htmlTemplate = assetSource.source().toString();
|
|
1985
|
-
compilation.deleteAsset(assetName);
|
|
1986
|
-
break;
|
|
1987
|
-
}
|
|
1988
|
-
await renderCSRPages(routeService, config, htmlTemplate, emitAsset);
|
|
1989
|
-
});
|
|
1990
|
-
});
|
|
1991
|
-
}
|
|
1992
|
-
});
|
|
1993
|
-
const rsbuildPluginSSG = ({ routeService, config })=>({
|
|
1994
|
-
name: 'rspress-inner-rsbuild-plugin-ssg',
|
|
1995
|
-
async setup (api) {
|
|
1996
|
-
api.onBeforeBuild(()=>{
|
|
1997
|
-
let htmlTemplate = '';
|
|
1998
|
-
let hasError = false;
|
|
1999
|
-
const indexHtmlEmittedInWeb = new Promise((resolve, reject)=>{
|
|
2000
|
-
api.processAssets({
|
|
2001
|
-
stage: 'report',
|
|
2002
|
-
environments: [
|
|
2003
|
-
'web'
|
|
2004
|
-
]
|
|
2005
|
-
}, ({ assets, compilation })=>{
|
|
2006
|
-
if (compilation.errors.length > 0) {
|
|
2007
|
-
hasError = true;
|
|
2008
|
-
return;
|
|
2009
|
-
}
|
|
2010
|
-
for (const [assetName, assetSource] of Object.entries(assets))if ('index.html' === assetName) {
|
|
2011
|
-
htmlTemplate = assetSource.source().toString();
|
|
2012
|
-
compilation.deleteAsset(assetName);
|
|
2013
|
-
resolve();
|
|
2014
|
-
break;
|
|
2015
|
-
}
|
|
2016
|
-
reject();
|
|
2017
|
-
});
|
|
2018
|
-
}).catch(()=>{
|
|
2019
|
-
const message = 'SSG requires an `index.html` as entry, but this file is not emitted successfully in the web target.';
|
|
2020
|
-
logger.error(message);
|
|
2021
|
-
const error = new Error(message);
|
|
2022
|
-
throw error;
|
|
2023
|
-
});
|
|
2024
|
-
api.processAssets({
|
|
2025
|
-
stage: 'optimize-transfer',
|
|
2026
|
-
environments: [
|
|
2027
|
-
'node'
|
|
2028
|
-
]
|
|
2029
|
-
}, async ({ assets, compilation, environment, compiler })=>{
|
|
2030
|
-
if (compilation.errors.length > 0) {
|
|
2031
|
-
hasError = true;
|
|
2032
|
-
return;
|
|
2033
|
-
}
|
|
2034
|
-
if (hasError) return;
|
|
2035
|
-
const emitAsset = (assetName, content)=>{
|
|
2036
|
-
compilation.emitAsset(assetName, new compiler.webpack.sources.RawSource(content));
|
|
2037
|
-
};
|
|
2038
|
-
const distPath = environment.distPath;
|
|
2039
|
-
const ssgFolderPath = (0, external_node_path_.join)(distPath, NODE_SSG_BUNDLE_FOLDER);
|
|
2040
|
-
const mainCjsAbsolutePath = (0, external_node_path_.join)(ssgFolderPath, NODE_SSG_BUNDLE_NAME);
|
|
2041
|
-
await mkdir(ssgFolderPath, {
|
|
2042
|
-
recursive: true
|
|
2043
|
-
});
|
|
2044
|
-
await Promise.all(Object.entries(assets).map(async ([assetName, assetSource])=>{
|
|
2045
|
-
if (assetName.startsWith(`${NODE_SSG_BUNDLE_FOLDER}/`)) {
|
|
2046
|
-
const fileAbsolutePath = (0, external_node_path_.join)(distPath, assetName);
|
|
2047
|
-
await writeFile(fileAbsolutePath, assetSource.source().toString());
|
|
2048
|
-
compilation.deleteAsset(assetName);
|
|
2049
|
-
}
|
|
2050
|
-
}));
|
|
2051
|
-
await indexHtmlEmittedInWeb;
|
|
2052
|
-
await renderPages(routeService, config, mainCjsAbsolutePath, htmlTemplate, emitAsset);
|
|
2053
|
-
if (!(0, shared_.isDebugMode)()) await rm(ssgFolderPath, {
|
|
2054
|
-
recursive: true
|
|
2055
|
-
});
|
|
2056
|
-
});
|
|
2057
|
-
});
|
|
2058
|
-
}
|
|
2059
|
-
});
|
|
2060
|
-
function routePathToMdPath(routePath, base) {
|
|
2061
|
-
let url = routePath;
|
|
2062
|
-
url = (0, shared_.normalizeHref)(url, false);
|
|
2063
|
-
url = url.replace(/\.html$/, '.md');
|
|
2064
|
-
return (0, shared_.withBase)(url, base);
|
|
2065
|
-
}
|
|
2066
|
-
async function generateLlmsTxt(routeGroups, others, navList, title, description, base, routeService) {
|
|
2067
|
-
const lines = [];
|
|
2068
|
-
const summary = `# ${title}${description ? `\n\n> ${description}` : ''}`;
|
|
2069
|
-
async function genH2Part(nav, routes) {
|
|
2070
|
-
const lines = [];
|
|
2071
|
-
const { text } = nav;
|
|
2072
|
-
if (0 === routes.length) return lines;
|
|
2073
|
-
const routeLines = (await Promise.all(routes.map(async (route)=>{
|
|
2074
|
-
const routePage = routeService.getRoutePageByRoutePath(route);
|
|
2075
|
-
const { lang, routePath, absolutePath } = routePage.routeMeta;
|
|
2076
|
-
if ('/' === routePath || routePath === `/${lang}/`) return;
|
|
2077
|
-
const { title, description } = await extractInfoFromFrontmatterWithAbsolutePath(absolutePath, routeService.getDocsDir());
|
|
2078
|
-
return `- [${title}](${routePathToMdPath(routePath, base)})${description ? `: ${description}` : ''}`;
|
|
2079
|
-
}))).filter((i)=>Boolean(i));
|
|
2080
|
-
if (routeLines.length > 0) {
|
|
2081
|
-
const title = text;
|
|
2082
|
-
lines.push(`\n## ${title}\n`);
|
|
2083
|
-
lines.push(...routeLines);
|
|
2084
|
-
}
|
|
2085
|
-
return lines;
|
|
2086
|
-
}
|
|
2087
|
-
const h2Parts = await Promise.all(navList.map(async (nav, i)=>{
|
|
2088
|
-
const routes = routeGroups[i];
|
|
2089
|
-
const h2Part = await genH2Part(nav, routes);
|
|
2090
|
-
return h2Part;
|
|
2091
|
-
}));
|
|
2092
|
-
lines.push(...h2Parts.flat());
|
|
2093
|
-
const otherLines = await genH2Part({
|
|
2094
|
-
text: 'Others'
|
|
2095
|
-
}, others);
|
|
2096
|
-
lines.push(...otherLines);
|
|
2097
|
-
const llmsTxt = `${summary}\n${lines.join('\n')}`;
|
|
2098
|
-
return llmsTxt;
|
|
2099
|
-
}
|
|
2100
|
-
function generateLlmsFullTxt(routeGroups, navList, others, base, mdContents) {
|
|
2101
|
-
const lines = [];
|
|
2102
|
-
for(let i = 0; i < navList.length; i++){
|
|
2103
|
-
const routeGroup = routeGroups[i];
|
|
2104
|
-
if (0 !== routeGroup.length) for (const routePath of routeGroup){
|
|
2105
|
-
lines.push(`---
|
|
2106
|
-
url: ${routePathToMdPath(routePath, base)}
|
|
2107
|
-
---
|
|
2108
|
-
`);
|
|
2109
|
-
lines.push(mdContents.get(routePath) ?? '');
|
|
2110
|
-
lines.push('\n');
|
|
2111
|
-
}
|
|
2112
|
-
}
|
|
2113
|
-
for (const routePath of others){
|
|
2114
|
-
lines.push(`---
|
|
2115
|
-
url: ${routePathToMdPath(routePath, base)}
|
|
2116
|
-
---
|
|
2117
|
-
`);
|
|
2118
|
-
lines.push(mdContents.get(routePath) ?? '');
|
|
2119
|
-
lines.push('\n');
|
|
2120
|
-
}
|
|
2121
|
-
return lines.join('\n');
|
|
2122
|
-
}
|
|
2123
|
-
async function emitLlmsTxt(config, routeService, emitAsset, mdContents) {
|
|
2124
|
-
const base = config.base ?? '/';
|
|
2125
|
-
const locales = config.themeConfig?.locales;
|
|
2126
|
-
const isMultiLang = locales && locales.length > 0;
|
|
2127
|
-
const nav = isMultiLang ? locales.filter((i)=>Boolean(i.nav)).map((i)=>({
|
|
2128
|
-
nav: i.nav,
|
|
2129
|
-
lang: i.lang
|
|
2130
|
-
})) : [
|
|
2131
|
-
{
|
|
2132
|
-
nav: config.themeConfig?.nav,
|
|
2133
|
-
lang: config.lang ?? ''
|
|
2134
|
-
}
|
|
2135
|
-
];
|
|
2136
|
-
const sidebars = isMultiLang ? locales.map((i)=>i.sidebar) : [
|
|
2137
|
-
config.themeConfig?.sidebar
|
|
2138
|
-
];
|
|
2139
|
-
const sidebar = sidebars.reduce((prev, curr)=>{
|
|
2140
|
-
Object.assign(prev, curr);
|
|
2141
|
-
return prev;
|
|
2142
|
-
}, {});
|
|
2143
|
-
const noVersionNav = Array.isArray(nav) ? nav.map((i)=>{
|
|
2144
|
-
const nav = i.nav.default || i.nav;
|
|
2145
|
-
const lang = i.lang;
|
|
2146
|
-
return nav.map((i)=>({
|
|
2147
|
-
...i,
|
|
2148
|
-
lang
|
|
2149
|
-
}));
|
|
2150
|
-
}).flat().filter((i)=>i.activeMatch || i.link) : [];
|
|
2151
|
-
const defaultLang = routeService.getDefaultLang();
|
|
2152
|
-
await Promise.all(routeService.getLangs().map(async (lang)=>{
|
|
2153
|
-
const navList = noVersionNav.filter((i)=>i.lang === lang);
|
|
2154
|
-
const routeGroups = new Array(navList.length).fill(0).map(()=>[]);
|
|
2155
|
-
const others = [];
|
|
2156
|
-
routeService.getRoutes().forEach((routeMeta)=>{
|
|
2157
|
-
if (routeMeta.lang !== lang) return;
|
|
2158
|
-
const { routePath } = routeMeta;
|
|
2159
|
-
for(let i = 0; i < routeGroups.length; i++){
|
|
2160
|
-
const routeGroup = routeGroups[i];
|
|
2161
|
-
const navItem = navList[i];
|
|
2162
|
-
if (lang === navItem.lang && new RegExp(navItem.activeMatch ?? navItem.link).test(routePath)) return void routeGroup.push(routePath);
|
|
2163
|
-
}
|
|
2164
|
-
others.push(routePath);
|
|
2165
|
-
});
|
|
2166
|
-
for (const routeGroup of routeGroups)organizeBySidebar(sidebar, routeGroup);
|
|
2167
|
-
const llmsTxtContent = await generateLlmsTxt(routeGroups, others, navList, config.title, config.description, config.base, routeService);
|
|
2168
|
-
const llmsFullTxtContent = generateLlmsFullTxt(routeGroups, navList, others, base, mdContents);
|
|
2169
|
-
const prefix = defaultLang === lang ? '' : `${lang}/`;
|
|
2170
|
-
emitAsset(`${prefix}llms.txt`, llmsTxtContent);
|
|
2171
|
-
emitAsset(`${prefix}llms-full.txt`, llmsFullTxtContent);
|
|
2172
|
-
}));
|
|
2173
|
-
}
|
|
2174
|
-
function flatSidebar(sidebar) {
|
|
2175
|
-
if (!sidebar) return [];
|
|
2176
|
-
return sidebar.flatMap((i)=>{
|
|
2177
|
-
if ('string' == typeof i) return i;
|
|
2178
|
-
if ('link' in i && 'string' == typeof i.link) return [
|
|
2179
|
-
i.link,
|
|
2180
|
-
...flatSidebar(i?.items ?? [])
|
|
2181
|
-
];
|
|
2182
|
-
if ('items' in i && Array.isArray(i.items)) return flatSidebar(i.items);
|
|
2183
|
-
}).filter(Boolean);
|
|
2184
|
-
}
|
|
2185
|
-
function organizeBySidebar(sidebar, routes) {
|
|
2186
|
-
if (0 === routes.length) return;
|
|
2187
|
-
const route = routes[0];
|
|
2188
|
-
const currSidebar = (0, shared_.getSidebarDataGroup)(sidebar, route);
|
|
2189
|
-
if (0 === currSidebar.length) return;
|
|
2190
|
-
const orderList = flatSidebar(currSidebar);
|
|
2191
|
-
routes.sort((a, b)=>{
|
|
2192
|
-
let aIndex = orderList.findIndex((order)=>matchPath(order, a));
|
|
2193
|
-
if (-1 === aIndex) aIndex = Number.MAX_SAFE_INTEGER;
|
|
2194
|
-
let bIndex = orderList.findIndex((order)=>matchPath(order, b));
|
|
2195
|
-
if (-1 === bIndex) bIndex = Number.MAX_SAFE_INTEGER;
|
|
2196
|
-
return aIndex - bIndex;
|
|
2197
|
-
});
|
|
2198
|
-
}
|
|
2199
|
-
async function renderPage_renderPage(route, ssrBundlePath) {
|
|
2200
|
-
let render;
|
|
2201
|
-
try {
|
|
2202
|
-
const { default: ssrExports } = await import((0, external_node_url_.pathToFileURL)(ssrBundlePath).toString());
|
|
2203
|
-
render = await ssrExports.render;
|
|
2204
|
-
} catch (e) {
|
|
2205
|
-
if (e instanceof Error) {
|
|
2206
|
-
logger.error(`Failed to load SSG bundle: ${picocolors.yellow(ssrBundlePath)}: ${e.message}`);
|
|
2207
|
-
logger.debug(e);
|
|
2208
|
-
hintSSGFailed();
|
|
2209
|
-
}
|
|
2210
|
-
throw e;
|
|
2211
|
-
}
|
|
2212
|
-
const head = createHead();
|
|
2213
|
-
const { routePath, absolutePath } = route;
|
|
2214
|
-
let appMd = '';
|
|
2215
|
-
if (render) try {
|
|
2216
|
-
({ appMd } = await render(routePath, head));
|
|
2217
|
-
} catch (e) {
|
|
2218
|
-
if (e instanceof Error) {
|
|
2219
|
-
logger.error(`Page "${picocolors.yellow(routePath)}" SSG-MD rendering failed.
|
|
2220
|
-
${absolutePath ? picocolors.gray(` File: ${absolutePath}\n`) : ''} ${picocolors.gray(e.toString())}`);
|
|
2221
|
-
throw e;
|
|
2222
|
-
}
|
|
2223
|
-
}
|
|
2224
|
-
return appMd;
|
|
2225
|
-
}
|
|
2226
|
-
const routePage2MdFilename = (routePath)=>{
|
|
2227
|
-
let fileName = routePath;
|
|
2228
|
-
fileName = fileName.endsWith('/') ? `${routePath}index.md` : `${routePath}.md`;
|
|
2229
|
-
return fileName.replace(/^\/+/, '');
|
|
2230
|
-
};
|
|
2231
|
-
async function renderPages_renderPages(routeService, ssrBundlePath, emitAsset) {
|
|
2232
|
-
logger.info('Rendering md pages...');
|
|
2233
|
-
const startTime = Date.now();
|
|
2234
|
-
const result = new Map();
|
|
2235
|
-
const routes = routeService.getRoutes();
|
|
2236
|
-
await pMap(routes, async (route)=>{
|
|
2237
|
-
const html = await renderPage_renderPage(route, ssrBundlePath);
|
|
2238
|
-
const fileName = routePage2MdFilename(route.routePath);
|
|
2239
|
-
emitAsset(fileName, html);
|
|
2240
|
-
result.set(route.routePath, html);
|
|
2241
|
-
}, {
|
|
2242
|
-
concurrency: SSGConcurrency()
|
|
2243
|
-
});
|
|
2244
|
-
const totalTime = Date.now() - startTime;
|
|
2245
|
-
logger.success(`Markdown rendered in ${picocolors.yellow(totalTime)} ms.`);
|
|
2246
|
-
return result;
|
|
2247
|
-
}
|
|
2248
|
-
const rsbuildPluginSSGMD = ({ routeService, config })=>({
|
|
2249
|
-
name: 'rspress-inner-rsbuild-plugin-ssg',
|
|
2250
|
-
async setup (api) {
|
|
2251
|
-
api.onBeforeBuild(()=>{
|
|
2252
|
-
let hasError = false;
|
|
2253
|
-
api.processAssets({
|
|
2254
|
-
stage: 'optimize-transfer',
|
|
2255
|
-
environments: [
|
|
2256
|
-
'node_md'
|
|
2257
|
-
]
|
|
2258
|
-
}, async ({ assets, compilation, environment, compiler })=>{
|
|
2259
|
-
if (compilation.errors.length > 0) {
|
|
2260
|
-
hasError = true;
|
|
2261
|
-
return;
|
|
2262
|
-
}
|
|
2263
|
-
if (hasError) return;
|
|
2264
|
-
const emitAsset = (assetName, content)=>{
|
|
2265
|
-
compilation.emitAsset(assetName, new compiler.webpack.sources.RawSource(content));
|
|
2266
|
-
};
|
|
2267
|
-
const distPath = environment.distPath;
|
|
2268
|
-
const ssgFolderPath = (0, external_node_path_.join)(distPath, NODE_SSG_MD_BUNDLE_FOLDER);
|
|
2269
|
-
const mainCjsAbsolutePath = (0, external_node_path_.join)(ssgFolderPath, NODE_SSG_MD_BUNDLE_NAME);
|
|
2270
|
-
await mkdir(ssgFolderPath, {
|
|
2271
|
-
recursive: true
|
|
2272
|
-
});
|
|
2273
|
-
await Promise.all(Object.entries(assets).map(async ([assetName, assetSource])=>{
|
|
2274
|
-
if (assetName.startsWith(`${NODE_SSG_MD_BUNDLE_FOLDER}/`)) {
|
|
2275
|
-
const fileAbsolutePath = (0, external_node_path_.join)(distPath, assetName);
|
|
2276
|
-
await writeFile(fileAbsolutePath, assetSource.source().toString());
|
|
2277
|
-
compilation.deleteAsset(assetName);
|
|
2278
|
-
}
|
|
2279
|
-
}));
|
|
2280
|
-
const mdContents = await renderPages_renderPages(routeService, mainCjsAbsolutePath, emitAsset);
|
|
2281
|
-
await emitLlmsTxt(config, routeService, emitAsset, mdContents);
|
|
2282
|
-
if (!(0, shared_.isDebugMode)()) await rm(ssgFolderPath, {
|
|
2283
|
-
recursive: true
|
|
2284
|
-
});
|
|
2285
|
-
});
|
|
2286
|
-
});
|
|
2287
|
-
}
|
|
2288
|
-
});
|
|
2289
|
-
const Resolver = core_rspack.experiments.resolver.ResolverFactory;
|
|
2290
|
-
async function detectPackageMajorVersion(name) {
|
|
2291
|
-
const cwd = process.cwd();
|
|
2292
|
-
const pkgPath = external_node_path_["default"].join(cwd, 'node_modules', name);
|
|
2293
|
-
if (await pathExists(pkgPath)) {
|
|
2294
|
-
const pkgJson = await readJson(external_node_path_["default"].join(pkgPath, 'package.json'));
|
|
2295
|
-
const version = Number(pkgJson.version?.split('.')[0]);
|
|
2296
|
-
return version;
|
|
2297
|
-
}
|
|
2298
|
-
}
|
|
2299
|
-
const DEFAULT_REACT_VERSION = 19;
|
|
2300
|
-
async function detectReactVersion() {
|
|
2301
|
-
return await detectPackageMajorVersion('react') ?? DEFAULT_REACT_VERSION;
|
|
2302
|
-
}
|
|
2303
|
-
async function resolveReactRouterDomAlias() {
|
|
2304
|
-
const alias = {};
|
|
2305
|
-
const resolver = new Resolver({
|
|
2306
|
-
mainFields: [
|
|
2307
|
-
'browser',
|
|
2308
|
-
'module',
|
|
2309
|
-
'main'
|
|
2310
|
-
],
|
|
2311
|
-
extensions: [
|
|
2312
|
-
'.js'
|
|
2313
|
-
],
|
|
2314
|
-
alias
|
|
2315
|
-
});
|
|
2316
|
-
try {
|
|
2317
|
-
const resolved = await resolver.async(PACKAGE_ROOT, 'react-router-dom');
|
|
2318
|
-
if (resolved.error) throw Error(resolved.error);
|
|
2319
|
-
if (!resolved.path) throw Error("'react-router-dom' resolved to empty path");
|
|
2320
|
-
return {
|
|
2321
|
-
'react-router-dom': resolved.path
|
|
2322
|
-
};
|
|
2323
|
-
} catch (e) {
|
|
2324
|
-
logger.warn('react-router-dom not found: \n', e);
|
|
2325
|
-
}
|
|
2326
|
-
return {};
|
|
2327
|
-
}
|
|
2328
|
-
async function resolveReactAlias(reactVersion, isSSR) {
|
|
2329
|
-
const basedir = reactVersion === DEFAULT_REACT_VERSION ? PACKAGE_ROOT : process.cwd();
|
|
2330
|
-
const libPaths = [
|
|
2331
|
-
'react',
|
|
2332
|
-
'react/jsx-runtime',
|
|
2333
|
-
'react/jsx-dev-runtime',
|
|
2334
|
-
'react-dom',
|
|
2335
|
-
'react-dom/client',
|
|
2336
|
-
'react-dom/server'
|
|
2337
|
-
];
|
|
2338
|
-
const alias = {};
|
|
2339
|
-
const resolver = new Resolver({
|
|
2340
|
-
extensions: [
|
|
2341
|
-
'.js'
|
|
2342
|
-
],
|
|
2343
|
-
alias,
|
|
2344
|
-
conditionNames: isSSR ? [
|
|
2345
|
-
'...'
|
|
2346
|
-
] : [
|
|
2347
|
-
'browser',
|
|
2348
|
-
'...'
|
|
2349
|
-
]
|
|
2350
|
-
});
|
|
2351
|
-
await Promise.all(libPaths.map(async (lib)=>{
|
|
2352
|
-
try {
|
|
2353
|
-
const resolved = await resolver.async(basedir, lib);
|
|
2354
|
-
if (resolved.error || !resolved.path) throw Error(resolved.error);
|
|
2355
|
-
alias[lib] = resolved.path;
|
|
2356
|
-
} catch (e) {
|
|
2357
|
-
if (e instanceof Error) {
|
|
2358
|
-
logger.warn(`${lib} not found: \n ${picocolors.gray(e.toString())}`);
|
|
2359
|
-
hintReactVersion();
|
|
2360
|
-
}
|
|
2361
|
-
}
|
|
2362
|
-
}));
|
|
2363
|
-
return alias;
|
|
2364
|
-
}
|
|
2365
|
-
const detectCustomIcon = async (customThemeDir)=>{
|
|
2366
|
-
const assetsDir = external_node_path_["default"].join(customThemeDir, 'assets');
|
|
2367
|
-
const alias = {};
|
|
2368
|
-
if (!(0, external_node_fs_.existsSync)(assetsDir)) return alias;
|
|
2369
|
-
const files = await glob('*.svg', {
|
|
2370
|
-
cwd: assetsDir
|
|
2371
|
-
});
|
|
2372
|
-
files.forEach((file)=>{
|
|
2373
|
-
const name = external_node_path_["default"].basename(file, '.svg');
|
|
2374
|
-
alias[`@theme-assets/${name}`] = external_node_path_["default"].join(assetsDir, file);
|
|
2375
|
-
});
|
|
2376
|
-
return alias;
|
|
2377
|
-
};
|
|
2378
|
-
function isPluginIncluded(config, pluginName) {
|
|
2379
|
-
return Boolean(config.builderConfig?.plugins?.some((plugin)=>plugin && plugin.name === pluginName));
|
|
2380
|
-
}
|
|
2381
|
-
const initRsbuild_require = createRequire(import.meta.url);
|
|
2382
|
-
const initRsbuild_filename = (0, external_node_url_.fileURLToPath)(import.meta.url);
|
|
2383
|
-
const initRsbuild_dirname = external_node_path_["default"].dirname(initRsbuild_filename);
|
|
2384
|
-
async function getVirtualModulesFromPlugins(pluginDriver) {
|
|
2385
|
-
const runtimeModule = {};
|
|
2386
|
-
const modulesByPlugin = await pluginDriver.addRuntimeModules();
|
|
2387
|
-
Object.keys(modulesByPlugin).forEach((key)=>{
|
|
2388
|
-
if (runtimeModule[key]) throw new Error(`The runtime module ${key} is duplicated, please check your plugin`);
|
|
2389
|
-
runtimeModule[key] = ()=>modulesByPlugin[key];
|
|
2390
|
-
});
|
|
2391
|
-
return runtimeModule;
|
|
2392
|
-
}
|
|
2393
|
-
async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeService, pluginDriver) {
|
|
2394
|
-
const CUSTOM_THEME_DIR = config?.themeDir ?? external_node_path_["default"].join(process.cwd(), 'theme');
|
|
2395
|
-
const outDir = config?.outDir ?? OUTPUT_DIR;
|
|
2396
|
-
const DEFAULT_THEME = external_node_path_["default"].join(initRsbuild_dirname, 'theme');
|
|
2397
|
-
const base = config?.base ?? '';
|
|
2398
|
-
const assetPrefix = isProduction() ? (0, shared_.removeTrailingSlash)(config?.builderConfig?.output?.assetPrefix ?? base) : '';
|
|
2399
|
-
const reactVersion = await detectReactVersion();
|
|
2400
|
-
const normalizeIcon = (icon)=>{
|
|
2401
|
-
if (!icon) return;
|
|
2402
|
-
icon = icon.toString();
|
|
2403
|
-
if (icon.startsWith('file://')) icon = (0, external_node_url_.fileURLToPath)(icon);
|
|
2404
|
-
else if (external_node_path_["default"].isAbsolute(icon)) return external_node_path_["default"].join(userDocRoot, PUBLIC_DIR, icon);
|
|
2405
|
-
return icon;
|
|
2406
|
-
};
|
|
2407
|
-
await hintThemeBreakingChange(CUSTOM_THEME_DIR);
|
|
2408
|
-
const [detectCustomIconAlias, reactCSRAlias, reactSSRAlias, reactRouterDomAlias] = await Promise.all([
|
|
2409
|
-
detectCustomIcon(CUSTOM_THEME_DIR),
|
|
2410
|
-
resolveReactAlias(reactVersion, false),
|
|
2411
|
-
enableSSG ? resolveReactAlias(reactVersion, true) : Promise.resolve({}),
|
|
2412
|
-
resolveReactAlias(reactVersion, true),
|
|
2413
|
-
resolveReactRouterDomAlias()
|
|
2414
|
-
]);
|
|
2415
|
-
const context = {
|
|
2416
|
-
userDocRoot,
|
|
2417
|
-
config,
|
|
2418
|
-
routeService,
|
|
2419
|
-
pluginDriver
|
|
2420
|
-
};
|
|
2421
|
-
return {
|
|
2422
|
-
plugins: [
|
|
2423
|
-
...isPluginIncluded(config, PLUGIN_REACT_NAME) ? [] : [
|
|
2424
|
-
pluginReact()
|
|
2425
|
-
],
|
|
2426
|
-
rsbuildPluginDocVM({
|
|
2427
|
-
config,
|
|
2428
|
-
pluginDriver,
|
|
2429
|
-
routeService,
|
|
2430
|
-
userDocRoot
|
|
2431
|
-
}),
|
|
2432
|
-
pluginVirtualModule({
|
|
2433
|
-
tempDir: '.rspress/runtime',
|
|
2434
|
-
virtualModules: {
|
|
2435
|
-
...socialLinksVMPlugin(context),
|
|
2436
|
-
...i18nVMPlugin(context),
|
|
2437
|
-
...globalUIComponentsVMPlugin(context),
|
|
2438
|
-
...globalStylesVMPlugin(context),
|
|
2439
|
-
...searchHookVMPlugin(context),
|
|
2440
|
-
...routeListVMPlugin(context),
|
|
2441
|
-
...await getVirtualModulesFromPlugins(pluginDriver),
|
|
2442
|
-
...siteDataVMPlugin(context)
|
|
2443
|
-
}
|
|
2444
|
-
}),
|
|
2445
|
-
enableSSG && config.ssg ? rsbuildPluginSSG({
|
|
2446
|
-
routeService,
|
|
2447
|
-
config
|
|
2448
|
-
}) : rsbuildPluginCSR({
|
|
2449
|
-
routeService,
|
|
2450
|
-
config
|
|
2451
|
-
}),
|
|
2452
|
-
enableSSG && config.llms ? rsbuildPluginSSGMD({
|
|
2453
|
-
routeService,
|
|
2454
|
-
config
|
|
2455
|
-
}) : null
|
|
2456
|
-
],
|
|
2457
|
-
server: {
|
|
2458
|
-
port: !isProduction() && process.env.PORT ? Number(process.env.PORT) : void 0,
|
|
2459
|
-
publicDir: {
|
|
2460
|
-
name: external_node_path_["default"].join(userDocRoot, PUBLIC_DIR)
|
|
2461
|
-
},
|
|
2462
|
-
...base.length > 0 ? {
|
|
2463
|
-
base: (0, shared_.removeTrailingSlash)(base)
|
|
2464
|
-
} : {}
|
|
2465
|
-
},
|
|
2466
|
-
dev: {
|
|
2467
|
-
lazyCompilation: 'false' !== process.env.RSPRESS_LAZY_COMPILATION,
|
|
2468
|
-
cliShortcuts: {
|
|
2469
|
-
custom: (shortcuts)=>shortcuts.filter(({ key })=>'r' !== key)
|
|
2470
|
-
}
|
|
2471
|
-
},
|
|
2472
|
-
html: {
|
|
2473
|
-
title: config?.title ?? DEFAULT_TITLE,
|
|
2474
|
-
favicon: normalizeIcon(config?.icon),
|
|
2475
|
-
template: TEMPLATE_PATH,
|
|
2476
|
-
tags: [
|
|
2477
|
-
config.themeConfig?.darkMode !== false ? {
|
|
2478
|
-
tag: "script",
|
|
2479
|
-
children: inlineThemeScript,
|
|
2480
|
-
append: false
|
|
2481
|
-
} : null
|
|
2482
|
-
].filter(Boolean)
|
|
2483
|
-
},
|
|
2484
|
-
output: {
|
|
2485
|
-
assetPrefix,
|
|
2486
|
-
distPath: {
|
|
2487
|
-
root: outDir
|
|
2488
|
-
}
|
|
2489
|
-
},
|
|
2490
|
-
resolve: {
|
|
2491
|
-
alias: {
|
|
2492
|
-
...detectCustomIconAlias,
|
|
2493
|
-
'@mdx-js/react': initRsbuild_require.resolve('@mdx-js/react'),
|
|
2494
|
-
'@theme': [
|
|
2495
|
-
CUSTOM_THEME_DIR,
|
|
2496
|
-
DEFAULT_THEME
|
|
2497
|
-
],
|
|
2498
|
-
'@theme-assets': external_node_path_["default"].join(DEFAULT_THEME, './assets'),
|
|
2499
|
-
'react-lazy-with-preload': initRsbuild_require.resolve('react-lazy-with-preload'),
|
|
2500
|
-
'@rspress/core/theme': DEFAULT_THEME,
|
|
2501
|
-
'@rspress/core/runtime': external_node_path_["default"].join(initRsbuild_dirname, 'runtime.js'),
|
|
2502
|
-
'@rspress/core/shiki-transformers': external_node_path_["default"].join(initRsbuild_dirname, 'shiki-transformers.js')
|
|
2503
|
-
}
|
|
2504
|
-
},
|
|
2505
|
-
source: {
|
|
2506
|
-
preEntry: [
|
|
2507
|
-
external_node_path_["default"].join(DEFAULT_THEME, './styles/index.js'),
|
|
2508
|
-
'virtual-global-styles',
|
|
2509
|
-
'@theme'
|
|
2510
|
-
],
|
|
2511
|
-
include: [
|
|
2512
|
-
PACKAGE_ROOT
|
|
2513
|
-
],
|
|
2514
|
-
define: {
|
|
2515
|
-
'process.env.TEST': JSON.stringify(process.env.TEST)
|
|
2516
|
-
}
|
|
2517
|
-
},
|
|
2518
|
-
performance: {
|
|
2519
|
-
...'false' !== process.env.RSPRESS_PERSISTENT_CACHE ? {
|
|
2520
|
-
buildCache: {
|
|
2521
|
-
buildDependencies: [
|
|
2522
|
-
initRsbuild_filename,
|
|
2523
|
-
pluginDriver.getConfigFilePath()
|
|
2524
|
-
],
|
|
2525
|
-
cacheDigest: [
|
|
2526
|
-
routeService.generateRoutesCode(),
|
|
2527
|
-
JSON.stringify(config.themeConfig?.locales?.map((i)=>({
|
|
2528
|
-
nav: i.nav,
|
|
2529
|
-
sidebar: i.sidebar
|
|
2530
|
-
})) ?? {
|
|
2531
|
-
nav: config.themeConfig?.nav,
|
|
2532
|
-
sidebar: config.themeConfig?.sidebar
|
|
2533
|
-
}),
|
|
2534
|
-
package_namespaceObject.rE
|
|
2535
|
-
]
|
|
2536
|
-
}
|
|
2537
|
-
} : {},
|
|
2538
|
-
chunkSplit: {
|
|
2539
|
-
override: {
|
|
2540
|
-
cacheGroups: {
|
|
2541
|
-
styles: {
|
|
2542
|
-
name: 'styles',
|
|
2543
|
-
minSize: 0,
|
|
2544
|
-
chunks: 'all',
|
|
2545
|
-
test: /\.(?:css|less|sass|scss)$/,
|
|
2546
|
-
priority: 99
|
|
2547
|
-
}
|
|
2548
|
-
}
|
|
2549
|
-
}
|
|
2550
|
-
}
|
|
2551
|
-
},
|
|
2552
|
-
tools: {
|
|
2553
|
-
bundlerChain (chain, { CHAIN_ID, environment }) {
|
|
2554
|
-
const isSsg = 'node' === environment.name;
|
|
2555
|
-
const isSsgMd = 'node_md' === environment.name;
|
|
2556
|
-
const jsModuleRule = chain.module.rule(CHAIN_ID.RULE.JS);
|
|
2557
|
-
const swcLoaderOptions = jsModuleRule.use(CHAIN_ID.USE.SWC).get('options');
|
|
2558
|
-
chain.module.rule('MDX').type("javascript/auto").test(shared_.MDX_OR_MD_REGEXP).resolve.merge({
|
|
2559
|
-
conditionNames: jsModuleRule.resolve.conditionNames.values(),
|
|
2560
|
-
mainFields: jsModuleRule.resolve.mainFields.values()
|
|
2561
|
-
}).end().oneOf('MDXCompile').use('builtin:swc-loader').loader('builtin:swc-loader').options(swcLoaderOptions).end().use('mdx-loader').loader(initRsbuild_require.resolve('./loader.js')).options({
|
|
2562
|
-
config,
|
|
2563
|
-
docDirectory: userDocRoot,
|
|
2564
|
-
routeService,
|
|
2565
|
-
pluginDriver,
|
|
2566
|
-
isSsgMd
|
|
2567
|
-
}).end();
|
|
2568
|
-
chain.experiments({
|
|
2569
|
-
...chain.get('experiments'),
|
|
2570
|
-
nativeWatcher: 'false' !== process.env.RSPRESS_NATIVE_WATCHER
|
|
2571
|
-
});
|
|
2572
|
-
if (chain.plugins.has(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH)) chain.plugin(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH).tap((options)=>{
|
|
2573
|
-
options[0] ??= {};
|
|
2574
|
-
options[0].test = [
|
|
2575
|
-
/\.([cm]js|[jt]sx?|flow)$/i,
|
|
2576
|
-
shared_.MDX_OR_MD_REGEXP
|
|
2577
|
-
];
|
|
2578
|
-
options[0].include = [
|
|
2579
|
-
/\.([cm]js|[jt]sx?|flow)$/i,
|
|
2580
|
-
shared_.MDX_OR_MD_REGEXP
|
|
2581
|
-
];
|
|
2582
|
-
return options;
|
|
2583
|
-
});
|
|
2584
|
-
chain.resolve.extensions.prepend('.md').prepend('.mdx').prepend('.mjs');
|
|
2585
|
-
chain.module.rule('css-virtual-module').test(/\.rspress[\\/]runtime[\\/]virtual-global-styles/).merge({
|
|
2586
|
-
sideEffects: true
|
|
2587
|
-
});
|
|
2588
|
-
if (isSsg || isSsgMd) chain.optimization.splitChunks({});
|
|
2589
|
-
if (isSsg) {
|
|
2590
|
-
chain.output.filename(`${NODE_SSG_BUNDLE_FOLDER}/${NODE_SSG_BUNDLE_NAME}`);
|
|
2591
|
-
chain.output.chunkFilename(`${NODE_SSG_BUNDLE_FOLDER}/[name].cjs`);
|
|
2592
|
-
} else if (isSsgMd) {
|
|
2593
|
-
chain.output.filename(`${NODE_SSG_MD_BUNDLE_FOLDER}/${NODE_SSG_MD_BUNDLE_NAME}`);
|
|
2594
|
-
chain.output.chunkFilename(`${NODE_SSG_MD_BUNDLE_FOLDER}/[name].cjs`);
|
|
2595
|
-
}
|
|
2596
|
-
}
|
|
2597
|
-
},
|
|
2598
|
-
environments: {
|
|
2599
|
-
web: {
|
|
2600
|
-
resolve: {
|
|
2601
|
-
alias: {
|
|
2602
|
-
...reactCSRAlias,
|
|
2603
|
-
...reactRouterDomAlias
|
|
2604
|
-
}
|
|
2605
|
-
},
|
|
2606
|
-
source: {
|
|
2607
|
-
entry: {
|
|
2608
|
-
index: enableSSG && isProduction() ? SSR_CLIENT_ENTRY : CSR_CLIENT_ENTRY
|
|
2609
|
-
},
|
|
2610
|
-
define: {
|
|
2611
|
-
'process.env.__SSR__': JSON.stringify(false),
|
|
2612
|
-
'process.env.__SSR_MD__': JSON.stringify(false)
|
|
2613
|
-
}
|
|
2614
|
-
},
|
|
2615
|
-
output: {
|
|
2616
|
-
target: 'web',
|
|
2617
|
-
distPath: {
|
|
2618
|
-
root: outDir
|
|
2619
|
-
}
|
|
2620
|
-
}
|
|
2621
|
-
},
|
|
2622
|
-
...enableSSG && config.ssg ? {
|
|
2623
|
-
node: {
|
|
2624
|
-
resolve: {
|
|
2625
|
-
alias: {
|
|
2626
|
-
...reactSSRAlias,
|
|
2627
|
-
...reactRouterDomAlias
|
|
2628
|
-
}
|
|
2629
|
-
},
|
|
2630
|
-
source: {
|
|
2631
|
-
entry: {
|
|
2632
|
-
index: SSR_SERVER_ENTRY
|
|
2633
|
-
},
|
|
2634
|
-
define: {
|
|
2635
|
-
'process.env.__SSR__': JSON.stringify(true),
|
|
2636
|
-
'process.env.__SSR_MD__': JSON.stringify(false)
|
|
2637
|
-
}
|
|
2638
|
-
},
|
|
2639
|
-
performance: {
|
|
2640
|
-
printFileSize: {
|
|
2641
|
-
compressed: true
|
|
2642
|
-
}
|
|
2643
|
-
},
|
|
2644
|
-
output: {
|
|
2645
|
-
emitAssets: false,
|
|
2646
|
-
target: 'node',
|
|
2647
|
-
minify: false
|
|
2648
|
-
}
|
|
2649
|
-
}
|
|
2650
|
-
} : {},
|
|
2651
|
-
...enableSSG && config.llms ? {
|
|
2652
|
-
node_md: {
|
|
2653
|
-
resolve: {
|
|
2654
|
-
alias: {
|
|
2655
|
-
...reactSSRAlias,
|
|
2656
|
-
...reactRouterDomAlias
|
|
2657
|
-
}
|
|
2658
|
-
},
|
|
2659
|
-
tools: {
|
|
2660
|
-
rspack: {
|
|
2661
|
-
optimization: {
|
|
2662
|
-
moduleIds: 'named',
|
|
2663
|
-
chunkIds: 'named'
|
|
2664
|
-
}
|
|
2665
|
-
}
|
|
2666
|
-
},
|
|
2667
|
-
source: {
|
|
2668
|
-
entry: {
|
|
2669
|
-
index: SSG_MD_SERVER_ENTRY
|
|
2670
|
-
},
|
|
2671
|
-
define: {
|
|
2672
|
-
'process.env.__SSR__': JSON.stringify(true),
|
|
2673
|
-
'process.env.__SSR_MD__': JSON.stringify(true)
|
|
2674
|
-
}
|
|
2675
|
-
},
|
|
2676
|
-
performance: {
|
|
2677
|
-
printFileSize: {
|
|
2678
|
-
compressed: true
|
|
2679
|
-
}
|
|
2680
|
-
},
|
|
2681
|
-
output: {
|
|
2682
|
-
emitAssets: false,
|
|
2683
|
-
target: 'node',
|
|
2684
|
-
minify: false
|
|
2685
|
-
}
|
|
2686
|
-
}
|
|
2687
|
-
} : {}
|
|
2688
|
-
}
|
|
2689
|
-
};
|
|
2690
|
-
}
|
|
2691
|
-
async function initRsbuild(rootDir, config, pluginDriver, routeService, enableSSG, extraRsbuildConfig) {
|
|
2692
|
-
const cwd = process.cwd();
|
|
2693
|
-
const userDocRoot = external_node_path_["default"].resolve(rootDir || config?.root || cwd);
|
|
2694
|
-
hintBuilderPluginsBreakingChange(config);
|
|
2695
|
-
const { createRsbuild, mergeRsbuildConfig } = await import("@rsbuild/core");
|
|
2696
|
-
const internalRsbuildConfig = await createInternalBuildConfig(userDocRoot, config, enableSSG, routeService, pluginDriver);
|
|
2697
|
-
const rsbuild = await createRsbuild({
|
|
2698
|
-
callerName: 'rspress',
|
|
2699
|
-
rsbuildConfig: mergeRsbuildConfig(internalRsbuildConfig, ...pluginDriver.getPlugins()?.map((plugin)=>plugin.builderConfig ?? {}) || [], config.builderConfig || {}, extraRsbuildConfig || {})
|
|
2700
|
-
});
|
|
2701
|
-
return rsbuild;
|
|
2702
|
-
}
|
|
2703
|
-
class PluginDriver {
|
|
2704
|
-
#config;
|
|
2705
|
-
#configFilePath;
|
|
2706
|
-
#plugins;
|
|
2707
|
-
#isProd;
|
|
2708
|
-
haveNavSidebarConfig = false;
|
|
2709
|
-
static async create(config, configFilePath, isProd) {
|
|
2710
|
-
const pluginDriver = new PluginDriver(config, configFilePath, isProd);
|
|
2711
|
-
await pluginDriver.init();
|
|
2712
|
-
return pluginDriver;
|
|
2713
|
-
}
|
|
2714
|
-
constructor(config, configFilePath, isProd){
|
|
2715
|
-
this.#config = config;
|
|
2716
|
-
this.#configFilePath = configFilePath;
|
|
2717
|
-
this.#isProd = isProd;
|
|
2718
|
-
this.#plugins = [];
|
|
2719
|
-
}
|
|
2720
|
-
getConfigFilePath() {
|
|
2721
|
-
return this.#configFilePath;
|
|
2722
|
-
}
|
|
2723
|
-
async init() {
|
|
2724
|
-
this.clearPlugins();
|
|
2725
|
-
const config = this.#config;
|
|
2726
|
-
const themeConfig = config?.themeConfig || {};
|
|
2727
|
-
const enableLastUpdated = themeConfig?.lastUpdated;
|
|
2728
|
-
const mediumZoomConfig = config?.mediumZoom ?? true;
|
|
2729
|
-
if (enableLastUpdated) {
|
|
2730
|
-
const { pluginLastUpdated } = await Promise.all([
|
|
2731
|
-
__webpack_require__.e("517"),
|
|
2732
|
-
__webpack_require__.e("128")
|
|
2733
|
-
]).then(__webpack_require__.bind(__webpack_require__, "./src/node/last-updated/index.ts"));
|
|
2734
|
-
this.addPlugin(pluginLastUpdated());
|
|
2735
|
-
}
|
|
2736
|
-
if (mediumZoomConfig) {
|
|
2737
|
-
const { pluginMediumZoom } = await __webpack_require__.e("894").then(__webpack_require__.bind(__webpack_require__, "./src/node/medium-zoom/index.ts"));
|
|
2738
|
-
this.addPlugin(pluginMediumZoom('object' == typeof mediumZoomConfig ? mediumZoomConfig : void 0));
|
|
2739
|
-
}
|
|
2740
|
-
(config.plugins || []).forEach((plugin)=>{
|
|
2741
|
-
this.addPlugin(plugin);
|
|
2742
|
-
});
|
|
2743
|
-
}
|
|
2744
|
-
addPlugin(plugin) {
|
|
2745
|
-
const existedIndex = this.#plugins.findIndex((item)=>item.name === plugin.name);
|
|
2746
|
-
if (-1 !== existedIndex) throw new Error(`The plugin "${plugin.name}" has been registered`);
|
|
2747
|
-
this.#plugins.push(plugin);
|
|
2748
|
-
}
|
|
2749
|
-
getPlugins() {
|
|
2750
|
-
return this.#plugins;
|
|
2751
|
-
}
|
|
2752
|
-
clearPlugins() {
|
|
2753
|
-
this.#plugins = [];
|
|
2754
|
-
}
|
|
2755
|
-
removePlugin(pluginName) {
|
|
2756
|
-
const index = this.#plugins.findIndex((item)=>item.name === pluginName);
|
|
2757
|
-
if (-1 !== index) this.#plugins.splice(index, 1);
|
|
2758
|
-
}
|
|
2759
|
-
async normalizeConfig() {
|
|
2760
|
-
this.#config.ssg ??= true;
|
|
2761
|
-
this.#config.llms ??= false;
|
|
2762
|
-
this.#config.base = (0, shared_.addTrailingSlash)((0, shared_.addLeadingSlash)(this.#config.base ?? '/'));
|
|
2763
|
-
this.#config.lang ??= 'en';
|
|
2764
|
-
}
|
|
2765
|
-
async modifyConfig() {
|
|
2766
|
-
this.normalizeConfig();
|
|
2767
|
-
let config = this.#config;
|
|
2768
|
-
for(let i = 0; i < this.#plugins.length; i++){
|
|
2769
|
-
const plugin = this.#plugins[i];
|
|
2770
|
-
if ('function' == typeof plugin.config) config = await plugin.config(config || {}, {
|
|
2771
|
-
addPlugin: this.addPlugin.bind(this),
|
|
2772
|
-
removePlugin: (pluginName)=>{
|
|
2773
|
-
const index = this.#plugins.findIndex((item)=>item.name === pluginName);
|
|
2774
|
-
this.removePlugin(pluginName);
|
|
2775
|
-
if (index <= i && index > 0) i--;
|
|
2776
|
-
}
|
|
2777
|
-
}, this.#isProd);
|
|
2778
|
-
}
|
|
2779
|
-
this.#config = config;
|
|
2780
|
-
this.haveNavSidebarConfig = auto_nav_sidebar_haveNavSidebarConfig(config);
|
|
2781
|
-
return this.#config;
|
|
2782
|
-
}
|
|
2783
|
-
async beforeBuild() {
|
|
2784
|
-
return this._runParallelAsyncHook('beforeBuild', this.#config || {}, this.#isProd);
|
|
2785
|
-
}
|
|
2786
|
-
async afterBuild() {
|
|
2787
|
-
return this._runParallelAsyncHook('afterBuild', this.#config || {}, this.#isProd);
|
|
2788
|
-
}
|
|
2789
|
-
async modifySearchIndexData(pages) {
|
|
2790
|
-
return this._runParallelAsyncHook('modifySearchIndexData', pages, this.#isProd);
|
|
2791
|
-
}
|
|
2792
|
-
async extendPageData(pageData) {
|
|
2793
|
-
return this._runParallelAsyncHook('extendPageData', pageData, this.#isProd);
|
|
2794
|
-
}
|
|
2795
|
-
async addPages() {
|
|
2796
|
-
const result = await this._runParallelAsyncHook('addPages', this.#config || {}, this.#isProd);
|
|
2797
|
-
return result.flat();
|
|
2798
|
-
}
|
|
2799
|
-
async routeGenerated(routes) {
|
|
2800
|
-
return this._runParallelAsyncHook('routeGenerated', routes, this.#isProd);
|
|
2801
|
-
}
|
|
2802
|
-
async routeServiceGenerated(routeService) {
|
|
2803
|
-
return this._runParallelAsyncHook('routeServiceGenerated', routeService, this.#isProd);
|
|
2804
|
-
}
|
|
2805
|
-
async addRuntimeModules() {
|
|
2806
|
-
const result = await this._runParallelAsyncHook('addRuntimeModules', this.#config || {}, this.#isProd);
|
|
2807
|
-
return result.reduce((prev, current)=>({
|
|
2808
|
-
...prev,
|
|
2809
|
-
...current
|
|
2810
|
-
}), {});
|
|
2811
|
-
}
|
|
2812
|
-
async i18nSource(defaultSource) {
|
|
2813
|
-
let i18nSource = defaultSource;
|
|
2814
|
-
for (const plugin of this.#plugins)if ('function' == typeof plugin.i18nSource) i18nSource = await plugin.i18nSource(i18nSource) || i18nSource;
|
|
2815
|
-
return i18nSource;
|
|
2816
|
-
}
|
|
2817
|
-
globalUIComponents() {
|
|
2818
|
-
const result = this.#plugins.map((plugin)=>plugin.globalUIComponents || []);
|
|
2819
|
-
return result.flat();
|
|
2820
|
-
}
|
|
2821
|
-
globalStyles() {
|
|
2822
|
-
return this.#plugins.filter((plugin)=>'string' == typeof plugin.globalStyles).map((plugin)=>plugin.globalStyles);
|
|
2823
|
-
}
|
|
2824
|
-
_runParallelAsyncHook(hookName, ...args) {
|
|
2825
|
-
return Promise.all(this.#plugins.filter((plugin)=>'function' == typeof plugin[hookName]).map((plugin)=>plugin[hookName](...args)));
|
|
2826
|
-
}
|
|
2827
|
-
_runSerialAsyncHook(hookName, ...args) {
|
|
2828
|
-
return this.#plugins.reduce(async (prev, plugin)=>{
|
|
2829
|
-
if ('function' == typeof plugin[hookName]) {
|
|
2830
|
-
await prev;
|
|
2831
|
-
return plugin[hookName](...args);
|
|
2832
|
-
}
|
|
2833
|
-
return prev;
|
|
2834
|
-
}, Promise.resolve());
|
|
2835
|
-
}
|
|
2836
|
-
}
|
|
2837
|
-
function checkLanguageParity_normalizePath(filePath) {
|
|
2838
|
-
return filePath.split(external_node_path_["default"].sep).join('/');
|
|
2839
|
-
}
|
|
2840
|
-
async function getAllMarkdownFilesFrom(dirPath) {
|
|
2841
|
-
const files = await node_fs_promises.readdir(dirPath, {
|
|
2842
|
-
withFileTypes: true
|
|
2843
|
-
});
|
|
2844
|
-
const allFiles = [];
|
|
2845
|
-
for (const file of files){
|
|
2846
|
-
const fullPath = external_node_path_["default"].join(dirPath, file.name);
|
|
2847
|
-
if (file.isDirectory()) {
|
|
2848
|
-
const nestedFiles = await getAllMarkdownFilesFrom(fullPath);
|
|
2849
|
-
allFiles.push(...nestedFiles);
|
|
2850
|
-
} else if ([
|
|
2851
|
-
'.md',
|
|
2852
|
-
'.mdx'
|
|
2853
|
-
].includes(external_node_path_["default"].extname(file.name))) allFiles.push(fullPath);
|
|
2854
|
-
}
|
|
2855
|
-
return allFiles;
|
|
2856
|
-
}
|
|
2857
|
-
async function collectModuleFiles(contentPath, lang, includedDir, excludedDirs, fileLangMap) {
|
|
2858
|
-
const langDirPath = external_node_path_["default"].join(contentPath, lang);
|
|
2859
|
-
const langModuleDir = external_node_path_["default"].join(langDirPath, includedDir);
|
|
2860
|
-
try {
|
|
2861
|
-
const moduleDirStats = await node_fs_promises.stat(langModuleDir);
|
|
2862
|
-
if (!moduleDirStats.isDirectory()) return fileLangMap;
|
|
2863
|
-
const files = await getAllMarkdownFilesFrom(langModuleDir);
|
|
2864
|
-
for (const file of files){
|
|
2865
|
-
const relativePath = checkLanguageParity_normalizePath(external_node_path_["default"].relative(langDirPath, file));
|
|
2866
|
-
if (excludedDirs.some((excludedDir)=>{
|
|
2867
|
-
const isFilePath = /\.(md|mdx)$/.test(excludedDir);
|
|
2868
|
-
return relativePath.includes(excludedDir + (isFilePath ? '' : '/'));
|
|
2869
|
-
})) continue;
|
|
2870
|
-
const baseName = relativePath;
|
|
2871
|
-
if (!fileLangMap[baseName]) fileLangMap[baseName] = new Set();
|
|
2872
|
-
fileLangMap[baseName].add(lang);
|
|
2873
|
-
}
|
|
2874
|
-
} catch (e) {
|
|
2875
|
-
logger.error(e);
|
|
2876
|
-
throw new Error(`Failed to access directory: ${checkLanguageParity_normalizePath(langModuleDir)}`);
|
|
2877
|
-
}
|
|
2878
|
-
return fileLangMap;
|
|
2879
|
-
}
|
|
2880
|
-
async function checkLanguageParity(config) {
|
|
2881
|
-
if (!config?.languageParity || false === config.languageParity.enabled) return;
|
|
2882
|
-
logger.info('Checking language parity...');
|
|
2883
|
-
const contentPath = external_node_path_["default"].resolve(config.root);
|
|
2884
|
-
const includedDirs = config.languageParity.include?.length ? config.languageParity.include : [
|
|
2885
|
-
''
|
|
2886
|
-
];
|
|
2887
|
-
const excludedDirs = config.languageParity.exclude ?? [];
|
|
2888
|
-
const supportedLanguages = (config.locales ?? config.themeConfig?.locales)?.map((locale)=>locale.lang) || [];
|
|
2889
|
-
if (!supportedLanguages.length) return void logger.error('No supported languages found in the configuration.');
|
|
2890
|
-
const missingLanguagesFile = [];
|
|
2891
|
-
try {
|
|
2892
|
-
for (const includedDir of includedDirs){
|
|
2893
|
-
if (excludedDirs.some((excludedDir)=>excludedDir === includedDir)) continue;
|
|
2894
|
-
const curFileLangMap = {};
|
|
2895
|
-
for (const lang of supportedLanguages)await collectModuleFiles(contentPath, lang, includedDir, excludedDirs, curFileLangMap);
|
|
2896
|
-
for (const [baseName, langs] of Object.entries(curFileLangMap)){
|
|
2897
|
-
const missingLangs = supportedLanguages.filter((lang)=>!langs.has(lang));
|
|
2898
|
-
missingLangs.forEach((lang)=>{
|
|
2899
|
-
const missingPath = external_node_path_["default"].join(lang, baseName);
|
|
2900
|
-
missingLanguagesFile.push(missingPath);
|
|
2901
|
-
});
|
|
2902
|
-
}
|
|
2903
|
-
}
|
|
2904
|
-
if (missingLanguagesFile.length > 0) throw new Error(`Check language parity failed! Missing content:\n${missingLanguagesFile.map((file)=>` - ${checkLanguageParity_normalizePath(file)}`).join('\n')}`);
|
|
2905
|
-
logger.success('Language parity checked successfully.');
|
|
2906
|
-
} catch (err) {
|
|
2907
|
-
logger.error('Error during language parity check: \n', err);
|
|
2908
|
-
throw err;
|
|
2909
|
-
}
|
|
2910
|
-
}
|
|
2911
|
-
async function build(options) {
|
|
2912
|
-
const { docDirectory, config, configFilePath } = options;
|
|
2913
|
-
const pluginDriver = await PluginDriver.create(config, configFilePath, true);
|
|
2914
|
-
const modifiedConfig = await pluginDriver.modifyConfig();
|
|
2915
|
-
const enableSSG = Boolean((modifiedConfig.ssg || modifiedConfig.llms) ?? true);
|
|
2916
|
-
const additionalPages = await pluginDriver.addPages();
|
|
2917
|
-
const routeService = await RouteService.create({
|
|
2918
|
-
config: modifiedConfig,
|
|
2919
|
-
scanDir: docDirectory,
|
|
2920
|
-
externalPages: additionalPages
|
|
2921
|
-
});
|
|
2922
|
-
await pluginDriver.routeGenerated(routeService.getRoutes());
|
|
2923
|
-
await pluginDriver.routeServiceGenerated(routeService);
|
|
2924
|
-
await modifyConfigWithAutoNavSide(modifiedConfig);
|
|
2925
|
-
try {
|
|
2926
|
-
await pluginDriver.beforeBuild();
|
|
2927
|
-
const rsbuild = await initRsbuild(docDirectory, modifiedConfig, pluginDriver, routeService, enableSSG);
|
|
2928
|
-
await rsbuild.build();
|
|
2929
|
-
} finally{
|
|
2930
|
-
await checkLanguageParity(config);
|
|
2931
|
-
}
|
|
2932
|
-
await pluginDriver.afterBuild();
|
|
2933
|
-
if (!enableSSG) hintSSGFalse();
|
|
2934
|
-
}
|
|
2935
|
-
async function dev(options) {
|
|
2936
|
-
const { docDirectory, config, extraBuilderConfig, configFilePath } = options;
|
|
2937
|
-
const isProd = false;
|
|
2938
|
-
const pluginDriver = await PluginDriver.create(config, configFilePath, isProd);
|
|
2939
|
-
const modifiedConfig = await pluginDriver.modifyConfig();
|
|
2940
|
-
try {
|
|
2941
|
-
const additionalPages = await pluginDriver.addPages();
|
|
2942
|
-
const routeService = await RouteService.create({
|
|
2943
|
-
config: modifiedConfig,
|
|
2944
|
-
scanDir: docDirectory,
|
|
2945
|
-
externalPages: additionalPages
|
|
2946
|
-
});
|
|
2947
|
-
await pluginDriver.routeGenerated(routeService.getRoutes());
|
|
2948
|
-
await pluginDriver.routeServiceGenerated(routeService);
|
|
2949
|
-
await pluginDriver.beforeBuild();
|
|
2950
|
-
const rsbuild = await initRsbuild(docDirectory, modifiedConfig, pluginDriver, routeService, false, extraBuilderConfig);
|
|
2951
|
-
rsbuild.onAfterDevCompile(async ()=>{
|
|
2952
|
-
await pluginDriver.afterBuild();
|
|
2953
|
-
});
|
|
2954
|
-
const { server } = await rsbuild.startDevServer({
|
|
2955
|
-
getPortSilently: true
|
|
2956
|
-
});
|
|
2957
|
-
return server;
|
|
2958
|
-
} finally{
|
|
2959
|
-
await checkLanguageParity(modifiedConfig);
|
|
2960
|
-
}
|
|
2961
|
-
}
|
|
2962
|
-
const ERROR_PREFIX = '[remarkFileCodeBlock]';
|
|
2963
|
-
function parseFileFromMeta(meta) {
|
|
2964
|
-
if (!meta) return '';
|
|
2965
|
-
const kvList = meta.split(' ').filter(Boolean);
|
|
2966
|
-
for (const item of kvList){
|
|
2967
|
-
const [k, v = ''] = item.split('=');
|
|
2968
|
-
if ('file' === k && v.length > 0) return v.replace(/["'`]/g, '');
|
|
2969
|
-
}
|
|
2970
|
-
return '';
|
|
2971
|
-
}
|
|
2972
|
-
const remarkFileCodeBlock = ({ filepath, addDependency })=>async (tree)=>{
|
|
2973
|
-
const promiseList = [];
|
|
2974
|
-
visit(tree, 'code', (node)=>{
|
|
2975
|
-
const { meta, value, lang } = node;
|
|
2976
|
-
const file = parseFileFromMeta(meta ?? '');
|
|
2977
|
-
if (!file) return;
|
|
2978
|
-
const originalMetaForErrorInfo = picocolors.cyan(`\`\`\`${lang} ${meta}`);
|
|
2979
|
-
if (file.startsWith('./') || file.startsWith('../')) {
|
|
2980
|
-
const resolvedFilePath = external_node_path_["default"].join(external_node_path_["default"].dirname(filepath), file);
|
|
2981
|
-
if ('' !== value.trim()) {
|
|
2982
|
-
logger.error(`${ERROR_PREFIX} ${originalMetaForErrorInfo} The content of file code block should be empty.
|
|
2983
|
-
|
|
2984
|
-
\`\`\`tsx file="./filename"
|
|
2985
|
-
content
|
|
2986
|
-
\`\`\`
|
|
2987
|
-
|
|
2988
|
-
this usage is not allowed, please use below:
|
|
2989
|
-
|
|
2990
|
-
\`\`\`tsx file="./filename"
|
|
2991
|
-
\`\`\`
|
|
2992
|
-
`);
|
|
2993
|
-
throw new Error(`${ERROR_PREFIX} ${originalMetaForErrorInfo} The content of file code block should be empty.`);
|
|
2994
|
-
}
|
|
2995
|
-
const promise = readFile(resolvedFilePath, 'utf-8').then((fileContent)=>{
|
|
2996
|
-
addDependency?.(resolvedFilePath);
|
|
2997
|
-
node.value = fileContent;
|
|
2998
|
-
}).catch((e)=>{
|
|
2999
|
-
const message = `${ERROR_PREFIX} ${originalMetaForErrorInfo} introduces another file in "${resolvedFilePath}", but the file does not exist.`;
|
|
3000
|
-
logger.error(message);
|
|
3001
|
-
e.message = `${message}\n${e.message}`;
|
|
3002
|
-
throw e;
|
|
3003
|
-
});
|
|
3004
|
-
promiseList.push(promise);
|
|
3005
|
-
return;
|
|
3006
|
-
}
|
|
3007
|
-
logger.error(`${ERROR_PREFIX} ${originalMetaForErrorInfo} syntax error of file code block:
|
|
3008
|
-
Please use below:
|
|
3009
|
-
|
|
3010
|
-
\`\`\`tsx file="./filename"
|
|
3011
|
-
\`\`\`
|
|
3012
|
-
`);
|
|
3013
|
-
throw new Error(`${ERROR_PREFIX} ${originalMetaForErrorInfo} syntax error of file code block`);
|
|
3014
|
-
});
|
|
3015
|
-
await Promise.all(promiseList);
|
|
3016
|
-
};
|
|
3017
|
-
function link_checkDeadLinks(checkDeadLinks, internalLinks, file, lint) {
|
|
3018
|
-
const errorInfos = [];
|
|
3019
|
-
const excludes = 'object' == typeof checkDeadLinks ? checkDeadLinks.excludes : void 0;
|
|
3020
|
-
const excludesUrl = Array.isArray(excludes) ? new Set(excludes) : void 0;
|
|
3021
|
-
const excludesFn = 'function' == typeof excludes ? excludes : void 0;
|
|
3022
|
-
let possibleBreakingChange = false;
|
|
3023
|
-
[
|
|
3024
|
-
...internalLinks.entries()
|
|
3025
|
-
].forEach(([nodeUrl, link])=>{
|
|
3026
|
-
if (excludesUrl?.has(nodeUrl)) return;
|
|
3027
|
-
if (excludesFn?.(nodeUrl)) return;
|
|
3028
|
-
if (!nodeUrl.startsWith('/') && /^\w/.test(nodeUrl)) possibleBreakingChange = true;
|
|
3029
|
-
errorInfos.push([
|
|
3030
|
-
nodeUrl,
|
|
3031
|
-
link
|
|
3032
|
-
]);
|
|
3033
|
-
});
|
|
3034
|
-
if (errorInfos.length > 0) {
|
|
3035
|
-
if (possibleBreakingChange) hintRelativeMarkdownLink();
|
|
3036
|
-
const message = `Dead links found${lint ? '' : ` in ${picocolors.cyan(file.path)}`}:
|
|
3037
|
-
${errorInfos.map(([nodeUrl, link])=>` ${picocolors.green(`"[..](${nodeUrl})"`)} ${picocolors.gray(link)}`).join('\n')}`;
|
|
3038
|
-
if (lint) file.message(message);
|
|
3039
|
-
else {
|
|
3040
|
-
logger.error(message);
|
|
3041
|
-
if ((0, shared_.isProduction)()) throw new Error('Dead link found');
|
|
3042
|
-
}
|
|
3043
|
-
}
|
|
3044
|
-
}
|
|
3045
|
-
function looseMarkdownLink(url, routeService, filePath) {
|
|
3046
|
-
if (!routeService.isInDocsDir(filePath)) return url;
|
|
3047
|
-
const [versionPart, langPart, pureRoute] = routeService.splitRoutePathParts(url);
|
|
3048
|
-
const relativePath = routeService.absolutePathToRelativePath(filePath);
|
|
3049
|
-
const [versionPartCurrFile, langPartCurrFile] = routeService.getRoutePathParts(relativePath);
|
|
3050
|
-
if ('' === versionPart) {
|
|
3051
|
-
if ('' === langPart) return (0, shared_.addLeadingSlash)(`${[
|
|
3052
|
-
versionPartCurrFile,
|
|
3053
|
-
langPartCurrFile
|
|
3054
|
-
].filter(Boolean).join('/')}${(0, shared_.addLeadingSlash)(pureRoute.replace(/^\/*/, ''))}`);
|
|
3055
|
-
return (0, shared_.addLeadingSlash)(`${[
|
|
3056
|
-
versionPartCurrFile,
|
|
3057
|
-
langPart
|
|
3058
|
-
].filter(Boolean).join('/')}${(0, shared_.addLeadingSlash)(pureRoute.replace(/^\/*/, ''))}`);
|
|
3059
|
-
}
|
|
3060
|
-
return url;
|
|
3061
|
-
}
|
|
3062
|
-
function normalizeLink(nodeUrl, routeService, filePath, cleanUrls, autoPrefix, deadLinks, __base) {
|
|
3063
|
-
if (!nodeUrl) return '';
|
|
3064
|
-
if (nodeUrl.startsWith('#')) return nodeUrl;
|
|
3065
|
-
if ((0, shared_.isExternalUrl)(nodeUrl)) return nodeUrl;
|
|
3066
|
-
if (!routeService) return nodeUrl;
|
|
3067
|
-
let { url, hash, search } = (0, shared_.parseUrl)(nodeUrl);
|
|
3068
|
-
if (url.startsWith('/')) {
|
|
3069
|
-
if (autoPrefix) url = looseMarkdownLink(url, routeService, filePath);
|
|
3070
|
-
const { routePath } = routeService.normalizeRoutePath(url);
|
|
3071
|
-
url = routePath;
|
|
3072
|
-
} else {
|
|
3073
|
-
const anotherFileAbsolutePath = external_node_path_["default"].join(external_node_path_["default"].dirname(filePath), url);
|
|
3074
|
-
url = routeService.absolutePathToRoutePath(anotherFileAbsolutePath);
|
|
3075
|
-
}
|
|
3076
|
-
if ('boolean' == typeof cleanUrls) {
|
|
3077
|
-
url = (0, shared_.normalizeHref)(url, cleanUrls);
|
|
3078
|
-
if (!routeService.isExistRoute(url)) {
|
|
3079
|
-
deadLinks.set(nodeUrl, url);
|
|
3080
|
-
return nodeUrl;
|
|
3081
|
-
}
|
|
3082
|
-
} else {
|
|
3083
|
-
url = (0, shared_.normalizeHref)(url, false);
|
|
3084
|
-
if (!routeService.isExistRoute(url)) {
|
|
3085
|
-
deadLinks.set(nodeUrl, url);
|
|
3086
|
-
return nodeUrl;
|
|
3087
|
-
}
|
|
3088
|
-
url = url.replace(/\.html$/, cleanUrls);
|
|
3089
|
-
}
|
|
3090
|
-
if (search) url += `?${search}`;
|
|
3091
|
-
if (hash) url += `#${hash}`;
|
|
3092
|
-
if (__base) url = (0, shared_.withBase)(url, __base);
|
|
3093
|
-
return url;
|
|
3094
|
-
}
|
|
3095
|
-
const remarkLink = ({ cleanUrls, routeService, remarkLinkOptions, lint, __base })=>(tree, file)=>{
|
|
3096
|
-
const { checkDeadLinks: shouldCheckDeadLinks = true, autoPrefix = true } = remarkLinkOptions ?? {};
|
|
3097
|
-
const deadLinks = new Map();
|
|
3098
|
-
visit(tree, 'link', (node)=>{
|
|
3099
|
-
const { url: nodeUrl } = node;
|
|
3100
|
-
const link = normalizeLink(nodeUrl, routeService, file.path, cleanUrls, autoPrefix, deadLinks, __base);
|
|
3101
|
-
node.url = link;
|
|
3102
|
-
});
|
|
3103
|
-
visit(tree, 'definition', (node)=>{
|
|
3104
|
-
const { url: nodeUrl } = node;
|
|
3105
|
-
const link = normalizeLink(nodeUrl, routeService, file.path, cleanUrls, autoPrefix, deadLinks, __base);
|
|
3106
|
-
node.url = link;
|
|
3107
|
-
});
|
|
3108
|
-
if (shouldCheckDeadLinks && routeService) link_checkDeadLinks(shouldCheckDeadLinks, deadLinks, file, lint);
|
|
3109
|
-
};
|
|
3110
|
-
async function serve(options) {
|
|
3111
|
-
const { config, port: userPort, host: userHost, configFilePath } = options;
|
|
3112
|
-
const envPort = process.env.PORT;
|
|
3113
|
-
const envHost = process.env.HOST;
|
|
3114
|
-
const { builderConfig = {} } = config;
|
|
3115
|
-
const port = Number(envPort || userPort || builderConfig?.server?.port || 4173);
|
|
3116
|
-
const host = envHost || userHost || builderConfig?.server?.host || 'localhost';
|
|
3117
|
-
config.builderConfig = core_mergeRsbuildConfig(builderConfig, {
|
|
3118
|
-
server: {
|
|
3119
|
-
port,
|
|
3120
|
-
host
|
|
3121
|
-
}
|
|
3122
|
-
});
|
|
3123
|
-
const pluginDriver = await PluginDriver.create(config, configFilePath, true);
|
|
3124
|
-
const modifiedConfig = await pluginDriver.modifyConfig();
|
|
3125
|
-
const rsbuild = await initRsbuild(config.root, modifiedConfig, pluginDriver, await RouteService.createSimple(), false);
|
|
3126
|
-
return rsbuild.preview();
|
|
3127
|
-
}
|
|
3128
|
-
var __webpack_exports__RSPRESS_TEMP_DIR = shared_.RSPRESS_TEMP_DIR;
|
|
3129
|
-
var __webpack_exports__getSidebarDataGroup = shared_.getSidebarDataGroup;
|
|
3130
|
-
var __webpack_exports__normalizeHref = shared_.normalizeHref;
|
|
3131
|
-
var __webpack_exports__normalizePosixPath = shared_.normalizePosixPath;
|
|
3132
|
-
var __webpack_exports__removeTrailingSlash = shared_.removeTrailingSlash;
|
|
3133
|
-
var __webpack_exports__withBase = shared_.withBase;
|
|
3134
|
-
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 };
|
|
1
|
+
import "./4669.12208c6a.js";
|
|
2
|
+
import "./6289.c67fe0d5.js";
|
|
3
|
+
import "./9643.f109822d.js";
|
|
4
|
+
import "./3521.56e42d70.js";
|
|
5
|
+
export { RSPRESS_TEMP_DIR, getSidebarDataGroup, normalizeHref, normalizePosixPath, removeTrailingSlash, withBase } from "@rspress/shared";
|
|
6
|
+
export { logger } from "@rspress/shared/logger";
|
|
7
|
+
export { getIconUrlPath, getNodeAttribute, mergeDocConfig } from "@rspress/shared/node-utils";
|
|
8
|
+
export { matchPath } from "react-router-dom";
|
|
9
|
+
export { defineConfig } from "./cli/config/index.js";
|
|
10
|
+
export { build } from "./node/build.js";
|
|
11
|
+
export { dev } from "./node/dev.js";
|
|
12
|
+
export { remarkFileCodeBlock } from "./node/mdx/remarkPlugins/fileCodeBlock.js";
|
|
13
|
+
export { remarkLink } from "./node/mdx/remarkPlugins/link.js";
|
|
14
|
+
export { serve } from "./node/serve.js";
|
|
15
|
+
export { PluginDriver } from "./node/PluginDriver.js";
|
|
16
|
+
export { RouteService } from "./node/route/RouteService.js";
|