@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
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { RsbuildPlugin } from '@rsbuild/core';
|
|
2
|
-
import { type FactoryContext } from '../types';
|
|
2
|
+
import { type FactoryContext } from '../types.js';
|
|
3
3
|
export declare const rsbuildPluginDocVM: ({ config, userDocRoot, routeService, pluginDriver, }: Omit<FactoryContext, "alias">) => Promise<RsbuildPlugin[]>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { pluginVirtualModule } from "../../../3521.56e42d70.js";
|
|
2
|
+
import { createPageData } from "./createPageData.js";
|
|
3
|
+
const rsbuildPluginDocVM = async ({ config, userDocRoot, routeService, pluginDriver })=>{
|
|
4
|
+
const ref = {
|
|
5
|
+
pageData: null,
|
|
6
|
+
searchIndex: null,
|
|
7
|
+
indexHashByGroup: null,
|
|
8
|
+
filepaths: []
|
|
9
|
+
};
|
|
10
|
+
const searchIndexRsbuildPlugin = {
|
|
11
|
+
name: 'rsbuild-plugin-searchIndex',
|
|
12
|
+
async setup (api) {
|
|
13
|
+
api.modifyBundlerChain(async (bundlerChain)=>{
|
|
14
|
+
const alias = bundlerChain.resolve.alias.entries();
|
|
15
|
+
const { pageData, indexHashByGroup, searchIndex, filepaths } = await createPageData({
|
|
16
|
+
config,
|
|
17
|
+
alias: alias,
|
|
18
|
+
userDocRoot,
|
|
19
|
+
routeService,
|
|
20
|
+
pluginDriver
|
|
21
|
+
});
|
|
22
|
+
ref.pageData = pageData;
|
|
23
|
+
ref.searchIndex = searchIndex;
|
|
24
|
+
ref.indexHashByGroup = indexHashByGroup;
|
|
25
|
+
ref.filepaths = filepaths;
|
|
26
|
+
api.processAssets({
|
|
27
|
+
stage: 'report',
|
|
28
|
+
environments: [
|
|
29
|
+
'web'
|
|
30
|
+
]
|
|
31
|
+
}, ({ compilation, compiler })=>{
|
|
32
|
+
for (const [filename, stringifiedIndex] of Object.entries(searchIndex))compilation.emitAsset(`static/${filename}`, new compiler.webpack.sources.RawSource(stringifiedIndex));
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
return [
|
|
38
|
+
searchIndexRsbuildPlugin,
|
|
39
|
+
pluginVirtualModule({
|
|
40
|
+
tempDir: '.rspress',
|
|
41
|
+
virtualModules: {
|
|
42
|
+
["virtual-page-data"]: async ({ addDependency })=>{
|
|
43
|
+
for (const file of ref.filepaths)addDependency(file);
|
|
44
|
+
return `export const pageData = ${JSON.stringify(ref.pageData, null, 2)};
|
|
45
|
+
export const searchIndexHash = ${JSON.stringify(ref.indexHashByGroup, null, 2)};`;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
];
|
|
50
|
+
};
|
|
51
|
+
export { rsbuildPluginDocVM };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { type VirtualModulePlugin } from './types';
|
|
1
|
+
import { type VirtualModulePlugin } from './types.js';
|
|
2
2
|
export declare const routeListVMPlugin: VirtualModulePlugin;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { type VirtualModulePlugin } from './types';
|
|
1
|
+
import { type VirtualModulePlugin } from './types.js';
|
|
2
2
|
export declare const searchHookVMPlugin: VirtualModulePlugin;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { node_path } from "../../6289.c67fe0d5.js";
|
|
2
|
+
const searchHookVMPlugin = (context)=>({
|
|
3
|
+
["virtual-search-hooks"]: ()=>{
|
|
4
|
+
const { config } = context;
|
|
5
|
+
let content = 'export const onSearch = () => {};';
|
|
6
|
+
const searchHooks = 'object' == typeof config.search && config.search?.searchHooks;
|
|
7
|
+
if (searchHooks) content = `export * from ${JSON.stringify(node_path.posix.normalize(searchHooks))}`;
|
|
8
|
+
return content;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
export { searchHookVMPlugin };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { getIconUrlPath } from "../../../9643.f109822d.js";
|
|
2
|
+
import { normalizeThemeConfig } from "./normalizeThemeConfig.js";
|
|
3
|
+
async function createSiteData(userConfig) {
|
|
4
|
+
const tempSearchObj = Object.assign({}, userConfig.search);
|
|
5
|
+
if (tempSearchObj) tempSearchObj.searchHooks = void 0;
|
|
6
|
+
const siteData = {
|
|
7
|
+
base: userConfig.base ?? '/',
|
|
8
|
+
title: userConfig?.title || '',
|
|
9
|
+
description: userConfig?.description || '',
|
|
10
|
+
icon: getIconUrlPath(userConfig?.icon) || '',
|
|
11
|
+
route: userConfig?.route || {},
|
|
12
|
+
themeConfig: await normalizeThemeConfig(userConfig),
|
|
13
|
+
lang: userConfig?.lang || '',
|
|
14
|
+
locales: userConfig?.locales || userConfig.themeConfig?.locales || [],
|
|
15
|
+
logo: userConfig?.logo || '',
|
|
16
|
+
logoText: userConfig?.logoText || '',
|
|
17
|
+
multiVersion: {
|
|
18
|
+
default: userConfig?.multiVersion?.default || '',
|
|
19
|
+
versions: userConfig?.multiVersion?.versions || []
|
|
20
|
+
},
|
|
21
|
+
search: tempSearchObj ?? {
|
|
22
|
+
mode: 'local'
|
|
23
|
+
},
|
|
24
|
+
markdown: {
|
|
25
|
+
showLineNumbers: userConfig?.markdown?.showLineNumbers ?? false,
|
|
26
|
+
defaultWrapCode: userConfig?.markdown?.defaultWrapCode ?? false,
|
|
27
|
+
shiki: {}
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
return {
|
|
31
|
+
siteData
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export { createSiteData };
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { isExternalUrl, slash, addLeadingSlash, normalizeHref } from "../../../4669.12208c6a.js";
|
|
2
|
+
import { getI18nData } from "../i18n.js";
|
|
3
|
+
import { applyReplaceRules } from "../../utils/applyReplaceRules.js";
|
|
4
|
+
async function normalizeThemeConfig(docConfig) {
|
|
5
|
+
const { locales: siteLocales, lang, replaceRules = [], multiVersion } = docConfig;
|
|
6
|
+
const { versions = [] } = multiVersion || {};
|
|
7
|
+
const hasMultiVersion = versions.length > 0;
|
|
8
|
+
docConfig.themeConfig = docConfig.themeConfig || {};
|
|
9
|
+
const { themeConfig } = docConfig;
|
|
10
|
+
const locales = siteLocales ?? (themeConfig?.locales || []);
|
|
11
|
+
const i18nTextData = await getI18nData(docConfig);
|
|
12
|
+
const normalizeLinkPrefix = (link, currentLang)=>{
|
|
13
|
+
const normalizedLink = slash(link);
|
|
14
|
+
if (!currentLang || !link || normalizedLink.startsWith(`/${currentLang}`) || isExternalUrl(normalizedLink) || hasMultiVersion) return normalizedLink;
|
|
15
|
+
return lang === currentLang ? normalizedLink : `/${currentLang}${addLeadingSlash(normalizedLink)}`;
|
|
16
|
+
};
|
|
17
|
+
const getI18nText = (key, currentLang)=>{
|
|
18
|
+
const text = i18nTextData[key]?.[currentLang];
|
|
19
|
+
return text || key;
|
|
20
|
+
};
|
|
21
|
+
const cleanUrls = false;
|
|
22
|
+
const transformLink = (link, currentLang)=>normalizeHref(normalizeLinkPrefix(link, currentLang), cleanUrls);
|
|
23
|
+
const textReplace = (text, currentLang)=>applyReplaceRules(getI18nText(text, currentLang), replaceRules);
|
|
24
|
+
const normalizeSidebar = (sidebar, currentLang)=>{
|
|
25
|
+
const normalizedSidebar = {};
|
|
26
|
+
if (!sidebar) return {};
|
|
27
|
+
const normalizeSidebarItem = (item)=>{
|
|
28
|
+
if ('object' == typeof item && 'dividerType' in item) return item;
|
|
29
|
+
if ('object' == typeof item && 'sectionHeaderText' in item) {
|
|
30
|
+
item.sectionHeaderText = textReplace(item.sectionHeaderText, currentLang);
|
|
31
|
+
return item;
|
|
32
|
+
}
|
|
33
|
+
if ('object' == typeof item && 'items' in item) return {
|
|
34
|
+
...item,
|
|
35
|
+
text: textReplace(item.text, currentLang),
|
|
36
|
+
...'link' in item && item.link ? {
|
|
37
|
+
link: transformLink(item.link, currentLang)
|
|
38
|
+
} : {},
|
|
39
|
+
collapsed: item.collapsed ?? false,
|
|
40
|
+
collapsible: item.collapsible ?? true,
|
|
41
|
+
items: item.items.map((subItem)=>normalizeSidebarItem(subItem))
|
|
42
|
+
};
|
|
43
|
+
return {
|
|
44
|
+
...item,
|
|
45
|
+
text: textReplace(item.text, currentLang),
|
|
46
|
+
link: transformLink(item.link, currentLang)
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
const normalizeSidebar = (sidebar)=>{
|
|
50
|
+
Object.keys(sidebar).forEach((key)=>{
|
|
51
|
+
const value = sidebar[key];
|
|
52
|
+
normalizedSidebar[key] = value.map(normalizeSidebarItem);
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
normalizeSidebar(sidebar);
|
|
56
|
+
return normalizedSidebar;
|
|
57
|
+
};
|
|
58
|
+
const normalizeNav = (nav, currentLang)=>{
|
|
59
|
+
if (!nav) return [];
|
|
60
|
+
const transformNavItem = (navItem)=>({
|
|
61
|
+
...navItem,
|
|
62
|
+
...navItem.text ? {
|
|
63
|
+
text: textReplace(navItem.text, currentLang)
|
|
64
|
+
} : {},
|
|
65
|
+
...'link' in navItem ? {
|
|
66
|
+
link: transformLink(navItem.link, currentLang)
|
|
67
|
+
} : {},
|
|
68
|
+
...'items' in navItem ? {
|
|
69
|
+
items: navItem.items.map((item)=>transformNavItem(item))
|
|
70
|
+
} : {}
|
|
71
|
+
});
|
|
72
|
+
if (Array.isArray(nav)) return nav.map(transformNavItem);
|
|
73
|
+
return Object.entries(nav).reduce((acc, [key, value])=>{
|
|
74
|
+
acc[key] = value.map(transformNavItem);
|
|
75
|
+
return acc;
|
|
76
|
+
}, {});
|
|
77
|
+
};
|
|
78
|
+
if (locales.length) themeConfig.locales = locales.map(({ lang: currentLang, label })=>{
|
|
79
|
+
const localeInThemeConfig = themeConfig.locales?.find((locale)=>locale.lang === currentLang);
|
|
80
|
+
return {
|
|
81
|
+
lang: currentLang,
|
|
82
|
+
label,
|
|
83
|
+
...localeInThemeConfig,
|
|
84
|
+
sidebar: normalizeSidebar(localeInThemeConfig?.sidebar ?? themeConfig.sidebar, currentLang),
|
|
85
|
+
nav: normalizeNav(localeInThemeConfig?.nav ?? themeConfig.nav, currentLang)
|
|
86
|
+
};
|
|
87
|
+
});
|
|
88
|
+
else {
|
|
89
|
+
themeConfig.sidebar = normalizeSidebar(themeConfig?.sidebar, '');
|
|
90
|
+
themeConfig.nav = normalizeNav(themeConfig?.nav, '');
|
|
91
|
+
}
|
|
92
|
+
return themeConfig;
|
|
93
|
+
}
|
|
94
|
+
export { normalizeThemeConfig };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { type VirtualModulePlugin } from '../types';
|
|
1
|
+
import { type VirtualModulePlugin } from '../types.js';
|
|
2
2
|
export declare const siteDataVMPlugin: VirtualModulePlugin;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { logger } from "../../../6289.c67fe0d5.js";
|
|
2
|
+
import { modifyConfigWithAutoNavSide } from "../../auto-nav-sidebar/index.js";
|
|
3
|
+
import { createSiteData } from "./createSiteData.js";
|
|
4
|
+
const siteDataVMPlugin = (context)=>{
|
|
5
|
+
const { config, pluginDriver } = context;
|
|
6
|
+
return {
|
|
7
|
+
["virtual-site-data"]: async ({ addDependency })=>{
|
|
8
|
+
const force = !pluginDriver.haveNavSidebarConfig;
|
|
9
|
+
const metaFileSet = new Set();
|
|
10
|
+
const mdFileSet = new Set();
|
|
11
|
+
const now = performance.now();
|
|
12
|
+
try {
|
|
13
|
+
await modifyConfigWithAutoNavSide(config, metaFileSet, mdFileSet, force);
|
|
14
|
+
} finally{
|
|
15
|
+
for (const metaFile of metaFileSet)addDependency(metaFile);
|
|
16
|
+
for (const mdFile of mdFileSet)addDependency(mdFile);
|
|
17
|
+
logger.debug(`modifyConfigWithAutoNavSide - size: ${mdFileSet.size} cost: ${performance.now() - now}ms`);
|
|
18
|
+
}
|
|
19
|
+
const { siteData } = await createSiteData(config);
|
|
20
|
+
return `export default ${JSON.stringify(siteData, null, 2)}`;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
export { siteDataVMPlugin };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { type VirtualModulePlugin } from './types';
|
|
1
|
+
import { type VirtualModulePlugin } from './types.js';
|
|
2
2
|
export declare const socialLinksVMPlugin: VirtualModulePlugin;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { getSocialIcons } from "../utils/getSocialIcons.js";
|
|
2
|
+
const socialLinksVMPlugin = (context)=>{
|
|
3
|
+
const { config } = context;
|
|
4
|
+
return {
|
|
5
|
+
["virtual-social-links"]: ()=>`export default ${JSON.stringify(getSocialIcons(config.themeConfig?.socialLinks), null, 2)}`
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
export { socialLinksVMPlugin };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { TransformHandler } from '@rsbuild/core';
|
|
2
2
|
import type { UserConfig } from '@rspress/shared';
|
|
3
|
-
import type { PluginDriver } from '../PluginDriver';
|
|
4
|
-
import type { RouteService } from '../route/RouteService';
|
|
3
|
+
import type { PluginDriver } from '../PluginDriver.js';
|
|
4
|
+
import type { RouteService } from '../route/RouteService.js';
|
|
5
5
|
export interface FactoryContext {
|
|
6
6
|
userDocRoot: string;
|
|
7
7
|
config: UserConfig;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { mergeRsbuildConfig } from "../3521.56e42d70.js";
|
|
2
|
+
import { PluginDriver } from "./PluginDriver.js";
|
|
3
|
+
import { initRsbuild } from "./initRsbuild.js";
|
|
4
|
+
import { RouteService } from "./route/RouteService.js";
|
|
5
|
+
async function serve(options) {
|
|
6
|
+
const { config, port: userPort, host: userHost, configFilePath } = options;
|
|
7
|
+
const envPort = process.env.PORT;
|
|
8
|
+
const envHost = process.env.HOST;
|
|
9
|
+
const { builderConfig = {} } = config;
|
|
10
|
+
const port = Number(envPort || userPort || builderConfig?.server?.port || 4173);
|
|
11
|
+
const host = envHost || userHost || builderConfig?.server?.host || 'localhost';
|
|
12
|
+
config.builderConfig = mergeRsbuildConfig(builderConfig, {
|
|
13
|
+
server: {
|
|
14
|
+
port,
|
|
15
|
+
host
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
const pluginDriver = await PluginDriver.create(config, configFilePath, true);
|
|
19
|
+
const modifiedConfig = await pluginDriver.modifyConfig();
|
|
20
|
+
const rsbuild = await initRsbuild(config.root, modifiedConfig, pluginDriver, await RouteService.createSimple(), false);
|
|
21
|
+
return rsbuild.preview();
|
|
22
|
+
}
|
|
23
|
+
export { serve };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { META_GENERATOR, RSPRESS_VERSION, APP_HTML_MARKER, HEAD_MARKER } from "../constants.js";
|
|
2
|
+
import { createError } from "../utils/error.js";
|
|
3
|
+
async function renderConfigHead(head, route) {
|
|
4
|
+
if (!isRouteMeta(route)) return '';
|
|
5
|
+
if (!head || 0 === head.length) return '';
|
|
6
|
+
return head.map((head)=>{
|
|
7
|
+
if ('string' == typeof head) return head;
|
|
8
|
+
if ('function' == typeof head) {
|
|
9
|
+
const resultHead = head(route);
|
|
10
|
+
if (!resultHead) return '';
|
|
11
|
+
if ('string' == typeof resultHead) return resultHead;
|
|
12
|
+
return `<${resultHead[0]} ${renderAttrs(resultHead[1])}>`;
|
|
13
|
+
}
|
|
14
|
+
return `<${head[0]} ${renderAttrs(head[1])}>`;
|
|
15
|
+
}).join('');
|
|
16
|
+
}
|
|
17
|
+
async function renderHtmlTemplate(htmlTemplate, head, route, appHtml = '') {
|
|
18
|
+
const replacedHtmlTemplate = htmlTemplate.replace(APP_HTML_MARKER, ()=>appHtml).replace(META_GENERATOR, ()=>`<meta name="generator" content="Rspress v${RSPRESS_VERSION}">`).replace(HEAD_MARKER, [
|
|
19
|
+
await renderConfigHead(head, route)
|
|
20
|
+
].join(''));
|
|
21
|
+
return replacedHtmlTemplate;
|
|
22
|
+
}
|
|
23
|
+
function renderAttrs(attrs) {
|
|
24
|
+
return Object.entries(attrs).map(([key, value])=>{
|
|
25
|
+
if ('boolean' == typeof value) return key;
|
|
26
|
+
if ('string' == typeof value || 'number' == typeof value) return `${key}="${value}"`;
|
|
27
|
+
throw createError(`Invalid value for attribute ${key}:${JSON.stringify(value)}`);
|
|
28
|
+
}).join('');
|
|
29
|
+
}
|
|
30
|
+
function isRouteMeta(route) {
|
|
31
|
+
return !!route && 'object' == typeof route && 'routePath' in route && 'absolutePath' in route;
|
|
32
|
+
}
|
|
33
|
+
export { renderHtmlTemplate };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { transformHtmlTemplate, pathToFileURL, createHead } from "../../5485.077f14ff.js";
|
|
2
|
+
import { logger, picocolors } from "../../6289.c67fe0d5.js";
|
|
3
|
+
import { hintSSGFailed } from "../logger/hint.js";
|
|
4
|
+
import { renderHtmlTemplate } from "./renderHtmlTemplate.js";
|
|
5
|
+
async function renderPage(route, htmlTemplate, configHead, ssrBundlePath) {
|
|
6
|
+
let render;
|
|
7
|
+
try {
|
|
8
|
+
const { default: ssrExports } = await import(pathToFileURL(ssrBundlePath).toString());
|
|
9
|
+
render = await ssrExports.render;
|
|
10
|
+
} catch (e) {
|
|
11
|
+
if (e instanceof Error) {
|
|
12
|
+
logger.error(`Failed to load SSG bundle: ${picocolors.yellow(ssrBundlePath)}: ${e.message}`);
|
|
13
|
+
logger.debug(e);
|
|
14
|
+
hintSSGFailed();
|
|
15
|
+
}
|
|
16
|
+
throw e;
|
|
17
|
+
}
|
|
18
|
+
const head = createHead();
|
|
19
|
+
const { routePath, absolutePath } = route;
|
|
20
|
+
let appHtml = '';
|
|
21
|
+
if (render) try {
|
|
22
|
+
({ appHtml } = await render(routePath, head));
|
|
23
|
+
} catch (e) {
|
|
24
|
+
if (e instanceof Error) {
|
|
25
|
+
logger.error(`Page "${picocolors.yellow(routePath)}" SSG rendering failed.
|
|
26
|
+
${absolutePath ? picocolors.gray(` File: ${absolutePath}\n`) : ''} ${picocolors.gray(e.toString())}`);
|
|
27
|
+
throw e;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const replacedHtmlTemplate = await renderHtmlTemplate(htmlTemplate, configHead, route, appHtml);
|
|
31
|
+
const html = await transformHtmlTemplate(head, replacedHtmlTemplate);
|
|
32
|
+
return html;
|
|
33
|
+
}
|
|
34
|
+
export { renderPage };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { workerData } from "./renderPageWorker.474f9f73.js";
|
|
2
|
+
import { createError } from "../utils/error.js";
|
|
3
|
+
import { pMap } from "../../5485.077f14ff.js";
|
|
4
|
+
import { renderPage } from "./renderPage.js";
|
|
5
|
+
const params = workerData?.[1]?.params;
|
|
6
|
+
if (!params) throw createError('SSG Worker Thread workerData params missing');
|
|
7
|
+
const { htmlTemplate: htmlTemplate, head: head, ssrBundlePath: ssrBundlePath } = params;
|
|
8
|
+
const exportWorkerGlueFn = async ({ routes })=>pMap(routes, async (route)=>{
|
|
9
|
+
const html = await renderPage(route, htmlTemplate, head, ssrBundlePath);
|
|
10
|
+
return html;
|
|
11
|
+
}, {
|
|
12
|
+
concurrency: 10
|
|
13
|
+
});
|
|
14
|
+
const renderPageWorker = exportWorkerGlueFn;
|
|
15
|
+
export default renderPageWorker;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { UserConfig } from '@rspress/shared';
|
|
2
|
-
import type { RouteService } from '../route/RouteService';
|
|
2
|
+
import type { RouteService } from '../route/RouteService.js';
|
|
3
3
|
export declare function renderPages(routeService: RouteService, config: UserConfig, ssrBundlePath: string, htmlTemplate: string, emitAsset: (assetName: string, content: string | Buffer) => void): Promise<void>;
|
|
4
4
|
export declare function renderCSRPages(routeService: RouteService, config: UserConfig, htmlTemplate: string, emitAsset: (assetName: string, content: string | Buffer) => void): Promise<void>;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/*! For license information please see renderPages.js.LICENSE.txt */
|
|
2
|
+
import { logger, picocolors } from "../../6289.c67fe0d5.js";
|
|
3
|
+
import { chunk } from "../../3521.56e42d70.js";
|
|
4
|
+
import { SSGWorkerThreadTaskSize, getNumberOfThreads, SSGWorkerThreadRecyclerMaxMemory, SSGConcurrency } from "./ssgEnv.js";
|
|
5
|
+
import { pMap } from "../../5485.077f14ff.js";
|
|
6
|
+
import { renderPage } from "./renderPage.js";
|
|
7
|
+
import { hintSSGFailed } from "../logger/hint.js";
|
|
8
|
+
import { renderHtmlTemplate } from "./renderHtmlTemplate.js";
|
|
9
|
+
const routePath2HtmlFileName = (routePath)=>{
|
|
10
|
+
let fileName = routePath;
|
|
11
|
+
fileName = fileName.endsWith('/') ? `${routePath}index.html` : `${routePath}.html`;
|
|
12
|
+
return fileName.replace(/^\/+/, '');
|
|
13
|
+
};
|
|
14
|
+
async function renderPages(routeService, config, ssrBundlePath, htmlTemplate, emitAsset) {
|
|
15
|
+
logger.info('Rendering pages...');
|
|
16
|
+
const startTime = Date.now();
|
|
17
|
+
const ssg = config.ssg || true;
|
|
18
|
+
try {
|
|
19
|
+
const routes = routeService.getRoutes();
|
|
20
|
+
if (!routeService.isExistRoute('/404')) routes.push({
|
|
21
|
+
routePath: '/404'
|
|
22
|
+
});
|
|
23
|
+
if ('object' == typeof ssg && Array.isArray(ssg?.experimentalExcludeRoutePaths) && ssg.experimentalExcludeRoutePaths.length > 0) {
|
|
24
|
+
const shouldIgnoreRoutePaths = new Set();
|
|
25
|
+
const shouldIgnoreRoutePathsRegExp = [];
|
|
26
|
+
for (const routePath of ssg.experimentalExcludeRoutePaths)if ('string' == typeof routePath) shouldIgnoreRoutePaths.add(routePath);
|
|
27
|
+
else if (routePath instanceof RegExp) shouldIgnoreRoutePathsRegExp.push(routePath);
|
|
28
|
+
const promiseList = [];
|
|
29
|
+
const csrRoutes = [];
|
|
30
|
+
const ssgRoutes = [];
|
|
31
|
+
for (const route of routes)if (shouldIgnoreRoutePaths.has(route.routePath) || shouldIgnoreRoutePathsRegExp.some((reg)=>reg.test(route.routePath))) {
|
|
32
|
+
csrRoutes.push(route);
|
|
33
|
+
promiseList.push(renderCSRPage(config.head, route, htmlTemplate, emitAsset));
|
|
34
|
+
} else ssgRoutes.push(route);
|
|
35
|
+
if (csrRoutes.length > 0) {
|
|
36
|
+
logger.warn(`Some routes are ignored in SSG and fallback to CSR via \`ssg.experimentalExcludeRoutePaths\`: ${picocolors.yellow(csrRoutes.map((r)=>r.routePath).join(', '))}`);
|
|
37
|
+
await Promise.all(promiseList);
|
|
38
|
+
routes.length = 0;
|
|
39
|
+
routes.push(...ssgRoutes);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if ('object' == typeof ssg && ssg?.experimentalWorker) {
|
|
43
|
+
const numberOfThreads = getNumberOfThreads(routes.length);
|
|
44
|
+
const Tinypool = await import("tinypool").then((m)=>m.default);
|
|
45
|
+
const pool = new Tinypool({
|
|
46
|
+
filename: new URL('./renderPageWorker.js', import.meta.url).href,
|
|
47
|
+
concurrentTasksPerWorker: 1,
|
|
48
|
+
minThreads: numberOfThreads,
|
|
49
|
+
maxThreads: numberOfThreads,
|
|
50
|
+
/**
|
|
51
|
+
* https://github.com/facebook/docusaurus/blob/0306d182407bb98f140cd5ec7481fa9608fe0297/packages/docusaurus/src/ssg/ssgExecutor.ts#L123
|
|
52
|
+
* @license MIT
|
|
53
|
+
*/ maxMemoryLimitBeforeRecycle: SSGWorkerThreadRecyclerMaxMemory(),
|
|
54
|
+
isolateWorkers: false,
|
|
55
|
+
workerData: {
|
|
56
|
+
params: {
|
|
57
|
+
htmlTemplate,
|
|
58
|
+
head: config.head,
|
|
59
|
+
ssrBundlePath
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
await Promise.all(chunk(routes, SSGWorkerThreadTaskSize()).map(async (routes)=>{
|
|
64
|
+
const htmlList = await pool.run({
|
|
65
|
+
routes
|
|
66
|
+
});
|
|
67
|
+
for(let i = 0; i < routes.length; i++){
|
|
68
|
+
const route = routes[i];
|
|
69
|
+
const html = htmlList[i];
|
|
70
|
+
const fileName = routePath2HtmlFileName(route.routePath);
|
|
71
|
+
emitAsset(fileName, html);
|
|
72
|
+
}
|
|
73
|
+
}));
|
|
74
|
+
await pool.destroy();
|
|
75
|
+
} else await pMap(routes, async (route)=>{
|
|
76
|
+
const html = await renderPage(route, htmlTemplate, config.head, ssrBundlePath);
|
|
77
|
+
const fileName = routePath2HtmlFileName(route.routePath);
|
|
78
|
+
emitAsset(fileName, html);
|
|
79
|
+
}, {
|
|
80
|
+
concurrency: SSGConcurrency()
|
|
81
|
+
});
|
|
82
|
+
const totalTime = Date.now() - startTime;
|
|
83
|
+
logger.success(`Pages rendered in ${picocolors.yellow(totalTime)} ms.`);
|
|
84
|
+
} catch (e) {
|
|
85
|
+
if (e instanceof Error) {
|
|
86
|
+
logger.error(`Pages render error: ${e.message}`);
|
|
87
|
+
logger.debug(e);
|
|
88
|
+
hintSSGFailed();
|
|
89
|
+
}
|
|
90
|
+
throw e;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
async function renderCSRPage(head, route, htmlTemplate, emitAsset) {
|
|
94
|
+
const html = await renderHtmlTemplate(htmlTemplate, head, route, '');
|
|
95
|
+
const fileName = routePath2HtmlFileName(route.routePath);
|
|
96
|
+
emitAsset(fileName, html);
|
|
97
|
+
}
|
|
98
|
+
async function renderCSRPages(routeService, config, htmlTemplate, emitAsset) {
|
|
99
|
+
const routes = routeService.getRoutes();
|
|
100
|
+
if (!routeService.isExistRoute('/404')) routes.push({
|
|
101
|
+
routePath: '/404'
|
|
102
|
+
});
|
|
103
|
+
await Promise.all(routes.map((route)=>renderCSRPage(config.head, route, htmlTemplate, emitAsset)));
|
|
104
|
+
}
|
|
105
|
+
export { renderCSRPages, renderPages };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { RsbuildPlugin } from '@rsbuild/core';
|
|
2
2
|
import type { UserConfig } from '@rspress/shared';
|
|
3
|
-
import type { RouteService } from '../route/RouteService';
|
|
3
|
+
import type { RouteService } from '../route/RouteService.js';
|
|
4
4
|
export declare const rsbuildPluginCSR: ({ routeService, config, }: {
|
|
5
5
|
routeService: RouteService;
|
|
6
6
|
config: UserConfig;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { renderCSRPages } from "./renderPages.js";
|
|
2
|
+
const rsbuildPluginCSR = ({ routeService, config })=>({
|
|
3
|
+
name: 'rspress-inner-rsbuild-plugin-csr',
|
|
4
|
+
async setup (api) {
|
|
5
|
+
api.onBeforeBuild(()=>{
|
|
6
|
+
api.processAssets({
|
|
7
|
+
stage: 'report',
|
|
8
|
+
environments: [
|
|
9
|
+
'web'
|
|
10
|
+
]
|
|
11
|
+
}, async ({ assets, compilation, compiler })=>{
|
|
12
|
+
if (compilation.errors.length > 0) return;
|
|
13
|
+
const emitAsset = (assetName, content)=>{
|
|
14
|
+
compilation.emitAsset(assetName, new compiler.webpack.sources.RawSource(content));
|
|
15
|
+
};
|
|
16
|
+
let htmlTemplate = '';
|
|
17
|
+
for (const [assetName, assetSource] of Object.entries(assets))if ('index.html' === assetName) {
|
|
18
|
+
htmlTemplate = assetSource.source().toString();
|
|
19
|
+
compilation.deleteAsset(assetName);
|
|
20
|
+
break;
|
|
21
|
+
}
|
|
22
|
+
await renderCSRPages(routeService, config, htmlTemplate, emitAsset);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
export { rsbuildPluginCSR };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { RsbuildPlugin } from '@rsbuild/core';
|
|
2
2
|
import { type UserConfig } from '@rspress/shared';
|
|
3
|
-
import type { RouteService } from '../route/RouteService';
|
|
3
|
+
import type { RouteService } from '../route/RouteService.js';
|
|
4
4
|
export declare const rsbuildPluginSSG: ({ routeService, config, }: {
|
|
5
5
|
routeService: RouteService;
|
|
6
6
|
config: UserConfig;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { logger, writeFile, mkdir, rm, join } from "../../6289.c67fe0d5.js";
|
|
2
|
+
import { isDebugMode } from "../../4669.12208c6a.js";
|
|
3
|
+
import { NODE_SSG_BUNDLE_FOLDER, NODE_SSG_BUNDLE_NAME } from "../constants.js";
|
|
4
|
+
import { renderPages } from "./renderPages.js";
|
|
5
|
+
const rsbuildPluginSSG = ({ routeService, config })=>({
|
|
6
|
+
name: 'rspress-inner-rsbuild-plugin-ssg',
|
|
7
|
+
async setup (api) {
|
|
8
|
+
api.onBeforeBuild(()=>{
|
|
9
|
+
let htmlTemplate = '';
|
|
10
|
+
let hasError = false;
|
|
11
|
+
const indexHtmlEmittedInWeb = new Promise((resolve, reject)=>{
|
|
12
|
+
api.processAssets({
|
|
13
|
+
stage: 'report',
|
|
14
|
+
environments: [
|
|
15
|
+
'web'
|
|
16
|
+
]
|
|
17
|
+
}, ({ assets, compilation })=>{
|
|
18
|
+
if (compilation.errors.length > 0) {
|
|
19
|
+
hasError = true;
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
for (const [assetName, assetSource] of Object.entries(assets))if ('index.html' === assetName) {
|
|
23
|
+
htmlTemplate = assetSource.source().toString();
|
|
24
|
+
compilation.deleteAsset(assetName);
|
|
25
|
+
resolve();
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
reject();
|
|
29
|
+
});
|
|
30
|
+
}).catch(()=>{
|
|
31
|
+
const message = 'SSG requires an `index.html` as entry, but this file is not emitted successfully in the web target.';
|
|
32
|
+
logger.error(message);
|
|
33
|
+
const error = new Error(message);
|
|
34
|
+
throw error;
|
|
35
|
+
});
|
|
36
|
+
api.processAssets({
|
|
37
|
+
stage: 'optimize-transfer',
|
|
38
|
+
environments: [
|
|
39
|
+
'node'
|
|
40
|
+
]
|
|
41
|
+
}, async ({ assets, compilation, environment, compiler })=>{
|
|
42
|
+
if (compilation.errors.length > 0) {
|
|
43
|
+
hasError = true;
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (hasError) return;
|
|
47
|
+
const emitAsset = (assetName, content)=>{
|
|
48
|
+
compilation.emitAsset(assetName, new compiler.webpack.sources.RawSource(content));
|
|
49
|
+
};
|
|
50
|
+
const distPath = environment.distPath;
|
|
51
|
+
const ssgFolderPath = join(distPath, NODE_SSG_BUNDLE_FOLDER);
|
|
52
|
+
const mainCjsAbsolutePath = join(ssgFolderPath, NODE_SSG_BUNDLE_NAME);
|
|
53
|
+
await mkdir(ssgFolderPath, {
|
|
54
|
+
recursive: true
|
|
55
|
+
});
|
|
56
|
+
await Promise.all(Object.entries(assets).map(async ([assetName, assetSource])=>{
|
|
57
|
+
if (assetName.startsWith(`${NODE_SSG_BUNDLE_FOLDER}/`)) {
|
|
58
|
+
const fileAbsolutePath = join(distPath, assetName);
|
|
59
|
+
await writeFile(fileAbsolutePath, assetSource.source().toString());
|
|
60
|
+
compilation.deleteAsset(assetName);
|
|
61
|
+
}
|
|
62
|
+
}));
|
|
63
|
+
await indexHtmlEmittedInWeb;
|
|
64
|
+
await renderPages(routeService, config, mainCjsAbsolutePath, htmlTemplate, emitAsset);
|
|
65
|
+
if (!isDebugMode()) await rm(ssgFolderPath, {
|
|
66
|
+
recursive: true
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
export { rsbuildPluginSSG };
|