@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.
Files changed (307) hide show
  1. package/bin/rspress.js +1 -1
  2. package/dist/0~7675.723d12b2.js +1794 -0
  3. package/dist/3521.56e42d70.js +56 -0
  4. package/dist/4669.12208c6a.js +2 -0
  5. package/dist/5485.077f14ff.js +98 -0
  6. package/dist/6289.c67fe0d5.js +5 -0
  7. package/dist/8813.9da1f210.js +2 -0
  8. package/dist/9643.f109822d.js +5 -0
  9. package/dist/_private/react/render.js +17 -4
  10. package/dist/cli/config/index.js +4 -0
  11. package/dist/cli/config/loadConfigFile.js +30 -0
  12. package/dist/cli/index.cb89dbd1.js +3 -0
  13. package/dist/cli/index.js +122 -0
  14. package/dist/eject-theme/components/Badge/index.scss +1 -0
  15. package/dist/eject-theme/components/Banner/index.tsx +6 -5
  16. package/dist/eject-theme/components/Callout/index.scss +0 -2
  17. package/dist/eject-theme/components/Callout/index.tsx +8 -2
  18. package/dist/eject-theme/components/CodeBlock/index.scss +12 -18
  19. package/dist/eject-theme/components/CodeBlock/index.tsx +10 -1
  20. package/dist/eject-theme/components/CodeBlockRuntime/index.tsx +50 -11
  21. package/dist/eject-theme/components/CodeButtonGroup/CopyCodeButton.tsx +1 -3
  22. package/dist/eject-theme/components/CodeButtonGroup/index.scss +5 -1
  23. package/dist/eject-theme/components/CodeButtonGroup/index.tsx +1 -3
  24. package/dist/eject-theme/components/DocContent/doc.scss +27 -7
  25. package/dist/eject-theme/components/DocContent/docComponents/pre.tsx +2 -1
  26. package/dist/eject-theme/components/DocContent/docComponents/table.tsx +10 -4
  27. package/dist/eject-theme/components/DocContent/index.tsx +21 -4
  28. package/dist/eject-theme/components/DocFooter/index.tsx +1 -6
  29. package/dist/eject-theme/components/{DocContent/FallbackHeading.tsx → FallbackHeading/index.tsx} +20 -11
  30. package/dist/eject-theme/components/HoverGroup/index.scss +1 -1
  31. package/dist/eject-theme/components/LastUpdated/index.tsx +8 -1
  32. package/dist/eject-theme/components/Link/index.tsx +22 -6
  33. package/dist/eject-theme/components/Nav/NavMenu.tsx +2 -3
  34. package/dist/eject-theme/components/NavHamburger/index.tsx +3 -4
  35. package/dist/eject-theme/components/NavScreen/NavScreenLangs.scss +6 -0
  36. package/dist/eject-theme/components/NavScreen/NavScreenLangs.tsx +23 -9
  37. package/dist/eject-theme/components/NavScreen/NavScreenMenuItem.tsx +2 -3
  38. package/dist/eject-theme/components/NavScreen/NavScreenVersions.scss +6 -0
  39. package/dist/eject-theme/components/NavScreen/NavScreenVersions.tsx +22 -9
  40. package/dist/eject-theme/components/Overview/index.tsx +7 -8
  41. package/dist/eject-theme/components/{Overview/OverviewGroup.scss → OverviewGroup/index.scss} +66 -12
  42. package/dist/eject-theme/components/{Overview/OverviewGroup.tsx → OverviewGroup/index.tsx} +51 -5
  43. package/dist/eject-theme/components/PackageManagerTabs/index.tsx +12 -0
  44. package/dist/eject-theme/components/PrevNextPage/index.tsx +6 -3
  45. package/dist/eject-theme/components/Root/index.tsx +58 -0
  46. package/dist/eject-theme/components/Search/NoSearchResult.tsx +2 -3
  47. package/dist/eject-theme/components/Search/SearchButton.tsx +3 -4
  48. package/dist/eject-theme/components/Search/SearchPanel.tsx +12 -7
  49. package/dist/eject-theme/components/Search/SuggestItem.tsx +15 -12
  50. package/dist/eject-theme/components/Search/logic/util.test.ts +1 -1
  51. package/dist/eject-theme/components/Sidebar/SidebarGroup.tsx +2 -3
  52. package/dist/eject-theme/components/Sidebar/SidebarItem.tsx +1 -0
  53. package/dist/eject-theme/components/SidebarMenu/index.tsx +4 -4
  54. package/dist/eject-theme/components/SocialLinks/index.tsx +2 -3
  55. package/dist/eject-theme/components/SourceCode/index.tsx +6 -4
  56. package/dist/eject-theme/components/SwitchAppearance/index.tsx +3 -5
  57. package/dist/eject-theme/components/Tabs/index.scss +31 -26
  58. package/dist/eject-theme/components/Tabs/index.tsx +16 -0
  59. package/dist/eject-theme/components/Tag/index.tsx +84 -5
  60. package/dist/eject-theme/components/Toc/TocItem.scss +3 -3
  61. package/dist/eject-theme/components/Toc/TocItem.tsx +1 -0
  62. package/dist/index.d.ts +6 -6
  63. package/dist/index.js +16 -3134
  64. package/dist/node/PluginDriver.d.ts +1 -1
  65. package/dist/node/PluginDriver.js +142 -0
  66. package/dist/node/auto-nav-sidebar/index.js +44 -0
  67. package/dist/node/auto-nav-sidebar/locales.js +26 -0
  68. package/dist/node/auto-nav-sidebar/normalize.js +230 -0
  69. package/dist/node/auto-nav-sidebar/utils.js +68 -0
  70. package/dist/node/auto-nav-sidebar/walk.js +67 -0
  71. package/dist/node/build.js +31 -0
  72. package/dist/node/constants.d.ts +2 -0
  73. package/dist/node/constants.js +34 -0
  74. package/dist/node/dev.js +32 -0
  75. package/dist/node/eject.js +111 -0
  76. package/dist/node/index.d.ts +5 -5
  77. package/dist/node/initRsbuild.d.ts +2 -2
  78. package/dist/node/initRsbuild.js +346 -0
  79. package/dist/node/last-updated/index.js +28 -0
  80. package/dist/node/logger/hint.d.ts +1 -1
  81. package/dist/node/logger/hint.js +85 -0
  82. package/dist/node/mdx/loader.d.ts +1 -1
  83. package/dist/node/mdx/loader.e1578c62.js +13 -0
  84. package/dist/{loader.js → node/mdx/loader.js} +4 -3
  85. package/dist/node/mdx/options.d.ts +2 -2
  86. package/dist/node/mdx/options.js +103 -0
  87. package/dist/node/mdx/processor.d.ts +2 -2
  88. package/dist/node/mdx/processor.js +71 -0
  89. package/dist/node/mdx/rehypePlugins/codeMeta.js +10 -0
  90. package/dist/node/mdx/rehypePlugins/headerAnchor.js +53 -0
  91. package/dist/node/mdx/rehypePlugins/shiki.js +34 -0
  92. package/dist/node/mdx/rehypePlugins/transformers/add-lang.js +15 -0
  93. package/dist/node/mdx/rehypePlugins/transformers/add-line-numbers.js +22 -0
  94. package/dist/node/mdx/rehypePlugins/transformers/add-title.js +24 -0
  95. package/dist/node/mdx/rehypePlugins/transformers/add-wrap-code.js +22 -0
  96. package/dist/node/mdx/rehypePlugins/transformers/index.d.ts +5 -5
  97. package/dist/node/mdx/rehypePlugins/transformers/index.js +5 -0
  98. package/dist/node/mdx/rehypePlugins/transformers/meta-highlight.js +41 -0
  99. package/dist/node/mdx/remarkPlugins/builtin.js +11 -0
  100. package/dist/node/mdx/remarkPlugins/containerSyntax.js +190 -0
  101. package/dist/node/mdx/remarkPlugins/fileCodeBlock.js +66 -0
  102. package/dist/node/mdx/remarkPlugins/image.js +67 -0
  103. package/dist/node/mdx/remarkPlugins/link.d.ts +1 -1
  104. package/dist/node/mdx/remarkPlugins/link.js +99 -0
  105. package/dist/node/mdx/remarkPlugins/toc.js +50 -0
  106. package/dist/node/mdx/types.d.ts +3 -3
  107. package/dist/node/medium-zoom/index.d.ts +1 -1
  108. package/dist/node/medium-zoom/index.js +14 -0
  109. package/dist/node/route/RoutePage.d.ts +1 -1
  110. package/dist/node/route/RoutePage.js +61 -0
  111. package/dist/node/route/RouteService.d.ts +1 -1
  112. package/dist/node/route/RouteService.js +177 -0
  113. package/dist/node/route/extractPageData.d.ts +1 -1
  114. package/dist/node/route/extractPageData.js +112 -0
  115. package/dist/node/route/normalizeRoutePath.js +54 -0
  116. package/dist/node/runtimeModule/DEFAULT_I18N_TEXT.d.ts +21 -0
  117. package/dist/node/runtimeModule/DEFAULT_I18N_TEXT.js +150 -0
  118. package/dist/node/runtimeModule/globalStyles.d.ts +1 -1
  119. package/dist/node/runtimeModule/globalStyles.js +12 -0
  120. package/dist/node/runtimeModule/globalUIComponents.d.ts +1 -1
  121. package/dist/node/runtimeModule/globalUIComponents.js +25 -0
  122. package/dist/node/runtimeModule/i18n.d.ts +2 -2
  123. package/dist/node/runtimeModule/i18n.js +83 -0
  124. package/dist/node/runtimeModule/pageData/createPageData.d.ts +1 -1
  125. package/dist/node/runtimeModule/pageData/createPageData.js +64 -0
  126. package/dist/node/runtimeModule/pageData/rsbuildPlugin.d.ts +1 -1
  127. package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +51 -0
  128. package/dist/node/runtimeModule/routeList.d.ts +1 -1
  129. package/dist/node/runtimeModule/routeList.js +7 -0
  130. package/dist/node/runtimeModule/searchHooks.d.ts +1 -1
  131. package/dist/node/runtimeModule/searchHooks.js +11 -0
  132. package/dist/node/runtimeModule/siteData/createSiteData.js +34 -0
  133. package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +94 -0
  134. package/dist/node/runtimeModule/siteData/rsbuildPlugin.d.ts +1 -1
  135. package/dist/node/runtimeModule/siteData/rsbuildPlugin.js +24 -0
  136. package/dist/node/runtimeModule/socialLinks.d.ts +1 -1
  137. package/dist/node/runtimeModule/socialLinks.js +8 -0
  138. package/dist/node/runtimeModule/types.d.ts +2 -2
  139. package/dist/node/serve.js +23 -0
  140. package/dist/node/ssg/renderHtmlTemplate.js +33 -0
  141. package/dist/node/ssg/renderPage.js +34 -0
  142. package/dist/node/ssg/renderPageWorker.474f9f73.js +2 -0
  143. package/dist/node/ssg/renderPageWorker.js +15 -0
  144. package/dist/node/ssg/renderPages.d.ts +1 -1
  145. package/dist/node/ssg/renderPages.js +105 -0
  146. package/dist/node/ssg/renderPages.js.LICENSE.txt +4 -0
  147. package/dist/node/ssg/rsbuildPluginCSR.d.ts +1 -1
  148. package/dist/node/ssg/rsbuildPluginCSR.js +27 -0
  149. package/dist/node/ssg/rsbuildPluginSSG.d.ts +1 -1
  150. package/dist/node/ssg/rsbuildPluginSSG.js +72 -0
  151. package/dist/node/ssg/ssgEnv.js +33 -0
  152. package/dist/node/ssg/ssgEnv.js.LICENSE.txt +5 -0
  153. package/dist/node/ssg-md/llms/emitLlmsTxt.d.ts +1 -1
  154. package/dist/node/ssg-md/llms/emitLlmsTxt.js +84 -0
  155. package/dist/node/ssg-md/llms/llmsTxt.d.ts +1 -1
  156. package/dist/node/ssg-md/llms/llmsTxt.js +66 -0
  157. package/dist/node/ssg-md/react/index.d.ts +1 -1
  158. package/dist/node/ssg-md/remarkSplitMdx.js +244 -0
  159. package/dist/node/ssg-md/renderPage.js +31 -0
  160. package/dist/node/ssg-md/renderPages.d.ts +1 -1
  161. package/dist/node/ssg-md/renderPages.js +27 -0
  162. package/dist/node/ssg-md/rsbuildPluginSSGMD.d.ts +1 -1
  163. package/dist/node/ssg-md/rsbuildPluginSSGMD.js +47 -0
  164. package/dist/node/utils/applyReplaceRules.js +6 -0
  165. package/dist/node/utils/checkLanguageParity.js +77 -0
  166. package/dist/node/utils/createHash.js +5 -0
  167. package/dist/node/utils/error.d.ts +9 -0
  168. package/dist/node/utils/error.js +10 -0
  169. package/dist/node/utils/escapeHeadingIds.js +5 -0
  170. package/dist/node/utils/flattenMdxContent.js +74 -0
  171. package/dist/node/utils/fs.js +14 -0
  172. package/dist/node/utils/getImportAstNode.js +63 -0
  173. package/dist/node/utils/getPageKey.js +6 -0
  174. package/dist/node/utils/getSocialIcons.js +32 -0
  175. package/dist/node/utils/index.d.ts +10 -9
  176. package/dist/node/utils/normalizePath.js +10 -0
  177. package/dist/node/utils/reactAlias.d.ts +2 -0
  178. package/dist/node/utils/reactAlias.js +83 -0
  179. package/dist/rslib-runtime.99091bf6.js +18 -0
  180. package/dist/runtime/App.js +2 -2
  181. package/dist/runtime/ClientApp.d.ts +1 -1
  182. package/dist/runtime/ClientApp.js +0 -4
  183. package/dist/runtime/initPageData.js +1 -1
  184. package/dist/runtime/ssrMdServerEntry.js +1 -1
  185. package/dist/runtime/ssrServerEntry.js +2 -1
  186. package/dist/runtime.72d450ac.js +1 -0
  187. package/dist/runtime.js +3 -2
  188. package/dist/shiki-transformers.d.ts +1 -1
  189. package/dist/shiki-transformers.js +6 -120
  190. package/dist/theme/assets/deprecated.js +18 -0
  191. package/dist/theme/assets/experimental.js +21 -0
  192. package/dist/theme/components/Badge/index.css +1 -0
  193. package/dist/theme/components/Banner/index.d.ts +1 -1
  194. package/dist/theme/components/Banner/index.js +4 -5
  195. package/dist/theme/components/Callout/index.css +0 -2
  196. package/dist/theme/components/Callout/index.js +5 -2
  197. package/dist/theme/components/CodeBlock/index.css +11 -21
  198. package/dist/theme/components/CodeBlock/index.js +5 -1
  199. package/dist/theme/components/CodeBlockRuntime/index.d.ts +1 -1
  200. package/dist/theme/components/CodeBlockRuntime/index.js +38 -8
  201. package/dist/theme/components/CodeButtonGroup/CopyCodeButton.js +3 -5
  202. package/dist/theme/components/CodeButtonGroup/index.css +5 -1
  203. package/dist/theme/components/CodeButtonGroup/index.js +3 -5
  204. package/dist/theme/components/DocContent/doc.css +28 -7
  205. package/dist/theme/components/DocContent/docComponents/index.d.ts +3 -3
  206. package/dist/theme/components/DocContent/docComponents/pre.js +3 -1
  207. package/dist/theme/components/DocContent/docComponents/table.d.ts +2 -2
  208. package/dist/theme/components/DocContent/docComponents/table.js +8 -3
  209. package/dist/theme/components/DocContent/index.d.ts +11 -2
  210. package/dist/theme/components/DocContent/index.js +6 -6
  211. package/dist/theme/components/DocFooter/index.js +1 -5
  212. package/dist/theme/components/{DocContent/FallbackHeading.js → FallbackHeading/index.js} +19 -11
  213. package/dist/theme/components/HoverGroup/index.css +3 -3
  214. package/dist/theme/components/HoverGroup/useHoverGroup.d.ts +1 -1
  215. package/dist/theme/components/LastUpdated/index.d.ts +1 -1
  216. package/dist/theme/components/LastUpdated/index.js +5 -1
  217. package/dist/theme/components/Link/index.d.ts +1 -1
  218. package/dist/theme/components/Link/index.js +17 -7
  219. package/dist/theme/components/Nav/NavMenu.js +2 -3
  220. package/dist/theme/components/NavHamburger/index.js +3 -4
  221. package/dist/theme/components/NavScreen/NavScreenLangs.css +6 -0
  222. package/dist/theme/components/NavScreen/NavScreenLangs.js +13 -3
  223. package/dist/theme/components/NavScreen/NavScreenMenuItem.js +2 -3
  224. package/dist/theme/components/NavScreen/NavScreenVersions.css +6 -0
  225. package/dist/theme/components/NavScreen/NavScreenVersions.js +12 -3
  226. package/dist/theme/components/Overview/index.d.ts +0 -1
  227. package/dist/theme/components/Overview/index.js +2 -3
  228. package/dist/theme/components/{Overview/OverviewGroup.css → OverviewGroup/index.css} +60 -8
  229. package/dist/theme/components/{Overview/OverviewGroup.d.ts → OverviewGroup/index.d.ts} +1 -1
  230. package/dist/theme/components/OverviewGroup/index.js +88 -0
  231. package/dist/theme/components/PackageManagerTabs/index.d.ts +1 -1
  232. package/dist/theme/components/PackageManagerTabs/index.js +4 -0
  233. package/dist/theme/components/PrevNextPage/index.js +3 -4
  234. package/dist/theme/components/Root/index.d.ts +54 -0
  235. package/dist/theme/components/Root/index.js +7 -0
  236. package/dist/theme/components/Search/NoSearchResult.js +2 -3
  237. package/dist/theme/components/Search/SearchButton.js +3 -4
  238. package/dist/theme/components/Search/SearchPanel.js +12 -15
  239. package/dist/theme/components/Search/SuggestItem.d.ts +1 -1
  240. package/dist/theme/components/Search/SuggestItem.js +7 -11
  241. package/dist/theme/components/Search/logic/Provider.d.ts +1 -1
  242. package/dist/theme/components/Search/logic/providers/LocalProvider.d.ts +2 -2
  243. package/dist/theme/components/Search/logic/search.d.ts +1 -1
  244. package/dist/theme/components/Search/logic/util.test.js +1 -1
  245. package/dist/theme/components/Sidebar/SidebarGroup.js +2 -3
  246. package/dist/theme/components/Sidebar/SidebarItem.js +1 -0
  247. package/dist/theme/components/SidebarMenu/index.js +3 -5
  248. package/dist/theme/components/SocialLinks/index.js +2 -3
  249. package/dist/theme/components/SourceCode/index.js +2 -4
  250. package/dist/theme/components/SwitchAppearance/index.js +3 -5
  251. package/dist/theme/components/Tabs/index.css +19 -27
  252. package/dist/theme/components/Tabs/index.js +9 -0
  253. package/dist/theme/components/Tag/index.d.ts +3 -0
  254. package/dist/theme/components/Tag/index.js +63 -8
  255. package/dist/theme/components/Toc/TocItem.css +2 -3
  256. package/dist/theme/components/Toc/TocItem.js +1 -0
  257. package/dist/theme/hooks/useActiveAnchor.js +1 -1
  258. package/dist/theme/icons.d.ts +27 -0
  259. package/dist/theme/icons.js +51 -0
  260. package/dist/theme/index.d.ts +64 -59
  261. package/dist/theme/index.js +7 -2
  262. package/dist/theme/layout/DocLayout/index.css +2 -4
  263. package/dist/theme/layout/Layout/index.js +1 -2
  264. package/dist/theme/layout/NotFountLayout/index.js +1 -1
  265. package/dist/theme/logic/useAppearance.js +1 -1
  266. package/dist/theme/logic/useFullTextSearch.d.ts +1 -1
  267. package/dist/theme/logic/useMediaQuery.js +1 -1
  268. package/dist/theme/styles/base.css +1 -0
  269. package/dist/theme/styles/scrollbar.css +1 -0
  270. package/dist/theme/styles/shiki.css +9 -3
  271. package/dist/theme/styles/vars/base-vars.css +7 -5
  272. package/dist/theme/styles/vars/code-vars.css +2 -0
  273. package/dist/theme/styles/vars/home-vars.css +2 -1
  274. package/package.json +22 -23
  275. package/dist/3~128.js +0 -74
  276. package/dist/3~517.js +0 -1786
  277. package/dist/3~894.js +0 -26
  278. package/dist/cli.js +0 -259
  279. package/dist/index.js.LICENSE.txt +0 -10
  280. package/dist/node/auto-nav-sidebar/fixtures/docs/guide/c.d.ts +0 -2
  281. package/dist/node/auto-nav-sidebar/fixtures/docs-locales/en/guide/c.d.ts +0 -2
  282. package/dist/node/auto-nav-sidebar/fixtures/docs-locales/zh/guide/c.d.ts +0 -2
  283. package/dist/node/auto-nav-sidebar/locales.test.d.ts +0 -1
  284. package/dist/node/auto-nav-sidebar/walk.test.d.ts +0 -1
  285. package/dist/node/mdx/rehypePlugins/headerAnchor.test.d.ts +0 -1
  286. package/dist/node/mdx/remarkPlugins/containerSyntax.test.d.ts +0 -1
  287. package/dist/node/mdx/remarkPlugins/fileCodeBlock.test.d.ts +0 -1
  288. package/dist/node/mdx/remarkPlugins/image.test.d.ts +0 -1
  289. package/dist/node/mdx/remarkPlugins/link.test.d.ts +0 -1
  290. package/dist/node/route/RouteService.test.d.ts +0 -1
  291. package/dist/node/route/extractPageData.test.d.ts +0 -1
  292. package/dist/node/route/fixtures/basic/guide/c.d.ts +0 -2
  293. package/dist/node/route/normalizeRoutePath.test.d.ts +0 -1
  294. package/dist/node/runtimeModule/i18n.test.d.ts +0 -1
  295. package/dist/node/ssg-md/remarkSplitMdx.test.d.ts +0 -4
  296. package/dist/node/utils/checkLanguageParity.test.d.ts +0 -1
  297. package/dist/node/utils/detectCustomIcon.d.ts +0 -1
  298. package/dist/node/utils/detectReactVersion.d.ts +0 -3
  299. package/dist/processor.js +0 -4539
  300. package/dist/renderPageWorker.js +0 -196
  301. package/dist/theme/components/Overview/OverviewGroup.js +0 -58
  302. package/dist/theme/components/Search/logic/util.test.d.ts +0 -1
  303. /package/dist/cli/{config.d.ts → config/index.d.ts} +0 -0
  304. /package/dist/eject-theme/components/{Overview → OverviewGroup}/icons/plugin.svg +0 -0
  305. /package/dist/{shiki-transformers.js.LICENSE.txt → node/mdx/rehypePlugins/transformers/meta-highlight.js.LICENSE.txt} +0 -0
  306. /package/dist/theme/components/{DocContent/FallbackHeading.d.ts → FallbackHeading/index.d.ts} +0 -0
  307. /package/dist/theme/components/{Overview → OverviewGroup}/icons/plugin.js +0 -0
@@ -0,0 +1,33 @@
1
+ /*! For license information please see ssgEnv.js.LICENSE.txt */
2
+ import { node_os } from "../../9643.f109822d.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 };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * these codes are copied from
3
+ * @link https://github.com/facebook/docusaurus/blob/45065e8d2b5831117b8d69fec1be28f5520cf105/packages/docusaurus/src/ssg/ssgEnv.ts#L11
4
+ * @license MIT
5
+ */
@@ -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,84 @@
1
+ import { getSidebarDataGroup } from "../../../4669.12208c6a.js";
2
+ import { matchPath } from "../../../3521.56e42d70.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
+ const langs = new Set([
34
+ defaultLang,
35
+ ...routeService.getLangs()
36
+ ]);
37
+ await Promise.all(langs.values().map(async (lang)=>{
38
+ const navList = noVersionNav.filter((i)=>i.lang === lang);
39
+ const routeGroups = new Array(navList.length).fill(0).map(()=>[]);
40
+ const others = [];
41
+ routeService.getRoutes().forEach((routeMeta)=>{
42
+ if (routeMeta.lang !== lang) return;
43
+ const { routePath } = routeMeta;
44
+ for(let i = 0; i < routeGroups.length; i++){
45
+ const routeGroup = routeGroups[i];
46
+ const navItem = navList[i];
47
+ if (lang === navItem.lang && new RegExp(navItem.activeMatch ?? navItem.link).test(routePath)) return void routeGroup.push(routePath);
48
+ }
49
+ others.push(routePath);
50
+ });
51
+ for (const routeGroup of routeGroups)organizeBySidebar(sidebar, routeGroup);
52
+ const llmsTxtContent = await generateLlmsTxt(routeGroups, others, navList, config.title, config.description, config.base, routeService);
53
+ const llmsFullTxtContent = generateLlmsFullTxt(routeGroups, navList, others, base, mdContents);
54
+ const prefix = defaultLang === lang ? '' : `${lang}/`;
55
+ emitAsset(`${prefix}llms.txt`, llmsTxtContent);
56
+ emitAsset(`${prefix}llms-full.txt`, llmsFullTxtContent);
57
+ }));
58
+ }
59
+ function flatSidebar(sidebar) {
60
+ if (!sidebar) return [];
61
+ return sidebar.flatMap((i)=>{
62
+ if ('string' == typeof i) return i;
63
+ if ('link' in i && 'string' == typeof i.link) return [
64
+ i.link,
65
+ ...flatSidebar(i?.items ?? [])
66
+ ];
67
+ if ('items' in i && Array.isArray(i.items)) return flatSidebar(i.items);
68
+ }).filter(Boolean);
69
+ }
70
+ function organizeBySidebar(sidebar, routes) {
71
+ if (0 === routes.length) return;
72
+ const route = routes[0];
73
+ const currSidebar = getSidebarDataGroup(sidebar, route);
74
+ if (0 === currSidebar.length) return;
75
+ const orderList = flatSidebar(currSidebar);
76
+ routes.sort((a, b)=>{
77
+ let aIndex = orderList.findIndex((order)=>matchPath(order, a));
78
+ if (-1 === aIndex) aIndex = Number.MAX_SAFE_INTEGER;
79
+ let bIndex = orderList.findIndex((order)=>matchPath(order, b));
80
+ if (-1 === bIndex) bIndex = Number.MAX_SAFE_INTEGER;
81
+ return aIndex - bIndex;
82
+ });
83
+ }
84
+ 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,244 @@
1
+ import { unified, remark_gfm, remark_mdx, remark_stringify } from "../mdx/loader.e1578c62.js";
2
+ import { visit } from "../../8813.9da1f210.js";
3
+ function remarkSplitMdx(options = {}) {
4
+ return (tree)=>{
5
+ const newChildren = [];
6
+ const { importMap, importNodes } = buildImportMap(tree);
7
+ newChildren.push(...importNodes);
8
+ for (const node of tree.children){
9
+ if ('mdxjsEsm' === node.type) continue;
10
+ if ('mdxJsxFlowElement' === node.type || 'mdxJsxTextElement' === node.type) {
11
+ newChildren.push(processJsxElement(node, importMap, options));
12
+ continue;
13
+ }
14
+ const hasJsxChildren = node.children?.some((child)=>'mdxJsxFlowElement' === child.type || 'mdxJsxTextElement' === child.type);
15
+ if (hasJsxChildren) {
16
+ const processedChildren = processMixedContent(node, node.children || [], importMap, options);
17
+ newChildren.push({
18
+ type: 'mdxJsxFlowElement',
19
+ name: null,
20
+ attributes: [],
21
+ children: processedChildren
22
+ });
23
+ } else newChildren.push(buildMdxFlowExpressionFragment(node));
24
+ }
25
+ tree.children = newChildren;
26
+ };
27
+ }
28
+ function processJsxElement(node, importMap, options) {
29
+ const processedNode = processJsxChildren(node, importMap, options);
30
+ const componentName = getComponentName(node.name);
31
+ const isMdxFragment = componentName && importMap.get(componentName)?.endsWith('.mdx');
32
+ if (isMdxFragment || shouldKeepJsxElement(node.name, importMap, options)) return processedNode;
33
+ return buildMdxFlowExpressionFragment(processedNode);
34
+ }
35
+ function processJsxChildren(node, importMap, options) {
36
+ if (!node.children || 0 === node.children.length) return node;
37
+ const processedChildren = [];
38
+ let textBuffer = [];
39
+ const flushTextBuffer = ()=>{
40
+ if (0 === textBuffer.length) return;
41
+ const combined = textBuffer.map((child)=>serializeNodeToMarkdown(child)).join('');
42
+ if (combined) processedChildren.push(createTextExpression(combined));
43
+ textBuffer = [];
44
+ };
45
+ for (const child of node.children)if ('mdxJsxFlowElement' === child.type || 'mdxJsxTextElement' === child.type) {
46
+ flushTextBuffer();
47
+ processedChildren.push(processJsxElement(child, importMap, options));
48
+ } else textBuffer.push(child);
49
+ flushTextBuffer();
50
+ return {
51
+ ...node,
52
+ children: processedChildren
53
+ };
54
+ }
55
+ function getComponentName(name) {
56
+ if (!name) return null;
57
+ if ('string' == typeof name) {
58
+ const dotIndex = name.indexOf('.');
59
+ if (dotIndex > 0) return name.substring(0, dotIndex);
60
+ return name;
61
+ }
62
+ if ('object' == typeof name) {
63
+ if ('mdxJsxMemberExpression' === name.type || 'mdxJsxNamespacedName' === name.type) return getComponentName(name.object);
64
+ }
65
+ return null;
66
+ }
67
+ function processMixedContent(parentNode, children, importMap, options) {
68
+ const result = [];
69
+ let textBuffer = [];
70
+ const prefix = 'heading' === parentNode.type ? `${'#'.repeat(parentNode.depth || 1)} ` : '';
71
+ let prefixAdded = false;
72
+ const flushTextBuffer = ()=>{
73
+ if (textBuffer.length > 0) {
74
+ let combined = textBuffer.join('');
75
+ if (!prefixAdded && prefix) {
76
+ combined = prefix + combined;
77
+ prefixAdded = true;
78
+ }
79
+ if (combined) result.push(createTextExpression(combined));
80
+ textBuffer = [];
81
+ } else if (!prefixAdded && prefix) {
82
+ result.push(createTextExpression(prefix.trimEnd()));
83
+ prefixAdded = true;
84
+ }
85
+ };
86
+ for (const child of children)if ('mdxJsxFlowElement' === child.type || 'mdxJsxTextElement' === child.type) {
87
+ flushTextBuffer();
88
+ result.push(processJsxElement(child, importMap, options));
89
+ } else if ('text' === child.type) textBuffer.push(child.value || '');
90
+ else {
91
+ const serialized = serializeNodeToMarkdown(child);
92
+ if (serialized) textBuffer.push(serialized);
93
+ }
94
+ flushTextBuffer();
95
+ return result;
96
+ }
97
+ function buildMdxFlowExpressionFragment(node) {
98
+ const children = node.children;
99
+ const hasJsxChildren = children?.some((child)=>'mdxJsxFlowElement' === child.type || 'mdxJsxTextElement' === child.type || 'mdxFlowExpression' === child.type || 'mdxTextExpression' === child.type);
100
+ if (hasJsxChildren && ('mdxJsxFlowElement' === node.type || 'mdxJsxTextElement' === node.type)) return buildMixedContentFragment(node, children);
101
+ const textContent = serializeNodeToMarkdown(node);
102
+ const stringified = JSON.stringify(textContent);
103
+ const fragment = {
104
+ type: 'mdxFlowExpression',
105
+ value: stringified,
106
+ data: {
107
+ estree: {
108
+ type: 'Program',
109
+ body: [
110
+ {
111
+ type: 'ExpressionStatement',
112
+ expression: {
113
+ type: 'Literal',
114
+ value: textContent,
115
+ raw: stringified
116
+ }
117
+ }
118
+ ],
119
+ sourceType: 'module'
120
+ }
121
+ }
122
+ };
123
+ return fragment;
124
+ }
125
+ function buildMixedContentFragment(node, children) {
126
+ const result = [];
127
+ const openingTag = serializeOpeningTag(node);
128
+ if (openingTag) result.push(createTextExpression(openingTag));
129
+ for (const child of children){
130
+ const isJsxOrExpression = 'mdxJsxFlowElement' === child.type || 'mdxJsxTextElement' === child.type || 'mdxFlowExpression' === child.type || 'mdxTextExpression' === child.type;
131
+ if (isJsxOrExpression) result.push(child);
132
+ else {
133
+ const text = serializeNodeToMarkdown(child);
134
+ if (text) result.push(createTextExpression(text));
135
+ }
136
+ }
137
+ const closingTag = serializeClosingTag(node);
138
+ if (closingTag) result.push(createTextExpression(closingTag));
139
+ return {
140
+ type: 'mdxJsxFlowElement',
141
+ name: null,
142
+ attributes: [],
143
+ children: result
144
+ };
145
+ }
146
+ function createTextExpression(text) {
147
+ const stringified = JSON.stringify(text);
148
+ return {
149
+ type: 'mdxTextExpression',
150
+ value: stringified,
151
+ data: {
152
+ estree: {
153
+ type: 'Program',
154
+ body: [
155
+ {
156
+ type: 'ExpressionStatement',
157
+ expression: {
158
+ type: 'Literal',
159
+ value: text,
160
+ raw: stringified
161
+ }
162
+ }
163
+ ],
164
+ sourceType: 'module'
165
+ }
166
+ }
167
+ };
168
+ }
169
+ function serializeOpeningTag(node) {
170
+ const name = 'string' == typeof node.name ? node.name : '';
171
+ if (!name) return '';
172
+ const attrs = node.attributes?.map((attr)=>{
173
+ if ('mdxJsxAttribute' !== attr.type) return '';
174
+ const attrName = attr.name;
175
+ if (null === attr.value || void 0 === attr.value) return attrName;
176
+ if ('string' == typeof attr.value) return `${attrName}="${attr.value}"`;
177
+ if ('mdxJsxAttributeValueExpression' === attr.value.type) return `${attrName}={${attr.value.value || ''}}`;
178
+ return '';
179
+ }).filter(Boolean).join(' ');
180
+ return `<${name}${attrs ? ` ${attrs}` : ''}>`;
181
+ }
182
+ function serializeClosingTag(node) {
183
+ const name = 'string' == typeof node.name ? node.name : '';
184
+ if (!name) return '';
185
+ return `</${name}>`;
186
+ }
187
+ const processor = unified().use(remark_mdx).use(remark_gfm).use(remark_stringify, {
188
+ bullet: '-',
189
+ emphasis: '_',
190
+ fences: true,
191
+ incrementListMarker: true,
192
+ handlers: {
193
+ mdxjsEsm: ()=>''
194
+ }
195
+ });
196
+ function serializeNodeToMarkdown(node) {
197
+ const tempRoot = {
198
+ type: 'root',
199
+ children: [
200
+ node
201
+ ]
202
+ };
203
+ const result = processor.stringify(tempRoot);
204
+ return result;
205
+ }
206
+ function buildImportMap(tree) {
207
+ const importMap = new Map();
208
+ const importNodes = new Set();
209
+ visit(tree, 'mdxjsEsm', (node)=>{
210
+ const estree = node.data?.estree;
211
+ if (!estree) return;
212
+ for (const statement of estree.body){
213
+ if ('ImportDeclaration' !== statement.type) continue;
214
+ const source = statement.source.value;
215
+ for (const specifier of statement.specifiers){
216
+ const localName = specifier.local?.name;
217
+ if (localName) {
218
+ importMap.set(localName, source);
219
+ importNodes.add(node);
220
+ }
221
+ }
222
+ }
223
+ });
224
+ return {
225
+ importMap,
226
+ importNodes
227
+ };
228
+ }
229
+ function shouldKeepJsxElement(nameField, importMap, options) {
230
+ const componentName = getComponentName(nameField);
231
+ if (!componentName) return true;
232
+ const { includes, excludes } = options;
233
+ const importSource = importMap.get(componentName);
234
+ if (!includes && !excludes) return true;
235
+ if (excludes) {
236
+ for (const [excludeSpecifiers, excludeSource] of excludes)if (excludeSpecifiers.includes(componentName) && (!importSource || importSource === excludeSource)) return false;
237
+ }
238
+ if (includes) {
239
+ for (const [includeSpecifiers, includeSource] of includes)if (includeSpecifiers.includes(componentName) && (!importSource || importSource === includeSource)) return true;
240
+ return false;
241
+ }
242
+ return true;
243
+ }
244
+ export { remarkSplitMdx };
@@ -0,0 +1,31 @@
1
+ import { pathToFileURL, createHead } from "../../5485.077f14ff.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.077f14ff.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,6 @@
1
+ function applyReplaceRules(code = '', replaceRules = []) {
2
+ let result = code;
3
+ for (const rule of replaceRules)result = result.replace(rule.search, rule.replace);
4
+ return result;
5
+ }
6
+ export { applyReplaceRules };
@@ -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,5 @@
1
+ import { createHash as external_node_crypto_createHash } from "../../3521.56e42d70.js";
2
+ function createHash(str) {
3
+ return external_node_crypto_createHash('sha256').update(str).digest('hex').slice(0, 8);
4
+ }
5
+ export { createHash };