@rspress/core 2.0.0-rc.1 → 2.0.0-rc.2
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.989ee664.js +1791 -0
- package/dist/1218.3869bad6.js +2 -0
- package/dist/4669.12208c6a.js +2 -0
- package/dist/5313.6594aba0.js +63 -0
- package/dist/5485.2a0273cf.js +98 -0
- package/dist/6289.c67fe0d5.js +5 -0
- package/dist/7805.cadab34e.js +4 -0
- package/dist/8813.9da1f210.js +2 -0
- 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/Banner/index.tsx +3 -4
- package/dist/eject-theme/components/Callout/index.scss +0 -2
- package/dist/eject-theme/components/CodeBlock/index.scss +4 -12
- package/dist/eject-theme/components/CodeBlock/index.tsx +6 -1
- 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/table.tsx +10 -4
- package/dist/eject-theme/components/DocContent/index.tsx +3 -3
- package/dist/eject-theme/components/{DocContent/FallbackHeading.tsx → FallbackHeading/index.tsx} +20 -11
- package/dist/eject-theme/components/Link/index.tsx +13 -4
- 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/NavScreenMenuItem.tsx +2 -3
- package/dist/eject-theme/components/Overview/OverviewGroup.tsx +1 -2
- package/dist/eject-theme/components/Overview/index.tsx +6 -2
- 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/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 +19 -22
- 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 +143 -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 +228 -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 +1 -0
- package/dist/node/constants.js +33 -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 +338 -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} +2 -2
- package/dist/node/mdx/options.d.ts +2 -2
- package/dist/node/mdx/options.js +100 -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 +80 -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 +202 -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 +9 -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/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/components/Banner/index.d.ts +1 -1
- package/dist/theme/components/Banner/index.js +2 -3
- package/dist/theme/components/Callout/index.css +0 -2
- package/dist/theme/components/CodeBlock/index.css +4 -15
- package/dist/theme/components/CodeBlock/index.js +1 -0
- 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/table.d.ts +2 -2
- package/dist/theme/components/DocContent/docComponents/table.js +8 -3
- package/dist/theme/components/DocContent/index.js +2 -3
- package/dist/theme/components/{DocContent/FallbackHeading.js → FallbackHeading/index.js} +19 -11
- package/dist/theme/components/HoverGroup/useHoverGroup.d.ts +1 -1
- package/dist/theme/components/Link/index.js +9 -5
- package/dist/theme/components/Nav/NavMenu.js +2 -3
- package/dist/theme/components/NavHamburger/index.js +3 -4
- package/dist/theme/components/NavScreen/NavScreenMenuItem.js +2 -3
- package/dist/theme/components/Overview/OverviewGroup.js +1 -2
- package/dist/theme/components/Overview/index.js +1 -2
- 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/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 +13 -22
- package/dist/theme/components/Toc/TocItem.css +2 -3
- package/dist/theme/components/Toc/TocItem.js +1 -0
- package/dist/theme/icons.d.ts +25 -0
- package/dist/theme/icons.js +47 -0
- package/dist/theme/index.d.ts +62 -59
- package/dist/theme/index.js +4 -1
- package/dist/theme/layout/DocLayout/index.css +2 -2
- package/dist/theme/logic/useFullTextSearch.d.ts +1 -1
- package/dist/theme/styles/scrollbar.css +1 -0
- package/dist/theme/styles/vars/base-vars.css +5 -3
- package/dist/theme/styles/vars/home-vars.css +2 -1
- package/package.json +17 -18
- 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/Search/logic/util.test.d.ts +0 -1
- /package/dist/cli/{config.d.ts → config/index.d.ts} +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
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/*! For license information please see ssgEnv.js.LICENSE.txt */
|
|
2
|
+
import { node_os } from "../../7805.cadab34e.js";
|
|
3
|
+
/**
|
|
4
|
+
* these codes are copied from
|
|
5
|
+
* @link https://github.com/facebook/docusaurus/blob/45065e8d2b5831117b8d69fec1be28f5520cf105/packages/docusaurus/src/ssg/ssgEnv.ts#L11
|
|
6
|
+
* @license MIT
|
|
7
|
+
*/ function SSGWorkerThreadTaskSize() {
|
|
8
|
+
return process.env.RSPRESS_SSG_WORKER_THREAD_TASK_SIZE ? Number.parseInt(process.env.RSPRESS_SSG_WORKER_THREAD_TASK_SIZE, 10) : 10;
|
|
9
|
+
}
|
|
10
|
+
function SSGWorkerThreadRecyclerMaxMemory() {
|
|
11
|
+
return process.env.RSPRESS_SSG_WORKER_THREAD_RECYCLER_MAX_MEMORY ? Number.parseInt(process.env.RSPRESS_SSG_WORKER_THREAD_RECYCLER_MAX_MEMORY, 10) : 1000000000;
|
|
12
|
+
}
|
|
13
|
+
function inferNumberOfThreads({ pageCount, cpuCount, minPagesPerCpu }) {
|
|
14
|
+
const threadsByWorkload = Math.ceil(pageCount / minPagesPerCpu);
|
|
15
|
+
return Math.max(1, Math.min(threadsByWorkload, cpuCount));
|
|
16
|
+
}
|
|
17
|
+
function SSGWorkerThreadCount() {
|
|
18
|
+
return process.env.RSPRESS_SSG_WORKER_THREAD_COUNT ? Number.parseInt(process.env.RSPRESS_SSG_WORKER_THREAD_COUNT, 10) : void 0;
|
|
19
|
+
}
|
|
20
|
+
function getNumberOfThreads(pathnamesLength) {
|
|
21
|
+
const workerCount = SSGWorkerThreadCount();
|
|
22
|
+
if (void 0 !== workerCount) return workerCount;
|
|
23
|
+
const cpuCount = 'function' == typeof node_os.availableParallelism ? node_os.availableParallelism() : node_os.cpus().length;
|
|
24
|
+
return inferNumberOfThreads({
|
|
25
|
+
pageCount: pathnamesLength,
|
|
26
|
+
cpuCount,
|
|
27
|
+
minPagesPerCpu: 100
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function SSGConcurrency() {
|
|
31
|
+
return process.env.RSPRESS_SSG_CONCURRENCY ? Number.parseInt(process.env.RSPRESS_SSG_CONCURRENCY, 10) : 32;
|
|
32
|
+
}
|
|
33
|
+
export { SSGConcurrency, SSGWorkerThreadRecyclerMaxMemory, SSGWorkerThreadTaskSize, getNumberOfThreads };
|
|
@@ -1,3 +1,3 @@
|
|
|
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 emitLlmsTxt(config: UserConfig, routeService: RouteService, emitAsset: (assetName: string, content: string | Buffer) => void, mdContents: Map<string, string>): Promise<void>;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { getSidebarDataGroup } from "../../../4669.12208c6a.js";
|
|
2
|
+
import { matchPath } from "../../../5313.6594aba0.js";
|
|
3
|
+
import { generateLlmsTxt, generateLlmsFullTxt } from "./llmsTxt.js";
|
|
4
|
+
async function emitLlmsTxt(config, routeService, emitAsset, mdContents) {
|
|
5
|
+
const base = config.base ?? '/';
|
|
6
|
+
const locales = config.themeConfig?.locales;
|
|
7
|
+
const isMultiLang = locales && locales.length > 0;
|
|
8
|
+
const nav = isMultiLang ? locales.filter((i)=>Boolean(i.nav)).map((i)=>({
|
|
9
|
+
nav: i.nav,
|
|
10
|
+
lang: i.lang
|
|
11
|
+
})) : [
|
|
12
|
+
{
|
|
13
|
+
nav: config.themeConfig?.nav,
|
|
14
|
+
lang: config.lang ?? ''
|
|
15
|
+
}
|
|
16
|
+
];
|
|
17
|
+
const sidebars = isMultiLang ? locales.map((i)=>i.sidebar) : [
|
|
18
|
+
config.themeConfig?.sidebar
|
|
19
|
+
];
|
|
20
|
+
const sidebar = sidebars.reduce((prev, curr)=>{
|
|
21
|
+
Object.assign(prev, curr);
|
|
22
|
+
return prev;
|
|
23
|
+
}, {});
|
|
24
|
+
const noVersionNav = Array.isArray(nav) ? nav.map((i)=>{
|
|
25
|
+
const nav = i.nav.default || i.nav;
|
|
26
|
+
const lang = i.lang;
|
|
27
|
+
return nav.map((i)=>({
|
|
28
|
+
...i,
|
|
29
|
+
lang
|
|
30
|
+
}));
|
|
31
|
+
}).flat().filter((i)=>i.activeMatch || i.link) : [];
|
|
32
|
+
const defaultLang = routeService.getDefaultLang();
|
|
33
|
+
await Promise.all(routeService.getLangs().map(async (lang)=>{
|
|
34
|
+
const navList = noVersionNav.filter((i)=>i.lang === lang);
|
|
35
|
+
const routeGroups = new Array(navList.length).fill(0).map(()=>[]);
|
|
36
|
+
const others = [];
|
|
37
|
+
routeService.getRoutes().forEach((routeMeta)=>{
|
|
38
|
+
if (routeMeta.lang !== lang) return;
|
|
39
|
+
const { routePath } = routeMeta;
|
|
40
|
+
for(let i = 0; i < routeGroups.length; i++){
|
|
41
|
+
const routeGroup = routeGroups[i];
|
|
42
|
+
const navItem = navList[i];
|
|
43
|
+
if (lang === navItem.lang && new RegExp(navItem.activeMatch ?? navItem.link).test(routePath)) return void routeGroup.push(routePath);
|
|
44
|
+
}
|
|
45
|
+
others.push(routePath);
|
|
46
|
+
});
|
|
47
|
+
for (const routeGroup of routeGroups)organizeBySidebar(sidebar, routeGroup);
|
|
48
|
+
const llmsTxtContent = await generateLlmsTxt(routeGroups, others, navList, config.title, config.description, config.base, routeService);
|
|
49
|
+
const llmsFullTxtContent = generateLlmsFullTxt(routeGroups, navList, others, base, mdContents);
|
|
50
|
+
const prefix = defaultLang === lang ? '' : `${lang}/`;
|
|
51
|
+
emitAsset(`${prefix}llms.txt`, llmsTxtContent);
|
|
52
|
+
emitAsset(`${prefix}llms-full.txt`, llmsFullTxtContent);
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
55
|
+
function flatSidebar(sidebar) {
|
|
56
|
+
if (!sidebar) return [];
|
|
57
|
+
return sidebar.flatMap((i)=>{
|
|
58
|
+
if ('string' == typeof i) return i;
|
|
59
|
+
if ('link' in i && 'string' == typeof i.link) return [
|
|
60
|
+
i.link,
|
|
61
|
+
...flatSidebar(i?.items ?? [])
|
|
62
|
+
];
|
|
63
|
+
if ('items' in i && Array.isArray(i.items)) return flatSidebar(i.items);
|
|
64
|
+
}).filter(Boolean);
|
|
65
|
+
}
|
|
66
|
+
function organizeBySidebar(sidebar, routes) {
|
|
67
|
+
if (0 === routes.length) return;
|
|
68
|
+
const route = routes[0];
|
|
69
|
+
const currSidebar = getSidebarDataGroup(sidebar, route);
|
|
70
|
+
if (0 === currSidebar.length) return;
|
|
71
|
+
const orderList = flatSidebar(currSidebar);
|
|
72
|
+
routes.sort((a, b)=>{
|
|
73
|
+
let aIndex = orderList.findIndex((order)=>matchPath(order, a));
|
|
74
|
+
if (-1 === aIndex) aIndex = Number.MAX_SAFE_INTEGER;
|
|
75
|
+
let bIndex = orderList.findIndex((order)=>matchPath(order, b));
|
|
76
|
+
if (-1 === bIndex) bIndex = Number.MAX_SAFE_INTEGER;
|
|
77
|
+
return aIndex - bIndex;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
export { emitLlmsTxt };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type NavItemWithLink } from '@rspress/shared';
|
|
2
|
-
import type { RouteService } from '../../route/RouteService';
|
|
2
|
+
import type { RouteService } from '../../route/RouteService.js';
|
|
3
3
|
declare function routePathToMdPath(routePath: string, base: string): string;
|
|
4
4
|
declare function generateLlmsTxt(routeGroups: string[][], others: string[], navList: {
|
|
5
5
|
text: string;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { normalizeHref, withBase } from "../../../4669.12208c6a.js";
|
|
2
|
+
import { extractInfoFromFrontmatterWithAbsolutePath } from "../../auto-nav-sidebar/utils.js";
|
|
3
|
+
function routePathToMdPath(routePath, base) {
|
|
4
|
+
let url = routePath;
|
|
5
|
+
url = normalizeHref(url, false);
|
|
6
|
+
url = url.replace(/\.html$/, '.md');
|
|
7
|
+
return withBase(url, base);
|
|
8
|
+
}
|
|
9
|
+
async function generateLlmsTxt(routeGroups, others, navList, title, description, base, routeService) {
|
|
10
|
+
const lines = [];
|
|
11
|
+
const summary = `# ${title}${description ? `\n\n> ${description}` : ''}`;
|
|
12
|
+
async function genH2Part(nav, routes) {
|
|
13
|
+
const lines = [];
|
|
14
|
+
const { text } = nav;
|
|
15
|
+
if (0 === routes.length) return lines;
|
|
16
|
+
const routeLines = (await Promise.all(routes.map(async (route)=>{
|
|
17
|
+
const routePage = routeService.getRoutePageByRoutePath(route);
|
|
18
|
+
const { lang, routePath, absolutePath } = routePage.routeMeta;
|
|
19
|
+
if ('/' === routePath || routePath === `/${lang}/`) return;
|
|
20
|
+
const { title, description } = await extractInfoFromFrontmatterWithAbsolutePath(absolutePath, routeService.getDocsDir());
|
|
21
|
+
return `- [${title}](${routePathToMdPath(routePath, base)})${description ? `: ${description}` : ''}`;
|
|
22
|
+
}))).filter((i)=>Boolean(i));
|
|
23
|
+
if (routeLines.length > 0) {
|
|
24
|
+
const title = text;
|
|
25
|
+
lines.push(`\n## ${title}\n`);
|
|
26
|
+
lines.push(...routeLines);
|
|
27
|
+
}
|
|
28
|
+
return lines;
|
|
29
|
+
}
|
|
30
|
+
const h2Parts = await Promise.all(navList.map(async (nav, i)=>{
|
|
31
|
+
const routes = routeGroups[i];
|
|
32
|
+
const h2Part = await genH2Part(nav, routes);
|
|
33
|
+
return h2Part;
|
|
34
|
+
}));
|
|
35
|
+
lines.push(...h2Parts.flat());
|
|
36
|
+
const otherLines = await genH2Part({
|
|
37
|
+
text: 'Others'
|
|
38
|
+
}, others);
|
|
39
|
+
lines.push(...otherLines);
|
|
40
|
+
const llmsTxt = `${summary}\n${lines.join('\n')}`;
|
|
41
|
+
return llmsTxt;
|
|
42
|
+
}
|
|
43
|
+
function generateLlmsFullTxt(routeGroups, navList, others, base, mdContents) {
|
|
44
|
+
const lines = [];
|
|
45
|
+
for(let i = 0; i < navList.length; i++){
|
|
46
|
+
const routeGroup = routeGroups[i];
|
|
47
|
+
if (0 !== routeGroup.length) for (const routePath of routeGroup){
|
|
48
|
+
lines.push(`---
|
|
49
|
+
url: ${routePathToMdPath(routePath, base)}
|
|
50
|
+
---
|
|
51
|
+
`);
|
|
52
|
+
lines.push(mdContents.get(routePath) ?? '');
|
|
53
|
+
lines.push('\n');
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
for (const routePath of others){
|
|
57
|
+
lines.push(`---
|
|
58
|
+
url: ${routePathToMdPath(routePath, base)}
|
|
59
|
+
---
|
|
60
|
+
`);
|
|
61
|
+
lines.push(mdContents.get(routePath) ?? '');
|
|
62
|
+
lines.push('\n');
|
|
63
|
+
}
|
|
64
|
+
return lines.join('\n');
|
|
65
|
+
}
|
|
66
|
+
export { generateLlmsFullTxt, generateLlmsTxt, routePathToMdPath };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { renderToMarkdownString } from './render';
|
|
1
|
+
export { renderToMarkdownString } from './render.js';
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { unified, remark_gfm, remark_mdx, remark_stringify } from "../mdx/loader.e1578c62.js";
|
|
2
|
+
function remarkSplitMdx(options = {}) {
|
|
3
|
+
return (tree)=>{
|
|
4
|
+
const newChildren = [];
|
|
5
|
+
const importMap = buildImportMap(tree);
|
|
6
|
+
for (const node of tree.children){
|
|
7
|
+
if ('mdxjsEsm' === node.type) {
|
|
8
|
+
newChildren.push(node);
|
|
9
|
+
continue;
|
|
10
|
+
}
|
|
11
|
+
if ('mdxJsxFlowElement' === node.type || 'mdxJsxTextElement' === node.type) {
|
|
12
|
+
const componentName = node.name;
|
|
13
|
+
const shouldKeep = shouldKeepJsxElement(componentName, importMap, options);
|
|
14
|
+
if (shouldKeep) newChildren.push(node);
|
|
15
|
+
else newChildren.push(buildMdxFlowExpressionFragment(node));
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
const hasJsxChildren = node.children?.some((child)=>'mdxJsxFlowElement' === child.type || 'mdxJsxTextElement' === child.type);
|
|
19
|
+
if (hasJsxChildren) {
|
|
20
|
+
const processedChildren = processMixedContent(node, node.children || [], importMap, options);
|
|
21
|
+
newChildren.push({
|
|
22
|
+
type: 'mdxJsxFlowElement',
|
|
23
|
+
name: null,
|
|
24
|
+
attributes: [],
|
|
25
|
+
children: processedChildren
|
|
26
|
+
});
|
|
27
|
+
} else {
|
|
28
|
+
const fragment = buildMdxFlowExpressionFragment(node);
|
|
29
|
+
newChildren.push(fragment);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
tree.children = newChildren;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function processMixedContent(parentNode, children, importMap, options) {
|
|
36
|
+
const result = [];
|
|
37
|
+
let textBuffer = [];
|
|
38
|
+
const getPrefix = ()=>{
|
|
39
|
+
if ('heading' === parentNode.type) {
|
|
40
|
+
const depth = parentNode.depth || 1;
|
|
41
|
+
return `${'#'.repeat(depth)} `;
|
|
42
|
+
}
|
|
43
|
+
return '';
|
|
44
|
+
};
|
|
45
|
+
const prefix = getPrefix();
|
|
46
|
+
let prefixAdded = false;
|
|
47
|
+
const flushTextBuffer = ()=>{
|
|
48
|
+
if (textBuffer.length > 0) {
|
|
49
|
+
let combined = textBuffer.join('');
|
|
50
|
+
if (!prefixAdded && prefix) {
|
|
51
|
+
combined = prefix + combined;
|
|
52
|
+
prefixAdded = true;
|
|
53
|
+
}
|
|
54
|
+
if (combined) {
|
|
55
|
+
const stringified = JSON.stringify(combined);
|
|
56
|
+
result.push({
|
|
57
|
+
type: 'mdxTextExpression',
|
|
58
|
+
value: stringified,
|
|
59
|
+
data: {
|
|
60
|
+
estree: {
|
|
61
|
+
type: 'Program',
|
|
62
|
+
body: [
|
|
63
|
+
{
|
|
64
|
+
type: 'ExpressionStatement',
|
|
65
|
+
expression: {
|
|
66
|
+
type: 'Literal',
|
|
67
|
+
value: combined,
|
|
68
|
+
raw: stringified
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
],
|
|
72
|
+
sourceType: 'module'
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
textBuffer = [];
|
|
78
|
+
} else if (!prefixAdded && prefix) {
|
|
79
|
+
const trimmedPrefix = prefix.trimEnd();
|
|
80
|
+
const stringified = JSON.stringify(trimmedPrefix);
|
|
81
|
+
result.push({
|
|
82
|
+
type: 'mdxTextExpression',
|
|
83
|
+
value: stringified,
|
|
84
|
+
data: {
|
|
85
|
+
estree: {
|
|
86
|
+
type: 'Program',
|
|
87
|
+
body: [
|
|
88
|
+
{
|
|
89
|
+
type: 'ExpressionStatement',
|
|
90
|
+
expression: {
|
|
91
|
+
type: 'Literal',
|
|
92
|
+
value: trimmedPrefix,
|
|
93
|
+
raw: stringified
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
],
|
|
97
|
+
sourceType: 'module'
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
prefixAdded = true;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
for (const child of children)if ('mdxJsxFlowElement' === child.type || 'mdxJsxTextElement' === child.type) {
|
|
105
|
+
flushTextBuffer();
|
|
106
|
+
const componentName = child.name;
|
|
107
|
+
const shouldKeep = shouldKeepJsxElement(componentName, importMap, options);
|
|
108
|
+
if (shouldKeep) result.push(child);
|
|
109
|
+
else {
|
|
110
|
+
const fragment = buildMdxFlowExpressionFragment(child);
|
|
111
|
+
result.push(fragment);
|
|
112
|
+
}
|
|
113
|
+
} else if ('text' === child.type) textBuffer.push(child.value || '');
|
|
114
|
+
else {
|
|
115
|
+
const serialized = serializeNodeToMarkdown(child);
|
|
116
|
+
if (serialized) textBuffer.push(serialized);
|
|
117
|
+
}
|
|
118
|
+
flushTextBuffer();
|
|
119
|
+
return result;
|
|
120
|
+
}
|
|
121
|
+
function buildMdxFlowExpressionFragment(node) {
|
|
122
|
+
const textContent = serializeNodeToMarkdown(node);
|
|
123
|
+
const stringified = JSON.stringify(textContent);
|
|
124
|
+
const fragment = {
|
|
125
|
+
type: 'mdxFlowExpression',
|
|
126
|
+
value: stringified,
|
|
127
|
+
data: {
|
|
128
|
+
estree: {
|
|
129
|
+
type: 'Program',
|
|
130
|
+
body: [
|
|
131
|
+
{
|
|
132
|
+
type: 'ExpressionStatement',
|
|
133
|
+
expression: {
|
|
134
|
+
type: 'Literal',
|
|
135
|
+
value: textContent,
|
|
136
|
+
raw: stringified
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
],
|
|
140
|
+
sourceType: 'module'
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
return fragment;
|
|
145
|
+
}
|
|
146
|
+
const processor = unified().use(remark_mdx).use(remark_gfm).use(remark_stringify, {
|
|
147
|
+
bullet: '-',
|
|
148
|
+
emphasis: '_',
|
|
149
|
+
fences: true,
|
|
150
|
+
incrementListMarker: true
|
|
151
|
+
});
|
|
152
|
+
function serializeNodeToMarkdown(node) {
|
|
153
|
+
const tempRoot = {
|
|
154
|
+
type: 'root',
|
|
155
|
+
children: [
|
|
156
|
+
node
|
|
157
|
+
]
|
|
158
|
+
};
|
|
159
|
+
const result = processor.stringify(tempRoot);
|
|
160
|
+
return result;
|
|
161
|
+
}
|
|
162
|
+
function buildImportMap(tree) {
|
|
163
|
+
const importMap = new Map();
|
|
164
|
+
for (const node of tree.children)if ('mdxjsEsm' === node.type && node.data?.estree) {
|
|
165
|
+
const estree = node.data.estree;
|
|
166
|
+
for (const statement of estree.body)if ('ImportDeclaration' === statement.type) {
|
|
167
|
+
const source = statement.source.value;
|
|
168
|
+
for (const specifier of statement.specifiers){
|
|
169
|
+
let localName = null;
|
|
170
|
+
if ('ImportDefaultSpecifier' === specifier.type) localName = specifier.local.name;
|
|
171
|
+
else if ('ImportSpecifier' === specifier.type) localName = specifier.local.name;
|
|
172
|
+
else if ('ImportNamespaceSpecifier' === specifier.type) localName = specifier.local.name;
|
|
173
|
+
if (localName) importMap.set(localName, source);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return importMap;
|
|
178
|
+
}
|
|
179
|
+
function shouldKeepJsxElement(componentName, importMap, options) {
|
|
180
|
+
if (!componentName) return true;
|
|
181
|
+
const { includes, excludes } = options;
|
|
182
|
+
if (!includes && !excludes) return true;
|
|
183
|
+
const importSource = importMap.get(componentName);
|
|
184
|
+
if (importSource?.endsWith('.mdx')) return true;
|
|
185
|
+
if (excludes) {
|
|
186
|
+
for (const [excludeSpecifiers, excludeSource] of excludes)if (excludeSpecifiers.includes(componentName)) {
|
|
187
|
+
if (!importSource || importSource === excludeSource) return false;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if (includes) {
|
|
191
|
+
let matchesAnyRule = false;
|
|
192
|
+
for (const [includeSpecifiers, includeSource] of includes)if (includeSpecifiers.includes(componentName)) {
|
|
193
|
+
if (!importSource || importSource === includeSource) {
|
|
194
|
+
matchesAnyRule = true;
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (!matchesAnyRule) return false;
|
|
199
|
+
}
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
202
|
+
export { remarkSplitMdx };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { pathToFileURL, createHead } from "../../5485.2a0273cf.js";
|
|
2
|
+
import { logger, picocolors } from "../../6289.c67fe0d5.js";
|
|
3
|
+
import { hintSSGFailed } from "../logger/hint.js";
|
|
4
|
+
async function renderPage(route, ssrBundlePath) {
|
|
5
|
+
let render;
|
|
6
|
+
try {
|
|
7
|
+
const { default: ssrExports } = await import(pathToFileURL(ssrBundlePath).toString());
|
|
8
|
+
render = await ssrExports.render;
|
|
9
|
+
} catch (e) {
|
|
10
|
+
if (e instanceof Error) {
|
|
11
|
+
logger.error(`Failed to load SSG bundle: ${picocolors.yellow(ssrBundlePath)}: ${e.message}`);
|
|
12
|
+
logger.debug(e);
|
|
13
|
+
hintSSGFailed();
|
|
14
|
+
}
|
|
15
|
+
throw e;
|
|
16
|
+
}
|
|
17
|
+
const head = createHead();
|
|
18
|
+
const { routePath, absolutePath } = route;
|
|
19
|
+
let appMd = '';
|
|
20
|
+
if (render) try {
|
|
21
|
+
({ appMd } = await render(routePath, head));
|
|
22
|
+
} catch (e) {
|
|
23
|
+
if (e instanceof Error) {
|
|
24
|
+
logger.error(`Page "${picocolors.yellow(routePath)}" SSG-MD rendering failed.
|
|
25
|
+
${absolutePath ? picocolors.gray(` File: ${absolutePath}\n`) : ''} ${picocolors.gray(e.toString())}`);
|
|
26
|
+
throw e;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return appMd;
|
|
30
|
+
}
|
|
31
|
+
export { renderPage };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { RouteService } from '../route/RouteService';
|
|
1
|
+
import type { RouteService } from '../route/RouteService.js';
|
|
2
2
|
export declare function renderPages(routeService: RouteService, ssrBundlePath: string, emitAsset: (assetName: string, content: string | Buffer) => void): Promise<Map<string, string>>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { logger, picocolors } from "../../6289.c67fe0d5.js";
|
|
2
|
+
import { pMap } from "../../5485.2a0273cf.js";
|
|
3
|
+
import { renderPage } from "./renderPage.js";
|
|
4
|
+
import { SSGConcurrency } from "../ssg/ssgEnv.js";
|
|
5
|
+
const routePage2MdFilename = (routePath)=>{
|
|
6
|
+
let fileName = routePath;
|
|
7
|
+
fileName = fileName.endsWith('/') ? `${routePath}index.md` : `${routePath}.md`;
|
|
8
|
+
return fileName.replace(/^\/+/, '');
|
|
9
|
+
};
|
|
10
|
+
async function renderPages(routeService, ssrBundlePath, emitAsset) {
|
|
11
|
+
logger.info('Rendering md pages...');
|
|
12
|
+
const startTime = Date.now();
|
|
13
|
+
const result = new Map();
|
|
14
|
+
const routes = routeService.getRoutes();
|
|
15
|
+
await pMap(routes, async (route)=>{
|
|
16
|
+
const html = await renderPage(route, ssrBundlePath);
|
|
17
|
+
const fileName = routePage2MdFilename(route.routePath);
|
|
18
|
+
emitAsset(fileName, html);
|
|
19
|
+
result.set(route.routePath, html);
|
|
20
|
+
}, {
|
|
21
|
+
concurrency: SSGConcurrency()
|
|
22
|
+
});
|
|
23
|
+
const totalTime = Date.now() - startTime;
|
|
24
|
+
logger.success(`Markdown rendered in ${picocolors.yellow(totalTime)} ms.`);
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
export { 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 rsbuildPluginSSGMD: ({ routeService, config, }: {
|
|
5
5
|
routeService: RouteService;
|
|
6
6
|
config: UserConfig;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { writeFile, mkdir, rm, join } from "../../6289.c67fe0d5.js";
|
|
2
|
+
import { isDebugMode } from "../../4669.12208c6a.js";
|
|
3
|
+
import { NODE_SSG_MD_BUNDLE_FOLDER, NODE_SSG_MD_BUNDLE_NAME } from "../constants.js";
|
|
4
|
+
import { renderPages } from "./renderPages.js";
|
|
5
|
+
import { emitLlmsTxt } from "./llms/emitLlmsTxt.js";
|
|
6
|
+
const rsbuildPluginSSGMD = ({ routeService, config })=>({
|
|
7
|
+
name: 'rspress-inner-rsbuild-plugin-ssg',
|
|
8
|
+
async setup (api) {
|
|
9
|
+
api.onBeforeBuild(()=>{
|
|
10
|
+
let hasError = false;
|
|
11
|
+
api.processAssets({
|
|
12
|
+
stage: 'optimize-transfer',
|
|
13
|
+
environments: [
|
|
14
|
+
'node_md'
|
|
15
|
+
]
|
|
16
|
+
}, async ({ assets, compilation, environment, compiler })=>{
|
|
17
|
+
if (compilation.errors.length > 0) {
|
|
18
|
+
hasError = true;
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (hasError) return;
|
|
22
|
+
const emitAsset = (assetName, content)=>{
|
|
23
|
+
compilation.emitAsset(assetName, new compiler.webpack.sources.RawSource(content));
|
|
24
|
+
};
|
|
25
|
+
const distPath = environment.distPath;
|
|
26
|
+
const ssgFolderPath = join(distPath, NODE_SSG_MD_BUNDLE_FOLDER);
|
|
27
|
+
const mainCjsAbsolutePath = join(ssgFolderPath, NODE_SSG_MD_BUNDLE_NAME);
|
|
28
|
+
await mkdir(ssgFolderPath, {
|
|
29
|
+
recursive: true
|
|
30
|
+
});
|
|
31
|
+
await Promise.all(Object.entries(assets).map(async ([assetName, assetSource])=>{
|
|
32
|
+
if (assetName.startsWith(`${NODE_SSG_MD_BUNDLE_FOLDER}/`)) {
|
|
33
|
+
const fileAbsolutePath = join(distPath, assetName);
|
|
34
|
+
await writeFile(fileAbsolutePath, assetSource.source().toString());
|
|
35
|
+
compilation.deleteAsset(assetName);
|
|
36
|
+
}
|
|
37
|
+
}));
|
|
38
|
+
const mdContents = await renderPages(routeService, mainCjsAbsolutePath, emitAsset);
|
|
39
|
+
await emitLlmsTxt(config, routeService, emitAsset, mdContents);
|
|
40
|
+
if (!isDebugMode()) await rm(ssgFolderPath, {
|
|
41
|
+
recursive: true
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
export { rsbuildPluginSSGMD };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { node_path, logger, promises } from "../../6289.c67fe0d5.js";
|
|
2
|
+
import { createError } from "./error.js";
|
|
3
|
+
function normalizePath(filePath) {
|
|
4
|
+
return filePath.split(node_path.sep).join('/');
|
|
5
|
+
}
|
|
6
|
+
async function getAllMarkdownFilesFrom(dirPath) {
|
|
7
|
+
const files = await promises.readdir(dirPath, {
|
|
8
|
+
withFileTypes: true
|
|
9
|
+
});
|
|
10
|
+
const allFiles = [];
|
|
11
|
+
for (const file of files){
|
|
12
|
+
const fullPath = node_path.join(dirPath, file.name);
|
|
13
|
+
if (file.isDirectory()) {
|
|
14
|
+
const nestedFiles = await getAllMarkdownFilesFrom(fullPath);
|
|
15
|
+
allFiles.push(...nestedFiles);
|
|
16
|
+
} else if ([
|
|
17
|
+
'.md',
|
|
18
|
+
'.mdx'
|
|
19
|
+
].includes(node_path.extname(file.name))) allFiles.push(fullPath);
|
|
20
|
+
}
|
|
21
|
+
return allFiles;
|
|
22
|
+
}
|
|
23
|
+
async function collectModuleFiles(contentPath, lang, includedDir, excludedDirs, fileLangMap) {
|
|
24
|
+
const langDirPath = node_path.join(contentPath, lang);
|
|
25
|
+
const langModuleDir = node_path.join(langDirPath, includedDir);
|
|
26
|
+
try {
|
|
27
|
+
const moduleDirStats = await promises.stat(langModuleDir);
|
|
28
|
+
if (!moduleDirStats.isDirectory()) return fileLangMap;
|
|
29
|
+
const files = await getAllMarkdownFilesFrom(langModuleDir);
|
|
30
|
+
for (const file of files){
|
|
31
|
+
const relativePath = normalizePath(node_path.relative(langDirPath, file));
|
|
32
|
+
if (excludedDirs.some((excludedDir)=>{
|
|
33
|
+
const isFilePath = /\.(md|mdx)$/.test(excludedDir);
|
|
34
|
+
return relativePath.includes(excludedDir + (isFilePath ? '' : '/'));
|
|
35
|
+
})) continue;
|
|
36
|
+
const baseName = relativePath;
|
|
37
|
+
if (!fileLangMap[baseName]) fileLangMap[baseName] = new Set();
|
|
38
|
+
fileLangMap[baseName].add(lang);
|
|
39
|
+
}
|
|
40
|
+
} catch (e) {
|
|
41
|
+
logger.error(e);
|
|
42
|
+
throw createError(`Failed to access directory: ${normalizePath(langModuleDir)}`);
|
|
43
|
+
}
|
|
44
|
+
return fileLangMap;
|
|
45
|
+
}
|
|
46
|
+
async function checkLanguageParity(config) {
|
|
47
|
+
if (!config?.languageParity || false === config.languageParity.enabled) return;
|
|
48
|
+
logger.info('Checking language parity...');
|
|
49
|
+
const contentPath = node_path.resolve(config.root);
|
|
50
|
+
const includedDirs = config.languageParity.include?.length ? config.languageParity.include : [
|
|
51
|
+
''
|
|
52
|
+
];
|
|
53
|
+
const excludedDirs = config.languageParity.exclude ?? [];
|
|
54
|
+
const supportedLanguages = (config.locales ?? config.themeConfig?.locales)?.map((locale)=>locale.lang) || [];
|
|
55
|
+
if (!supportedLanguages.length) return void logger.error('No supported languages found in the configuration.');
|
|
56
|
+
const missingLanguagesFile = [];
|
|
57
|
+
try {
|
|
58
|
+
for (const includedDir of includedDirs){
|
|
59
|
+
if (excludedDirs.some((excludedDir)=>excludedDir === includedDir)) continue;
|
|
60
|
+
const curFileLangMap = {};
|
|
61
|
+
for (const lang of supportedLanguages)await collectModuleFiles(contentPath, lang, includedDir, excludedDirs, curFileLangMap);
|
|
62
|
+
for (const [baseName, langs] of Object.entries(curFileLangMap)){
|
|
63
|
+
const missingLangs = supportedLanguages.filter((lang)=>!langs.has(lang));
|
|
64
|
+
missingLangs.forEach((lang)=>{
|
|
65
|
+
const missingPath = node_path.join(lang, baseName);
|
|
66
|
+
missingLanguagesFile.push(missingPath);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (missingLanguagesFile.length > 0) throw createError(`Check language parity failed! Missing content:\n${missingLanguagesFile.map((file)=>` - ${normalizePath(file)}`).join('\n')}`);
|
|
71
|
+
logger.success('Language parity checked successfully.');
|
|
72
|
+
} catch (err) {
|
|
73
|
+
logger.error('Error during language parity check: \n', err);
|
|
74
|
+
throw err;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
export { checkLanguageParity };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates an Error with a truncated stack trace.
|
|
3
|
+
* Only keeps the first N lines of the stack trace to reduce noise.
|
|
4
|
+
*
|
|
5
|
+
* @param message - The error message
|
|
6
|
+
* @param maxStackLines - Maximum number of stack trace lines to keep (default: 5)
|
|
7
|
+
* @returns An Error object with truncated stack
|
|
8
|
+
*/
|
|
9
|
+
export declare function createError(message: string, maxStackLines?: number): Error;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
function createError(message, maxStackLines = 5) {
|
|
2
|
+
const error = new Error(message);
|
|
3
|
+
if (error.stack) {
|
|
4
|
+
const lines = error.stack.split('\n');
|
|
5
|
+
if (lines.length > maxStackLines + 1) error.stack = `${lines.slice(0, maxStackLines + 1).join('\n')}\n ... (truncated)`;
|
|
6
|
+
}
|
|
7
|
+
return error;
|
|
8
|
+
}
|
|
9
|
+
export { createError };
|