@rspress/core 2.0.0-rc.0 → 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/Button/index.scss +1 -6
- 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 +30 -9
- package/dist/eject-theme/components/DocContent/docComponents/table.tsx +10 -4
- package/dist/eject-theme/components/DocContent/index.tsx +5 -2
- package/dist/eject-theme/components/{DocContent/FallbackHeading.tsx → FallbackHeading/index.tsx} +20 -11
- package/dist/eject-theme/components/HoverGroup/index.scss +5 -1
- package/dist/eject-theme/components/HoverGroup/index.tsx +5 -1
- package/dist/eject-theme/components/Link/index.tsx +43 -9
- package/dist/eject-theme/components/Link/useLinkNavigate.ts +32 -16
- package/dist/eject-theme/components/Nav/NavMenu.scss +1 -0
- package/dist/eject-theme/components/Nav/NavMenu.tsx +2 -3
- package/dist/eject-theme/components/Nav/NavTitle.scss +11 -0
- package/dist/eject-theme/components/Nav/NavTitle.tsx +1 -0
- package/dist/eject-theme/components/Nav/index.scss +0 -8
- package/dist/eject-theme/components/NavHamburger/index.tsx +3 -4
- package/dist/eject-theme/components/NavScreen/NavScreenMenuItem.scss +14 -0
- package/dist/eject-theme/components/NavScreen/NavScreenMenuItem.tsx +2 -3
- package/dist/eject-theme/components/Outline/index.scss +0 -1
- 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 +14 -9
- 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.scss +12 -8
- package/dist/eject-theme/components/Sidebar/SidebarItem.tsx +6 -4
- package/dist/eject-theme/components/Sidebar/SidebarSectionHeader.scss +1 -1
- 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.scss +2 -1
- 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 +8 -4
- 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/assets/moon.js +9 -26
- package/dist/theme/components/Banner/index.d.ts +1 -1
- package/dist/theme/components/Banner/index.js +2 -3
- package/dist/theme/components/Button/index.css +1 -1
- 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 +30 -8
- 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 +3 -2
- package/dist/theme/components/{DocContent/FallbackHeading.js → FallbackHeading/index.js} +19 -11
- package/dist/theme/components/HoverGroup/index.css +5 -1
- package/dist/theme/components/HoverGroup/index.js +1 -0
- package/dist/theme/components/HoverGroup/useHoverGroup.d.ts +1 -1
- package/dist/theme/components/Link/index.d.ts +18 -1
- package/dist/theme/components/Link/index.js +14 -8
- package/dist/theme/components/Link/useLinkNavigate.d.ts +4 -1
- package/dist/theme/components/Link/useLinkNavigate.js +23 -17
- package/dist/theme/components/Nav/NavMenu.css +1 -0
- package/dist/theme/components/Nav/NavMenu.js +2 -3
- package/dist/theme/components/Nav/NavTitle.css +12 -0
- package/dist/theme/components/Nav/NavTitle.d.ts +1 -0
- package/dist/theme/components/Nav/NavTitle.js +1 -0
- package/dist/theme/components/Nav/index.css +0 -8
- package/dist/theme/components/NavHamburger/index.js +3 -4
- package/dist/theme/components/NavScreen/NavScreenMenuItem.css +9 -0
- package/dist/theme/components/NavScreen/NavScreenMenuItem.js +2 -3
- package/dist/theme/components/Outline/index.css +0 -1
- 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 +13 -16
- 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.css +11 -3
- package/dist/theme/components/Sidebar/SidebarItem.js +6 -3
- package/dist/theme/components/Sidebar/SidebarSectionHeader.css +1 -1
- package/dist/theme/components/SidebarMenu/index.js +3 -5
- package/dist/theme/components/SocialLinks/index.js +2 -3
- package/dist/theme/components/SourceCode/index.css +5 -0
- 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 +7 -4
- 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 +5 -2
- package/dist/theme/layout/DocLayout/index.css +2 -2
- package/dist/theme/layout/DocLayout/index.js +1 -4
- package/dist/theme/layout/Layout/index.d.ts +1 -1
- package/dist/theme/layout/Layout/index.js +3 -3
- package/dist/theme/logic/useFullTextSearch.d.ts +1 -1
- package/dist/theme/logic/useScrollAfterNav.d.ts +5 -0
- package/dist/theme/logic/{sideEffects.js → useScrollAfterNav.js} +5 -6
- package/dist/theme/logic/useScrollReset.d.ts +5 -0
- package/dist/theme/logic/useScrollReset.js +12 -0
- package/dist/theme/logic/useSetup.js +2 -0
- package/dist/theme/styles/base.css +1 -10
- package/dist/theme/styles/index.d.ts +1 -1
- package/dist/theme/styles/index.js +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 +4 -2
- package/package.json +19 -20
- package/dist/3~101.js +0 -1786
- package/dist/3~335.js +0 -26
- package/dist/3~395.js +0 -74
- 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
- /package/dist/theme/logic/{sideEffects.d.ts → useSetup.d.ts} +0 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { node_path, logger, picocolors, readFile } from "../../../6289.c67fe0d5.js";
|
|
2
|
+
import { cwd } from "../../../1218.3869bad6.js";
|
|
3
|
+
import { visit } from "../../../8813.9da1f210.js";
|
|
4
|
+
import { createError } from "../../utils/error.js";
|
|
5
|
+
const ERROR_PREFIX = '[remarkFileCodeBlock]';
|
|
6
|
+
function parseFileFromMeta(meta) {
|
|
7
|
+
if (!meta) return '';
|
|
8
|
+
const kvList = meta.split(' ').filter(Boolean);
|
|
9
|
+
for (const item of kvList){
|
|
10
|
+
const [k, v = ''] = item.split('=');
|
|
11
|
+
if ('file' === k && v.length > 0) return v.replace(/["'`]/g, '');
|
|
12
|
+
}
|
|
13
|
+
return '';
|
|
14
|
+
}
|
|
15
|
+
const remarkFileCodeBlock = ({ filepath, addDependency })=>async (tree)=>{
|
|
16
|
+
const promiseList = [];
|
|
17
|
+
visit(tree, 'code', (node)=>{
|
|
18
|
+
const { meta, value, lang } = node;
|
|
19
|
+
const file = parseFileFromMeta(meta ?? '');
|
|
20
|
+
if (!file) return;
|
|
21
|
+
const originalMetaForErrorInfo = picocolors.cyan(`\`\`\`${lang} ${meta}`);
|
|
22
|
+
if (file.startsWith('./') || file.startsWith('../') || file.startsWith('<root>/')) {
|
|
23
|
+
let resolvedFilePath;
|
|
24
|
+
resolvedFilePath = file.startsWith('<root>/') ? node_path.join(cwd(), file.slice(7)) : node_path.join(node_path.dirname(filepath), file);
|
|
25
|
+
if ('' !== value.trim()) {
|
|
26
|
+
logger.error(`${ERROR_PREFIX} ${originalMetaForErrorInfo} The content of file code block should be empty.
|
|
27
|
+
|
|
28
|
+
\`\`\`tsx file="./filename"
|
|
29
|
+
content
|
|
30
|
+
\`\`\`
|
|
31
|
+
|
|
32
|
+
this usage is not allowed, please use below:
|
|
33
|
+
|
|
34
|
+
\`\`\`tsx file="./filename"
|
|
35
|
+
\`\`\`
|
|
36
|
+
`);
|
|
37
|
+
throw createError(`${ERROR_PREFIX} ${originalMetaForErrorInfo} The content of file code block should be empty.`);
|
|
38
|
+
}
|
|
39
|
+
const promise = readFile(resolvedFilePath, 'utf-8').then((fileContent)=>{
|
|
40
|
+
addDependency?.(resolvedFilePath);
|
|
41
|
+
node.value = fileContent;
|
|
42
|
+
}).catch((e)=>{
|
|
43
|
+
const message = `${ERROR_PREFIX} ${originalMetaForErrorInfo} introduces another file in "${resolvedFilePath}", but the file does not exist.`;
|
|
44
|
+
logger.error(message);
|
|
45
|
+
e.message = `${message}\n${e.message}`;
|
|
46
|
+
throw e;
|
|
47
|
+
});
|
|
48
|
+
promiseList.push(promise);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
logger.error(`${ERROR_PREFIX} ${originalMetaForErrorInfo} syntax error of file code block:
|
|
52
|
+
Please use below:
|
|
53
|
+
|
|
54
|
+
\`\`\`tsx file="./filename"
|
|
55
|
+
\`\`\`
|
|
56
|
+
|
|
57
|
+
or
|
|
58
|
+
|
|
59
|
+
\`\`\`tsx file="<root>/path/to/filename"
|
|
60
|
+
\`\`\`
|
|
61
|
+
`);
|
|
62
|
+
throw createError(`${ERROR_PREFIX} ${originalMetaForErrorInfo} syntax error of file code block`);
|
|
63
|
+
});
|
|
64
|
+
await Promise.all(promiseList);
|
|
65
|
+
};
|
|
66
|
+
export { remarkFileCodeBlock };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { isExternalUrl } from "../../../4669.12208c6a.js";
|
|
2
|
+
import { getNodeAttribute } from "../../../7805.cadab34e.js";
|
|
3
|
+
import { visit } from "../../../8813.9da1f210.js";
|
|
4
|
+
import { getDefaultImportAstNode } from "../../utils/getImportAstNode.js";
|
|
5
|
+
const normalizeImageUrl = (imageUrl)=>{
|
|
6
|
+
if (isExternalUrl(imageUrl) || imageUrl.startsWith('/')) return '';
|
|
7
|
+
return imageUrl;
|
|
8
|
+
};
|
|
9
|
+
const remarkImage = ()=>(tree, _file)=>{
|
|
10
|
+
const images = [];
|
|
11
|
+
const getMdxSrcAttribute = (tempVar)=>({
|
|
12
|
+
type: 'mdxJsxAttribute',
|
|
13
|
+
name: 'src',
|
|
14
|
+
value: {
|
|
15
|
+
type: 'mdxJsxAttributeValueExpression',
|
|
16
|
+
value: tempVar,
|
|
17
|
+
data: {
|
|
18
|
+
estree: {
|
|
19
|
+
type: 'Program',
|
|
20
|
+
sourceType: 'module',
|
|
21
|
+
body: [
|
|
22
|
+
{
|
|
23
|
+
type: 'ExpressionStatement',
|
|
24
|
+
expression: {
|
|
25
|
+
type: 'Identifier',
|
|
26
|
+
name: tempVar
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
]
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
visit(tree, 'image', (node)=>{
|
|
35
|
+
const { alt, url } = node;
|
|
36
|
+
if (!url) return;
|
|
37
|
+
const imagePath = normalizeImageUrl(url);
|
|
38
|
+
if (!imagePath) return;
|
|
39
|
+
const tempVariableName = `image${images.length}`;
|
|
40
|
+
Object.assign(node, {
|
|
41
|
+
type: 'mdxJsxFlowElement',
|
|
42
|
+
name: 'img',
|
|
43
|
+
children: [],
|
|
44
|
+
attributes: [
|
|
45
|
+
alt && {
|
|
46
|
+
type: 'mdxJsxAttribute',
|
|
47
|
+
name: 'alt',
|
|
48
|
+
value: alt
|
|
49
|
+
},
|
|
50
|
+
getMdxSrcAttribute(tempVariableName)
|
|
51
|
+
].filter(Boolean)
|
|
52
|
+
});
|
|
53
|
+
images.push(getDefaultImportAstNode(tempVariableName, imagePath));
|
|
54
|
+
});
|
|
55
|
+
visit(tree, (node)=>{
|
|
56
|
+
if ('mdxJsxFlowElement' !== node.type && 'mdxJsxTextElement' !== node.type || 'img' !== node.name) return;
|
|
57
|
+
const srcAttr = getNodeAttribute(node, 'src', true);
|
|
58
|
+
if ('string' != typeof srcAttr?.value) return;
|
|
59
|
+
const imagePath = normalizeImageUrl(srcAttr.value);
|
|
60
|
+
if (!imagePath) return;
|
|
61
|
+
const tempVariableName = `image${images.length}`;
|
|
62
|
+
Object.assign(srcAttr, getMdxSrcAttribute(tempVariableName));
|
|
63
|
+
images.push(getDefaultImportAstNode(tempVariableName, imagePath));
|
|
64
|
+
});
|
|
65
|
+
tree.children.unshift(...images);
|
|
66
|
+
};
|
|
67
|
+
export { remarkImage };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type MarkdownOptions } from '@rspress/shared';
|
|
2
2
|
import type { Root } from 'mdast';
|
|
3
3
|
import type { VFile } from 'vfile';
|
|
4
|
-
import type { RouteService } from '../../route/RouteService';
|
|
4
|
+
import type { RouteService } from '../../route/RouteService.js';
|
|
5
5
|
/**
|
|
6
6
|
* Remark plugin to normalize a link href
|
|
7
7
|
* 1. add version and lang prefix to the link
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { node_path, logger, picocolors } from "../../../6289.c67fe0d5.js";
|
|
2
|
+
import { isExternalUrl, isProduction, addLeadingSlash, parseUrl, normalizeHref, withBase } from "../../../4669.12208c6a.js";
|
|
3
|
+
import { visit } from "../../../8813.9da1f210.js";
|
|
4
|
+
import { hintRelativeMarkdownLink } from "../../logger/hint.js";
|
|
5
|
+
import { createError } from "../../utils/error.js";
|
|
6
|
+
function link_checkDeadLinks(checkDeadLinks, internalLinks, file, lint) {
|
|
7
|
+
const errorInfos = [];
|
|
8
|
+
const excludes = 'object' == typeof checkDeadLinks ? checkDeadLinks.excludes : void 0;
|
|
9
|
+
const excludesUrl = Array.isArray(excludes) ? new Set(excludes) : void 0;
|
|
10
|
+
const excludesFn = 'function' == typeof excludes ? excludes : void 0;
|
|
11
|
+
let possibleBreakingChange = false;
|
|
12
|
+
[
|
|
13
|
+
...internalLinks.entries()
|
|
14
|
+
].forEach(([nodeUrl, link])=>{
|
|
15
|
+
if (excludesUrl?.has(nodeUrl)) return;
|
|
16
|
+
if (excludesFn?.(nodeUrl)) return;
|
|
17
|
+
if (!nodeUrl.startsWith('/') && /^\w/.test(nodeUrl)) possibleBreakingChange = true;
|
|
18
|
+
errorInfos.push([
|
|
19
|
+
nodeUrl,
|
|
20
|
+
link
|
|
21
|
+
]);
|
|
22
|
+
});
|
|
23
|
+
if (errorInfos.length > 0) {
|
|
24
|
+
if (possibleBreakingChange) hintRelativeMarkdownLink();
|
|
25
|
+
const message = `Dead links found${lint ? '' : ` in ${picocolors.cyan(file.path)}`}:
|
|
26
|
+
${errorInfos.map(([nodeUrl, link])=>` ${picocolors.green(`"[..](${nodeUrl})"`)} ${picocolors.gray(link)}`).join('\n')}`;
|
|
27
|
+
if (lint) file.message(message);
|
|
28
|
+
else {
|
|
29
|
+
logger.error(message);
|
|
30
|
+
if (isProduction()) throw createError('Dead link found');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function looseMarkdownLink(url, routeService, filePath) {
|
|
35
|
+
if (!routeService.isInDocsDir(filePath)) return url;
|
|
36
|
+
const [versionPart, langPart, pureRoute] = routeService.splitRoutePathParts(url);
|
|
37
|
+
const relativePath = routeService.absolutePathToRelativePath(filePath);
|
|
38
|
+
const [versionPartCurrFile, langPartCurrFile] = routeService.getRoutePathParts(relativePath);
|
|
39
|
+
if ('' === versionPart) {
|
|
40
|
+
if ('' === langPart) return addLeadingSlash(`${[
|
|
41
|
+
versionPartCurrFile,
|
|
42
|
+
langPartCurrFile
|
|
43
|
+
].filter(Boolean).join('/')}${addLeadingSlash(pureRoute.replace(/^\/*/, ''))}`);
|
|
44
|
+
return addLeadingSlash(`${[
|
|
45
|
+
versionPartCurrFile,
|
|
46
|
+
langPart
|
|
47
|
+
].filter(Boolean).join('/')}${addLeadingSlash(pureRoute.replace(/^\/*/, ''))}`);
|
|
48
|
+
}
|
|
49
|
+
return url;
|
|
50
|
+
}
|
|
51
|
+
function normalizeLink(nodeUrl, routeService, filePath, cleanUrls, autoPrefix, deadLinks, __base) {
|
|
52
|
+
if (!nodeUrl) return '';
|
|
53
|
+
if (nodeUrl.startsWith('#')) return nodeUrl;
|
|
54
|
+
if (isExternalUrl(nodeUrl)) return nodeUrl;
|
|
55
|
+
if (!routeService) return nodeUrl;
|
|
56
|
+
let { url, hash, search } = parseUrl(nodeUrl);
|
|
57
|
+
if (url.startsWith('/')) {
|
|
58
|
+
if (autoPrefix) url = looseMarkdownLink(url, routeService, filePath);
|
|
59
|
+
const { routePath } = routeService.normalizeRoutePath(url);
|
|
60
|
+
url = routePath;
|
|
61
|
+
} else {
|
|
62
|
+
const anotherFileAbsolutePath = node_path.join(node_path.dirname(filePath), url);
|
|
63
|
+
url = routeService.absolutePathToRoutePath(anotherFileAbsolutePath);
|
|
64
|
+
}
|
|
65
|
+
if ('boolean' == typeof cleanUrls) {
|
|
66
|
+
url = normalizeHref(url, cleanUrls);
|
|
67
|
+
if (!routeService.isExistRoute(url)) {
|
|
68
|
+
deadLinks.set(nodeUrl, url);
|
|
69
|
+
return nodeUrl;
|
|
70
|
+
}
|
|
71
|
+
} else {
|
|
72
|
+
url = normalizeHref(url, false);
|
|
73
|
+
if (!routeService.isExistRoute(url)) {
|
|
74
|
+
deadLinks.set(nodeUrl, url);
|
|
75
|
+
return nodeUrl;
|
|
76
|
+
}
|
|
77
|
+
url = url.replace(/\.html$/, cleanUrls);
|
|
78
|
+
}
|
|
79
|
+
if (search) url += `?${search}`;
|
|
80
|
+
if (hash) url += `#${hash}`;
|
|
81
|
+
if (__base) url = withBase(url, __base);
|
|
82
|
+
return url;
|
|
83
|
+
}
|
|
84
|
+
const remarkLink = ({ cleanUrls, routeService, remarkLinkOptions, lint, __base })=>(tree, file)=>{
|
|
85
|
+
const { checkDeadLinks: shouldCheckDeadLinks = true, autoPrefix = true } = remarkLinkOptions ?? {};
|
|
86
|
+
const deadLinks = new Map();
|
|
87
|
+
visit(tree, 'link', (node)=>{
|
|
88
|
+
const { url: nodeUrl } = node;
|
|
89
|
+
const link = normalizeLink(nodeUrl, routeService, file.path, cleanUrls, autoPrefix, deadLinks, __base);
|
|
90
|
+
node.url = link;
|
|
91
|
+
});
|
|
92
|
+
visit(tree, 'definition', (node)=>{
|
|
93
|
+
const { url: nodeUrl } = node;
|
|
94
|
+
const link = normalizeLink(nodeUrl, routeService, file.path, cleanUrls, autoPrefix, deadLinks, __base);
|
|
95
|
+
node.url = link;
|
|
96
|
+
});
|
|
97
|
+
if (shouldCheckDeadLinks && routeService) link_checkDeadLinks(shouldCheckDeadLinks, deadLinks, file, lint);
|
|
98
|
+
};
|
|
99
|
+
export { remarkLink };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { extractTextAndId } from "../../../7805.cadab34e.js";
|
|
2
|
+
import { github_slugger, visitChildren } from "../loader.e1578c62.js";
|
|
3
|
+
const parseToc = (tree)=>{
|
|
4
|
+
let title = '';
|
|
5
|
+
const toc = [];
|
|
6
|
+
const slugger = new github_slugger();
|
|
7
|
+
visitChildren((node)=>{
|
|
8
|
+
if ('heading' !== node.type || !node.depth || !node.children) return;
|
|
9
|
+
if (node.depth >= 1 && node.depth < 5) {
|
|
10
|
+
let customId = '';
|
|
11
|
+
const text = node.children.map((child)=>{
|
|
12
|
+
if ('link' === child.type) return child.children?.map((item)=>item.value).join('');
|
|
13
|
+
if ('strong' === child.type) return `**${child.children?.map((item)=>item.value).join('')}**`;
|
|
14
|
+
if ('emphasis' === child.type) return `*${child.children?.map((item)=>item.value).join('')}*`;
|
|
15
|
+
if ('delete' === child.type) return `~~${child.children?.map((item)=>item.value).join('')}~~`;
|
|
16
|
+
if ('text' === child.type) {
|
|
17
|
+
const [textPart, idPart] = extractTextAndId(child.value);
|
|
18
|
+
customId = idPart;
|
|
19
|
+
return textPart;
|
|
20
|
+
}
|
|
21
|
+
if ('inlineCode' === child.type) return `\`${child.value}\``;
|
|
22
|
+
return '';
|
|
23
|
+
}).join('');
|
|
24
|
+
if (1 === node.depth) {
|
|
25
|
+
if (!title) title = text;
|
|
26
|
+
} else {
|
|
27
|
+
const id = customId ? customId : slugger.slug(text.trim());
|
|
28
|
+
const { depth } = node;
|
|
29
|
+
toc.push({
|
|
30
|
+
id,
|
|
31
|
+
text,
|
|
32
|
+
depth
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
})(tree);
|
|
37
|
+
return {
|
|
38
|
+
title,
|
|
39
|
+
toc
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
const remarkToc = function() {
|
|
43
|
+
const data = this.data();
|
|
44
|
+
return (tree)=>{
|
|
45
|
+
const { toc, title } = parseToc(tree);
|
|
46
|
+
data.pageMeta.toc = toc;
|
|
47
|
+
if (title) data.pageMeta.title = title;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
export { parseToc, remarkToc };
|
package/dist/node/mdx/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { FrontMatterMeta, UserConfig } from '@rspress/shared';
|
|
2
|
-
import type { PluginDriver } from '../PluginDriver';
|
|
3
|
-
import type { RouteService } from '../route/RouteService';
|
|
4
|
-
import type { TocItem } from './remarkPlugins/toc';
|
|
2
|
+
import type { PluginDriver } from '../PluginDriver.js';
|
|
3
|
+
import type { RouteService } from '../route/RouteService.js';
|
|
4
|
+
import type { TocItem } from './remarkPlugins/toc.js';
|
|
5
5
|
export interface MdxLoaderOptions {
|
|
6
6
|
config: UserConfig;
|
|
7
7
|
docDirectory: string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { node_path } from "../../6289.c67fe0d5.js";
|
|
2
|
+
import { PACKAGE_ROOT } from "../constants.js";
|
|
3
|
+
function pluginMediumZoom(options = {}) {
|
|
4
|
+
return {
|
|
5
|
+
name: '@rspress/plugin-medium-zoom',
|
|
6
|
+
globalUIComponents: [
|
|
7
|
+
[
|
|
8
|
+
node_path.join(PACKAGE_ROOT, './static/MediumZoom.tsx'),
|
|
9
|
+
options
|
|
10
|
+
]
|
|
11
|
+
]
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export { pluginMediumZoom };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { node_path } from "../../6289.c67fe0d5.js";
|
|
2
|
+
import { RouteService } from "./RouteService.js";
|
|
3
|
+
import { normalizePath, slash } from "../utils/normalizePath.js";
|
|
4
|
+
import { getPageKey } from "../utils/getPageKey.js";
|
|
5
|
+
class RoutePage {
|
|
6
|
+
routeMeta;
|
|
7
|
+
#docDir;
|
|
8
|
+
static create(absolutePath, docsDir) {
|
|
9
|
+
const routeMeta = absolutePathToRouteMeta(absolutePath, docsDir, RouteService.getInstance());
|
|
10
|
+
return new RoutePage(routeMeta, docsDir);
|
|
11
|
+
}
|
|
12
|
+
static createFromExternal(routePath, filepath, docDir) {
|
|
13
|
+
const routeMeta = RoutePage.generateRouteMeta(routePath, filepath, docDir);
|
|
14
|
+
return new RoutePage(routeMeta, node_path.dirname(filepath));
|
|
15
|
+
}
|
|
16
|
+
constructor(routeMeta, docDir){
|
|
17
|
+
this.routeMeta = routeMeta;
|
|
18
|
+
this.#docDir = docDir;
|
|
19
|
+
}
|
|
20
|
+
static generateRouteMeta(routePath, filepath, docDir) {
|
|
21
|
+
const routeService = RouteService.getInstance();
|
|
22
|
+
const { routePath: normalizedPath, lang, version } = routeService.normalizeRoutePath(routePath);
|
|
23
|
+
return {
|
|
24
|
+
routePath: normalizedPath,
|
|
25
|
+
absolutePath: normalizePath(filepath),
|
|
26
|
+
relativePath: absolutePathToRelativePath(filepath, docDir),
|
|
27
|
+
pageName: getPageKey(routePath),
|
|
28
|
+
lang,
|
|
29
|
+
version
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function absolutePathToRelativePath(absolutePath, docsDir) {
|
|
34
|
+
return slash(node_path.relative(docsDir, absolutePath));
|
|
35
|
+
}
|
|
36
|
+
function absolutePathToRouteMeta(absolutePath, docsDir, routeService = RouteService.getInstance()) {
|
|
37
|
+
const relativePath = absolutePathToRelativePath(absolutePath, docsDir);
|
|
38
|
+
const { lang, routePath, version } = routeService.normalizeRoutePath(relativePath);
|
|
39
|
+
return {
|
|
40
|
+
pageName: getPageKey(relativePath),
|
|
41
|
+
absolutePath,
|
|
42
|
+
lang,
|
|
43
|
+
version,
|
|
44
|
+
routePath,
|
|
45
|
+
relativePath
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function absolutePathToRoutePath(absolutePath, docsDir, routeService = RouteService.getInstance()) {
|
|
49
|
+
return absolutePathToRouteMeta(absolutePath, docsDir, routeService).routePath;
|
|
50
|
+
}
|
|
51
|
+
function absolutePathToRoutePrefix(absolutePath, docsDir) {
|
|
52
|
+
const relativePath = slash(node_path.relative(docsDir, absolutePath.replace(node_path.extname(absolutePath), '')));
|
|
53
|
+
const routeService = RouteService.getInstance();
|
|
54
|
+
const [versionPrefix, langPrefix] = routeService.getRoutePathParts(relativePath);
|
|
55
|
+
return `${versionPrefix ? `/${versionPrefix}` : ''}${langPrefix ? `/${langPrefix}` : ''}`;
|
|
56
|
+
}
|
|
57
|
+
function addRoutePrefix(workDir, docsDir, link) {
|
|
58
|
+
const routePrefix = absolutePathToRoutePrefix(workDir, docsDir);
|
|
59
|
+
return `${routePrefix.replace(/\/$/, '')}/${link.replace(/^\//, '')}`;
|
|
60
|
+
}
|
|
61
|
+
export { RoutePage, absolutePathToRelativePath, absolutePathToRoutePath, addRoutePrefix };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type AdditionalPage, type PageModule, type RouteMeta, type UserConfig } from '@rspress/shared';
|
|
2
2
|
import type { ComponentType } from 'react';
|
|
3
|
-
import { RoutePage } from './RoutePage';
|
|
3
|
+
import { RoutePage } from './RoutePage.js';
|
|
4
4
|
interface InitOptions {
|
|
5
5
|
scanDir: string;
|
|
6
6
|
config: UserConfig;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { node_path, promises } from "../../6289.c67fe0d5.js";
|
|
2
|
+
import { RSPRESS_TEMP_DIR, removeTrailingSlash, addTrailingSlash } from "../../4669.12208c6a.js";
|
|
3
|
+
import { DEFAULT_PAGE_EXTENSIONS, glob } from "../../5313.6594aba0.js";
|
|
4
|
+
import { PUBLIC_DIR } from "../constants.js";
|
|
5
|
+
import { RoutePage, absolutePathToRoutePath, absolutePathToRelativePath } from "./RoutePage.js";
|
|
6
|
+
import { createError } from "../utils/error.js";
|
|
7
|
+
import { getRoutePathParts, normalizeRoutePath, splitRoutePathParts } from "./normalizeRoutePath.js";
|
|
8
|
+
class RouteService {
|
|
9
|
+
routeData = new Map();
|
|
10
|
+
#scanDir;
|
|
11
|
+
#defaultLang;
|
|
12
|
+
#defaultVersion;
|
|
13
|
+
#extensions;
|
|
14
|
+
#langs;
|
|
15
|
+
#versions;
|
|
16
|
+
#include;
|
|
17
|
+
#exclude;
|
|
18
|
+
#excludeConvention;
|
|
19
|
+
#tempDir;
|
|
20
|
+
#externalPages;
|
|
21
|
+
static __instance__ = null;
|
|
22
|
+
static getInstance() {
|
|
23
|
+
return RouteService.__instance__;
|
|
24
|
+
}
|
|
25
|
+
static async create(options) {
|
|
26
|
+
const { scanDir, config, externalPages } = options;
|
|
27
|
+
const runtimeAbsTempDir = node_path.join(process.cwd(), 'node_modules', RSPRESS_TEMP_DIR, 'runtime');
|
|
28
|
+
await promises.mkdir(runtimeAbsTempDir, {
|
|
29
|
+
recursive: true
|
|
30
|
+
});
|
|
31
|
+
const routeService = new RouteService(scanDir, config, externalPages || [], runtimeAbsTempDir);
|
|
32
|
+
RouteService.__instance__ = routeService;
|
|
33
|
+
await routeService.#init();
|
|
34
|
+
return routeService;
|
|
35
|
+
}
|
|
36
|
+
static async createSimple() {
|
|
37
|
+
return new RouteService('', {}, [], '');
|
|
38
|
+
}
|
|
39
|
+
constructor(scanDir, userConfig, externalPages, runtimeAbsTempDir){
|
|
40
|
+
const routeOptions = userConfig?.route || {};
|
|
41
|
+
this.#scanDir = scanDir;
|
|
42
|
+
this.#extensions = routeOptions.extensions || DEFAULT_PAGE_EXTENSIONS;
|
|
43
|
+
this.#include = routeOptions.include || [];
|
|
44
|
+
this.#exclude = routeOptions.exclude || [];
|
|
45
|
+
this.#excludeConvention = routeOptions.excludeConvention || [
|
|
46
|
+
'**/_[^_]*'
|
|
47
|
+
];
|
|
48
|
+
this.#defaultLang = userConfig?.lang || '';
|
|
49
|
+
this.#langs = (userConfig?.locales ?? userConfig?.themeConfig?.locales ?? []).map((item)=>item.lang);
|
|
50
|
+
this.#tempDir = runtimeAbsTempDir;
|
|
51
|
+
this.#externalPages = externalPages;
|
|
52
|
+
if (userConfig.multiVersion) {
|
|
53
|
+
this.#defaultVersion = userConfig.multiVersion.default || '';
|
|
54
|
+
this.#versions = userConfig.multiVersion.versions || [];
|
|
55
|
+
} else {
|
|
56
|
+
this.#defaultVersion = '';
|
|
57
|
+
this.#versions = [];
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
get extensions() {
|
|
61
|
+
return this.#extensions;
|
|
62
|
+
}
|
|
63
|
+
async #init() {
|
|
64
|
+
const extensions = this.#extensions.map((i)=>i.slice(1));
|
|
65
|
+
const files = (await glob([
|
|
66
|
+
`**/*.{${extensions.join(',')}}`,
|
|
67
|
+
...this.#include
|
|
68
|
+
], {
|
|
69
|
+
cwd: this.#scanDir,
|
|
70
|
+
absolute: true,
|
|
71
|
+
onlyFiles: true,
|
|
72
|
+
ignore: [
|
|
73
|
+
...this.#exclude,
|
|
74
|
+
...this.#excludeConvention,
|
|
75
|
+
'**/node_modules/**',
|
|
76
|
+
'**/.eslintrc.js',
|
|
77
|
+
'**/.nx/**',
|
|
78
|
+
`./${PUBLIC_DIR}/**`,
|
|
79
|
+
'**/*.d.ts'
|
|
80
|
+
]
|
|
81
|
+
})).sort();
|
|
82
|
+
files.forEach((filePath)=>{
|
|
83
|
+
const routePage = RoutePage.create(filePath, this.#scanDir);
|
|
84
|
+
this.addRoute(routePage);
|
|
85
|
+
});
|
|
86
|
+
const externalPages = this.#externalPages;
|
|
87
|
+
await Promise.all(externalPages.map(async (route, index)=>{
|
|
88
|
+
const { routePath, content, filepath } = route;
|
|
89
|
+
if (filepath) {
|
|
90
|
+
const routePage = RoutePage.createFromExternal(routePath, filepath, this.#scanDir);
|
|
91
|
+
this.addRoute(routePage);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (content) {
|
|
95
|
+
const filepath = await this.#writeTempFile(index, content);
|
|
96
|
+
const routePage = RoutePage.createFromExternal(routePath, filepath, this.#scanDir);
|
|
97
|
+
this.addRoute(routePage);
|
|
98
|
+
}
|
|
99
|
+
}));
|
|
100
|
+
}
|
|
101
|
+
async addRoute(routePage) {
|
|
102
|
+
const { routeMeta: { routePath } } = routePage;
|
|
103
|
+
if (this.routeData.has(routePath)) throw createError(`routePath ${routePath} has already been added`);
|
|
104
|
+
this.routeData.set(routePath, routePage);
|
|
105
|
+
}
|
|
106
|
+
getRoutes() {
|
|
107
|
+
return Array.from(this.routeData.values()).map((i)=>i.routeMeta);
|
|
108
|
+
}
|
|
109
|
+
getRoutePages() {
|
|
110
|
+
return Array.from(this.routeData.values());
|
|
111
|
+
}
|
|
112
|
+
isExistRoute(link) {
|
|
113
|
+
function linkToRoutePath(routePath) {
|
|
114
|
+
return decodeURIComponent(routePath.split('#')[0]).replace(/\.html$/, '').replace(/\/index$/, '/');
|
|
115
|
+
}
|
|
116
|
+
const cleanLinkPath = linkToRoutePath(link);
|
|
117
|
+
if (!this.routeData.has(removeTrailingSlash(cleanLinkPath)) && !this.routeData.has(addTrailingSlash(cleanLinkPath))) return false;
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
generateRoutesCode() {
|
|
121
|
+
return this.generateRoutesCodeByRouteMeta(this.getRoutes());
|
|
122
|
+
}
|
|
123
|
+
generateRoutesCodeByRouteMeta(routeMeta) {
|
|
124
|
+
return `
|
|
125
|
+
import React from 'react';
|
|
126
|
+
import { lazyWithPreload } from "react-lazy-with-preload";
|
|
127
|
+
${routeMeta.map((route, index)=>`const Route${index} = lazyWithPreload(() => import('${route.absolutePath}'))`).join('\n')}
|
|
128
|
+
export const routes = [
|
|
129
|
+
${routeMeta.map((route, index)=>{
|
|
130
|
+
const preload = `async () => {
|
|
131
|
+
await Route${index}.preload();
|
|
132
|
+
return import("${route.absolutePath}");
|
|
133
|
+
}`;
|
|
134
|
+
const component = `Route${index}`;
|
|
135
|
+
return `{ path: '${route.routePath}', element: React.createElement(${component}), filePath: '${route.relativePath}', preload: ${preload}, lang: '${route.lang}', version: '${route.version}' }`;
|
|
136
|
+
}).join(',\n')}
|
|
137
|
+
];
|
|
138
|
+
`;
|
|
139
|
+
}
|
|
140
|
+
getRoutePathParts(relativePath) {
|
|
141
|
+
return getRoutePathParts(relativePath, this.#defaultLang, this.#defaultVersion, this.#langs, this.#versions);
|
|
142
|
+
}
|
|
143
|
+
splitRoutePathParts(relativePath) {
|
|
144
|
+
return splitRoutePathParts(relativePath, this.#defaultLang, this.#defaultVersion, this.#langs, this.#versions);
|
|
145
|
+
}
|
|
146
|
+
normalizeRoutePath(relativePath) {
|
|
147
|
+
return normalizeRoutePath(relativePath, this.#defaultLang, this.#defaultVersion, this.#langs, this.#versions, this.#extensions);
|
|
148
|
+
}
|
|
149
|
+
absolutePathToRoutePath(absolutePath) {
|
|
150
|
+
return absolutePathToRoutePath(absolutePath, this.#scanDir, this);
|
|
151
|
+
}
|
|
152
|
+
isInDocsDir(absolutePath) {
|
|
153
|
+
const relativePath = node_path.relative(this.#scanDir, absolutePath);
|
|
154
|
+
return !relativePath.startsWith('..') && !node_path.isAbsolute(relativePath);
|
|
155
|
+
}
|
|
156
|
+
absolutePathToRelativePath(absolutePath) {
|
|
157
|
+
return absolutePathToRelativePath(absolutePath, this.#scanDir);
|
|
158
|
+
}
|
|
159
|
+
async #writeTempFile(index, content) {
|
|
160
|
+
const tempFilePath = node_path.join(this.#tempDir, `temp-${index}.mdx`);
|
|
161
|
+
await promises.writeFile(tempFilePath, content);
|
|
162
|
+
return tempFilePath;
|
|
163
|
+
}
|
|
164
|
+
getRoutePageByRoutePath(routePath) {
|
|
165
|
+
return this.routeData.get(routePath);
|
|
166
|
+
}
|
|
167
|
+
getDocsDir() {
|
|
168
|
+
return this.#scanDir;
|
|
169
|
+
}
|
|
170
|
+
getLangs() {
|
|
171
|
+
return this.#langs;
|
|
172
|
+
}
|
|
173
|
+
getDefaultLang() {
|
|
174
|
+
return this.#defaultLang;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
export { RouteService };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type PageIndexInfo, type ReplaceRule, type RouteMeta } from '@rspress/shared';
|
|
2
|
-
import type { RouteService } from './RouteService';
|
|
2
|
+
import type { RouteService } from './RouteService.js';
|
|
3
3
|
interface ExtractPageDataOptions {
|
|
4
4
|
root: string;
|
|
5
5
|
searchCodeBlocks: boolean;
|