@rspress/core 2.0.14 → 2.0.16
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/dist/0~execa.js +1 -1
- package/dist/3358.js +1 -1
- package/dist/5580.js +1 -1
- package/dist/{4942.js → 6010.js} +1 -1
- package/dist/8005.js +1 -1
- package/dist/{7261.js → 9958.js} +2 -1
- package/dist/cli/index.js +6 -6
- package/dist/eject-theme/components/Callout/index.scss +32 -0
- package/dist/eject-theme/components/Callout/index.tsx +9 -1
- package/dist/eject-theme/components/DocContent/doc.scss +2 -2
- package/dist/eject-theme/components/HomeBackground/useNavTransparent.tsx +2 -2
- package/dist/eject-theme/components/HoverGroup/index.scss +1 -1
- package/dist/eject-theme/components/LastUpdated/index.tsx +8 -2
- package/dist/eject-theme/components/Link/useLinkNavigate.ts +1 -1
- package/dist/eject-theme/components/Llms/LlmsContainer.tsx +1 -1
- package/dist/eject-theme/components/Nav/NavMenu.scss +1 -1
- package/dist/eject-theme/components/Nav/hooks.tsx +18 -14
- package/dist/eject-theme/components/Nav/index.tsx +4 -1
- package/dist/eject-theme/components/NavScreen/NavScreenAppearance.tsx +4 -1
- package/dist/eject-theme/components/NavScreen/NavScreenMenuItem.scss +3 -0
- package/dist/eject-theme/components/NavScreen/NavScreenMenuOthers.tsx +4 -1
- package/dist/eject-theme/components/Overview/index.tsx +1 -2
- package/dist/eject-theme/components/Overview/utils.ts +4 -10
- package/dist/eject-theme/components/Search/SearchPanel.tsx +23 -17
- package/dist/eject-theme/components/Search/logic/providers/LocalProvider.ts +3 -1
- package/dist/eject-theme/components/SidebarMenu/useClickOutside.ts +1 -2
- package/dist/index.d.ts +1 -1
- package/dist/node/PluginDriver.js +4 -4
- package/dist/node/auto-nav-sidebar/index.js +1 -1
- package/dist/node/auto-nav-sidebar/locales.js +1 -1
- package/dist/node/auto-nav-sidebar/normalize.js +1 -1
- package/dist/node/auto-nav-sidebar/utils.js +1 -1
- package/dist/node/auto-nav-sidebar/walk.d.ts +4 -2
- package/dist/node/auto-nav-sidebar/walk.js +3 -3
- package/dist/node/constants.d.ts +2 -1
- package/dist/node/constants.js +12 -6
- package/dist/node/initRsbuild.js +8 -15
- package/dist/node/last-updated/index.d.ts +3 -3
- package/dist/node/last-updated/index.js +24 -9
- package/dist/node/mdx/options.js +8 -1
- package/dist/node/mdx/processor.js +3 -1
- package/dist/node/mdx/rehypePlugins/headerAnchor.d.ts +1 -1
- package/dist/node/mdx/rehypePlugins/headerAnchor.js +10 -6
- package/dist/node/mdx/remarkPlugins/containerSyntax.d.ts +2 -1
- package/dist/node/mdx/remarkPlugins/containerSyntax.js +13 -6
- package/dist/node/mdx/remarkPlugins/link.js +91 -16
- package/dist/node/mdx/remarkPlugins/toc.d.ts +8 -1
- package/dist/node/mdx/remarkPlugins/toc.js +44 -15
- package/dist/node/route/RoutePage.js +1 -1
- package/dist/node/route/RouteService.d.ts +6 -0
- package/dist/node/route/RouteService.js +41 -7
- package/dist/node/route/extractPageData.js +1 -1
- package/dist/node/route/normalizeRoutePath.js +1 -1
- package/dist/node/runtimeModule/DEFAULT_I18N_TEXT.d.ts +7 -0
- package/dist/node/runtimeModule/DEFAULT_I18N_TEXT.js +7 -0
- package/dist/node/runtimeModule/i18n.js +1 -1
- package/dist/node/runtimeModule/pageData/createPageData.js +2 -1
- package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +1 -1
- package/dist/node/runtimeModule/searchHooks.js +1 -1
- package/dist/node/runtimeModule/siteData/createSiteData.js +1 -1
- package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +12 -2
- package/dist/node/runtimeModule/siteData/rsbuildPlugin.js +1 -1
- package/dist/node/serve.js +1 -1
- package/dist/node/ssg/htmlFile.js +1 -1
- package/dist/node/ssg/renderPage.js +1 -1
- package/dist/node/ssg/renderPageWorker.js +1 -1
- package/dist/node/ssg/renderPages.js +2 -2
- package/dist/node/ssg/rsbuildPluginCSR.js +2 -1
- package/dist/node/ssg/rsbuildPluginSSG.js +5 -3
- package/dist/node/ssg/ssgEnv.js +1 -1
- package/dist/node/ssg-md/llms/emitLlmsTxt.js +1 -1
- package/dist/node/ssg-md/llms/llmsTxt.js +1 -1
- package/dist/node/ssg-md/renderPage.js +1 -1
- package/dist/node/ssg-md/renderPages.js +2 -2
- package/dist/node/ssg-md/rsbuildPluginSSGMD.js +3 -2
- package/dist/node/utils/checkLanguageParity.js +1 -1
- package/dist/node/utils/createHash.js +1 -1
- package/dist/node/utils/flattenMdxContent.js +1 -1
- package/dist/node/utils/getPageKey.js +1 -1
- package/dist/node/utils/reactAlias.js +1 -1
- package/dist/runtime/App.d.ts +2 -1
- package/dist/runtime/App.js +1 -1
- package/dist/runtime/ClientApp.d.ts +1 -1
- package/dist/runtime/ClientApp.js +2 -1
- package/dist/runtime/Content.d.ts +1 -1
- package/dist/runtime/NoSSR.d.ts +1 -1
- package/dist/theme/components/Badge/index.d.ts +1 -1
- package/dist/theme/components/Callout/index.css +29 -0
- package/dist/theme/components/Callout/index.d.ts +1 -1
- package/dist/theme/components/CodeBlock/index.d.ts +1 -1
- package/dist/theme/components/CodeButtonGroup/CopyCodeButton.d.ts +1 -1
- package/dist/theme/components/CodeButtonGroup/index.d.ts +1 -1
- package/dist/theme/components/DocContent/doc.css +2 -2
- package/dist/theme/components/DocContent/docComponents/a.d.ts +1 -1
- package/dist/theme/components/DocContent/docComponents/code.d.ts +1 -1
- package/dist/theme/components/DocContent/docComponents/hr.d.ts +1 -1
- package/dist/theme/components/DocContent/docComponents/img.d.ts +1 -1
- package/dist/theme/components/DocContent/docComponents/index.d.ts +18 -18
- package/dist/theme/components/DocContent/docComponents/list.d.ts +3 -3
- package/dist/theme/components/DocContent/docComponents/paragraph.d.ts +3 -3
- package/dist/theme/components/DocContent/docComponents/pre.d.ts +1 -1
- package/dist/theme/components/DocContent/docComponents/table.d.ts +3 -3
- package/dist/theme/components/DocContent/docComponents/title.d.ts +6 -6
- package/dist/theme/components/DocContent/index.d.ts +1 -1
- package/dist/theme/components/DocFooter/index.d.ts +1 -1
- package/dist/theme/components/EditLink/index.d.ts +1 -1
- package/dist/theme/components/FallbackHeading/index.d.ts +1 -1
- package/dist/theme/components/HomeBackground/index.d.ts +1 -1
- package/dist/theme/components/HomeBackground/useNavTransparent.d.ts +1 -1
- package/dist/theme/components/HomeBackground/useNavTransparent.js +2 -2
- package/dist/theme/components/HomeFeature/useCardAnimation.d.ts +1 -1
- package/dist/theme/components/HomeFooter/index.d.ts +1 -1
- package/dist/theme/components/HomeHero/index.d.ts +1 -1
- package/dist/theme/components/HoverGroup/index.css +1 -1
- package/dist/theme/components/HoverGroup/index.d.ts +1 -1
- package/dist/theme/components/HoverGroup/useHoverGroup.d.ts +1 -1
- package/dist/theme/components/LastUpdated/index.d.ts +1 -1
- package/dist/theme/components/LastUpdated/index.js +13 -3
- package/dist/theme/components/Link/useLinkNavigate.js +1 -1
- package/dist/theme/components/Llms/LlmsContainer.d.ts +2 -3
- package/dist/theme/components/Llms/LlmsCopyButton.d.ts +1 -1
- package/dist/theme/components/Llms/LlmsCopyRow.d.ts +1 -1
- package/dist/theme/components/Llms/LlmsOpenRow.d.ts +1 -1
- package/dist/theme/components/Llms/LlmsViewOptions.d.ts +1 -1
- package/dist/theme/components/Nav/NavMenu.css +1 -1
- package/dist/theme/components/Nav/NavMenu.d.ts +9 -9
- package/dist/theme/components/Nav/hooks.js +6 -3
- package/dist/theme/components/Nav/index.d.ts +1 -1
- package/dist/theme/components/Nav/index.js +2 -1
- package/dist/theme/components/NavHamburger/index.d.ts +1 -1
- package/dist/theme/components/NavScreen/NavScreenAppearance.d.ts +1 -1
- package/dist/theme/components/NavScreen/NavScreenAppearance.js +2 -1
- package/dist/theme/components/NavScreen/NavScreenLangs.d.ts +1 -1
- package/dist/theme/components/NavScreen/NavScreenMenu.d.ts +1 -1
- package/dist/theme/components/NavScreen/NavScreenMenuItem.css +10 -1
- package/dist/theme/components/NavScreen/NavScreenMenuItem.d.ts +5 -5
- package/dist/theme/components/NavScreen/NavScreenMenuOthers.d.ts +1 -1
- package/dist/theme/components/NavScreen/NavScreenMenuOthers.js +2 -1
- package/dist/theme/components/NavScreen/NavScreenVersions.d.ts +1 -1
- package/dist/theme/components/NavScreen/index.d.ts +2 -2
- package/dist/theme/components/NavTitle/index.d.ts +1 -1
- package/dist/theme/components/Outline/ScrollToTop.d.ts +1 -1
- package/dist/theme/components/Outline/index.d.ts +1 -1
- package/dist/theme/components/Overview/index.d.ts +1 -1
- package/dist/theme/components/OverviewGroup/index.d.ts +1 -1
- package/dist/theme/components/PackageManagerTabs/icons/Bun.d.ts +1 -1
- package/dist/theme/components/PackageManagerTabs/icons/Deno.d.ts +1 -1
- package/dist/theme/components/PackageManagerTabs/icons/Npm.d.ts +1 -1
- package/dist/theme/components/PackageManagerTabs/icons/Pnpm.d.ts +1 -1
- package/dist/theme/components/PackageManagerTabs/icons/Yarn.d.ts +1 -1
- package/dist/theme/components/PackageManagerTabs/index.d.ts +1 -1
- package/dist/theme/components/PrevNextPage/index.d.ts +1 -1
- package/dist/theme/components/Prompt/index.d.ts +1 -1
- package/dist/theme/components/ReadPercent/index.d.ts +1 -1
- package/dist/theme/components/Root/index.d.ts +1 -1
- package/dist/theme/components/Search/NoSearchResult.d.ts +1 -1
- package/dist/theme/components/Search/SearchButton.d.ts +1 -1
- package/dist/theme/components/Search/SearchPanel.d.ts +1 -1
- package/dist/theme/components/Search/SearchPanel.js +11 -7
- package/dist/theme/components/Search/SuggestItem.d.ts +1 -1
- package/dist/theme/components/Search/index.d.ts +1 -1
- package/dist/theme/components/Sidebar/SidebarDivider.d.ts +1 -1
- package/dist/theme/components/Sidebar/SidebarGroup.d.ts +1 -1
- package/dist/theme/components/Sidebar/SidebarItem.d.ts +2 -2
- package/dist/theme/components/Sidebar/SidebarSectionHeader.d.ts +1 -1
- package/dist/theme/components/Sidebar/index.d.ts +2 -2
- package/dist/theme/components/SidebarMenu/useSidebarMenu.d.ts +1 -1
- package/dist/theme/components/SocialLinks/GithubStars.d.ts +1 -1
- package/dist/theme/components/SocialLinks/SocialLink.d.ts +1 -1
- package/dist/theme/components/SocialLinks/index.d.ts +1 -1
- package/dist/theme/components/SourceCode/index.d.ts +1 -1
- package/dist/theme/components/Steps/index.d.ts +1 -1
- package/dist/theme/components/SvgWrapper/index.d.ts +1 -1
- package/dist/theme/components/SwitchAppearance/index.d.ts +1 -1
- package/dist/theme/components/Tag/index.d.ts +1 -1
- package/dist/theme/components/Toc/TocItem.d.ts +1 -1
- package/dist/theme/components/Toc/index.d.ts +1 -1
- package/dist/theme/layout/DocLayout/index.d.ts +1 -1
- package/dist/theme/layout/HomeLayout/index.d.ts +1 -1
- package/dist/theme/layout/Layout/index.d.ts +1 -1
- package/dist/theme/layout/NotFountLayout/index.d.ts +1 -1
- package/dist/theme/logic/useThemeState.d.ts +6 -7
- package/dist/theme/logic/useThemeState.js +19 -15
- package/package.json +19 -19
package/dist/node/constants.js
CHANGED
|
@@ -1,17 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isDarkModeSwitchEnabled, node_path, package_namespaceObject, getDefaultDarkModeValue, createRequire } from "../9958.js";
|
|
2
2
|
const constants_require = createRequire(import.meta.url);
|
|
3
3
|
const RSPRESS_VERSION = package_namespaceObject.rE;
|
|
4
4
|
const APPEARANCE_KEY = 'rspress-theme-appearance';
|
|
5
5
|
const isProduction = ()=>'production' === process.env.NODE_ENV;
|
|
6
6
|
const importStatementRegex = /import\s+(.*?)\s+from\s+(['"])(.*?)(?:"|');?/gm;
|
|
7
|
-
const
|
|
8
|
-
|
|
7
|
+
const getInlineThemeScript = (darkMode)=>{
|
|
8
|
+
const defaultTheme = getDefaultDarkModeValue(darkMode);
|
|
9
|
+
const shouldReadStorage = isDarkModeSwitchEnabled(darkMode);
|
|
10
|
+
return `{
|
|
11
|
+
const saved = ${shouldReadStorage ? `localStorage.getItem('${APPEARANCE_KEY}')` : 'null'}
|
|
9
12
|
const preferDark = window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
10
|
-
const
|
|
13
|
+
const defaultTheme = '${defaultTheme}'
|
|
14
|
+
const theme = saved === 'light' || saved === 'dark' || saved === 'auto' ? saved : defaultTheme
|
|
15
|
+
const isDark = theme === 'auto' ? preferDark : theme === 'dark'
|
|
11
16
|
document.documentElement.classList.toggle('dark', isDark)
|
|
12
17
|
document.documentElement.classList.toggle('rp-dark', isDark)
|
|
13
18
|
document.documentElement.style.colorScheme = isDark ? 'dark' : 'light'
|
|
14
19
|
}`.replace(/\n/g, ';').replace(/\s{2,}/g, '');
|
|
20
|
+
};
|
|
15
21
|
const PACKAGE_ROOT = node_path.dirname(constants_require.resolve('@rspress/core/package.json'));
|
|
16
22
|
const DEFAULT_THEME = node_path.join(PACKAGE_ROOT, 'dist/theme');
|
|
17
23
|
const EJECTED_THEME = node_path.join(PACKAGE_ROOT, 'dist/eject-theme');
|
|
@@ -25,9 +31,9 @@ const APP_HTML_MARKER = '<!--<?- DOC_CONTENT ?>-->';
|
|
|
25
31
|
const HEAD_MARKER = '<!--<?- HEAD ?>-->';
|
|
26
32
|
const META_GENERATOR = '<!--<?- GENERATOR ?>-->';
|
|
27
33
|
const DEFAULT_TITLE = 'Rspress';
|
|
34
|
+
const PUBLIC_DIR = 'public';
|
|
28
35
|
const NODE_SSG_BUNDLE_FOLDER = '__ssg__';
|
|
29
36
|
const NODE_SSG_BUNDLE_NAME = 'rspress-ssg-entry.cjs';
|
|
30
37
|
const NODE_SSG_MD_BUNDLE_FOLDER = '__ssg_md__';
|
|
31
38
|
const NODE_SSG_MD_BUNDLE_NAME = 'rspress-ssg-md-entry.cjs';
|
|
32
|
-
|
|
33
|
-
export { APP_HTML_MARKER, CSR_CLIENT_ENTRY, DEFAULT_THEME, DEFAULT_TITLE, EJECTED_THEME, HEAD_MARKER, META_GENERATOR, NODE_SSG_BUNDLE_FOLDER, NODE_SSG_BUNDLE_NAME, NODE_SSG_MD_BUNDLE_FOLDER, NODE_SSG_MD_BUNDLE_NAME, OUTPUT_DIR, PACKAGE_ROOT, RSPRESS_VERSION, SSG_MD_SERVER_ENTRY, SSR_CLIENT_ENTRY, SSR_SERVER_ENTRY, TEMPLATE_PATH, constants_PUBLIC_DIR as PUBLIC_DIR, importStatementRegex, inlineThemeScript, isProduction };
|
|
39
|
+
export { APP_HTML_MARKER, CSR_CLIENT_ENTRY, DEFAULT_THEME, DEFAULT_TITLE, EJECTED_THEME, HEAD_MARKER, META_GENERATOR, NODE_SSG_BUNDLE_FOLDER, NODE_SSG_BUNDLE_NAME, NODE_SSG_MD_BUNDLE_FOLDER, NODE_SSG_MD_BUNDLE_NAME, OUTPUT_DIR, PACKAGE_ROOT, PUBLIC_DIR, RSPRESS_VERSION, SSG_MD_SERVER_ENTRY, SSR_CLIENT_ENTRY, SSR_SERVER_ENTRY, TEMPLATE_PATH, getInlineThemeScript, importStatementRegex, isProduction };
|
package/dist/node/initRsbuild.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { external_node_process_cwd, node_path, external_node_url_fileURLToPath, addTrailingSlash, PLUGIN_REACT_NAME, external_node_module_createRequire, removeTrailingSlash,
|
|
1
|
+
import { external_node_process_cwd, node_path, external_node_url_fileURLToPath, addTrailingSlash, PLUGIN_REACT_NAME, external_node_module_createRequire, removeTrailingSlash, normalizeDarkMode, pluginReact, pluginVirtualModule, MDX_OR_MD_REGEXP } from "../6010.js";
|
|
2
2
|
import { createError } from "./utils/error.js";
|
|
3
|
-
import { CSR_CLIENT_ENTRY, SSR_CLIENT_ENTRY, OUTPUT_DIR, SSG_MD_SERVER_ENTRY,
|
|
3
|
+
import { CSR_CLIENT_ENTRY, SSR_CLIENT_ENTRY, OUTPUT_DIR, SSG_MD_SERVER_ENTRY, NODE_SSG_BUNDLE_FOLDER, isProduction, PACKAGE_ROOT, SSR_SERVER_ENTRY, TEMPLATE_PATH, NODE_SSG_MD_BUNDLE_FOLDER, DEFAULT_THEME, NODE_SSG_MD_BUNDLE_NAME, getInlineThemeScript, DEFAULT_TITLE, NODE_SSG_BUNDLE_NAME } from "./constants.js";
|
|
4
4
|
import { hintBuilderPluginsBreakingChange, hintThemeBreakingChange } from "./logger/hint.js";
|
|
5
5
|
import { resolveReactRouterDomAlias, resolveReactRenderToMarkdownAlias, resolveReactAlias } from "./utils/reactAlias.js";
|
|
6
6
|
import { rsbuildPluginDocVM } from "./runtimeModule/pageData/rsbuildPlugin.js";
|
|
@@ -14,7 +14,7 @@ import { siteDataVMPlugin } from "./runtimeModule/siteData/rsbuildPlugin.js";
|
|
|
14
14
|
import { rsbuildPluginSSG } from "./ssg/rsbuildPluginSSG.js";
|
|
15
15
|
import { rsbuildPluginCSR } from "./ssg/rsbuildPluginCSR.js";
|
|
16
16
|
import { rsbuildPluginSSGMD } from "./ssg-md/rsbuildPluginSSGMD.js";
|
|
17
|
-
import { package_namespaceObject } from "../
|
|
17
|
+
import { package_namespaceObject } from "../9958.js";
|
|
18
18
|
function isPluginIncluded(config, pluginName) {
|
|
19
19
|
return Boolean(config.builderConfig?.plugins?.some((plugin)=>plugin && plugin.name === pluginName));
|
|
20
20
|
}
|
|
@@ -116,9 +116,9 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
116
116
|
favicon: normalizeIcon(config?.icon),
|
|
117
117
|
template: TEMPLATE_PATH,
|
|
118
118
|
tags: [
|
|
119
|
-
config.themeConfig?.darkMode
|
|
119
|
+
'force-light' !== normalizeDarkMode(config.themeConfig?.darkMode) ? {
|
|
120
120
|
tag: "script",
|
|
121
|
-
children:
|
|
121
|
+
children: getInlineThemeScript(config.themeConfig?.darkMode),
|
|
122
122
|
append: false
|
|
123
123
|
} : null
|
|
124
124
|
].filter(Boolean)
|
|
@@ -162,6 +162,9 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
162
162
|
}
|
|
163
163
|
},
|
|
164
164
|
performance: {
|
|
165
|
+
printFileSize: {
|
|
166
|
+
compressed: true
|
|
167
|
+
},
|
|
165
168
|
...'false' !== process.env.RSPRESS_PERSISTENT_CACHE ? {
|
|
166
169
|
buildCache: {
|
|
167
170
|
buildDependencies: [
|
|
@@ -293,11 +296,6 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
293
296
|
'import.meta.env.SSG_MD': JSON.stringify(false)
|
|
294
297
|
}
|
|
295
298
|
},
|
|
296
|
-
performance: {
|
|
297
|
-
printFileSize: {
|
|
298
|
-
compressed: true
|
|
299
|
-
}
|
|
300
|
-
},
|
|
301
299
|
tools: {
|
|
302
300
|
rspack: {
|
|
303
301
|
optimization: NODE_RSPACK_OPTIMIZATION
|
|
@@ -335,11 +333,6 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
335
333
|
'import.meta.env.SSG_MD': JSON.stringify(true)
|
|
336
334
|
}
|
|
337
335
|
},
|
|
338
|
-
performance: {
|
|
339
|
-
printFileSize: {
|
|
340
|
-
compressed: true
|
|
341
|
-
}
|
|
342
|
-
},
|
|
343
336
|
output: {
|
|
344
337
|
emitAssets: false,
|
|
345
338
|
target: 'node',
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { RspressPlugin } from '@rspress/shared';
|
|
1
|
+
import type { LastUpdatedAuthor, RspressPlugin } from '@rspress/shared';
|
|
2
2
|
/**
|
|
3
|
-
* The plugin is used to add the last updated time to the page.
|
|
3
|
+
* The plugin is used to add the last updated time and author to the page.
|
|
4
4
|
*/
|
|
5
|
-
export declare function pluginLastUpdated(): RspressPlugin;
|
|
5
|
+
export declare function pluginLastUpdated(authorOption?: LastUpdatedAuthor): RspressPlugin;
|
|
@@ -2,26 +2,41 @@ import { execa } from "../../0~execa.js";
|
|
|
2
2
|
function transform(timestamp, lang) {
|
|
3
3
|
return new Date(timestamp).toLocaleString(lang || 'zh');
|
|
4
4
|
}
|
|
5
|
-
async function
|
|
6
|
-
let lastUpdated;
|
|
5
|
+
async function getGitInfo(filePath) {
|
|
7
6
|
try {
|
|
8
7
|
const { stdout } = await execa('git', [
|
|
9
8
|
'log',
|
|
10
9
|
'-1',
|
|
11
|
-
'--format=%at',
|
|
10
|
+
'--format=%at%n%an%n%ae',
|
|
11
|
+
'--',
|
|
12
12
|
filePath
|
|
13
13
|
]);
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
const [at, an, ae] = stdout.split('\n');
|
|
15
|
+
if (!at) return;
|
|
16
|
+
return {
|
|
17
|
+
timestamp: 1000 * Number(at),
|
|
18
|
+
authorName: an ?? '',
|
|
19
|
+
authorEmail: ae ?? ''
|
|
20
|
+
};
|
|
21
|
+
} catch (_e) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
17
24
|
}
|
|
18
|
-
function pluginLastUpdated() {
|
|
25
|
+
function pluginLastUpdated(authorOption = false) {
|
|
19
26
|
return {
|
|
20
27
|
name: '@rspress/plugin-last-updated',
|
|
21
28
|
async extendPageData (pageData) {
|
|
22
29
|
const { _filepath, lang } = pageData;
|
|
23
|
-
const
|
|
24
|
-
if (
|
|
30
|
+
const info = await getGitInfo(_filepath);
|
|
31
|
+
if (!info) return;
|
|
32
|
+
pageData.lastUpdatedTime = transform(info.timestamp, lang);
|
|
33
|
+
if (false === authorOption) return;
|
|
34
|
+
const display = 'function' == typeof authorOption ? authorOption({
|
|
35
|
+
name: info.authorName,
|
|
36
|
+
email: info.authorEmail,
|
|
37
|
+
filePath: _filepath
|
|
38
|
+
}) : info.authorName;
|
|
39
|
+
pageData.lastUpdatedAuthor = display;
|
|
25
40
|
}
|
|
26
41
|
};
|
|
27
42
|
}
|
package/dist/node/mdx/options.js
CHANGED
|
@@ -28,7 +28,13 @@ async function createMDXOptions(options) {
|
|
|
28
28
|
remark_gfm,
|
|
29
29
|
cjkFriendlyEmphasis && remark_cjk_friendly,
|
|
30
30
|
cjkFriendlyEmphasis && remark_cjk_friendly_gfm_strikethrough,
|
|
31
|
-
|
|
31
|
+
[
|
|
32
|
+
remarkToc,
|
|
33
|
+
{
|
|
34
|
+
routeService,
|
|
35
|
+
fallbackHeadingTitle: config?.themeConfig?.fallbackHeadingTitle
|
|
36
|
+
}
|
|
37
|
+
],
|
|
32
38
|
!isSsgMd && remarkContainerSyntax,
|
|
33
39
|
[
|
|
34
40
|
remarkFileCodeBlock,
|
|
@@ -46,6 +52,7 @@ async function createMDXOptions(options) {
|
|
|
46
52
|
routeService,
|
|
47
53
|
remarkLinkOptions: {
|
|
48
54
|
checkDeadLinks: false,
|
|
55
|
+
checkAnchors: false,
|
|
49
56
|
autoPrefix: true
|
|
50
57
|
},
|
|
51
58
|
__base: config?.base
|
|
@@ -29,7 +29,9 @@ async function compile(options) {
|
|
|
29
29
|
const compiler = createProcessor(mdxOptions);
|
|
30
30
|
compiler.data('pageMeta', {
|
|
31
31
|
toc: [],
|
|
32
|
-
title: ''
|
|
32
|
+
title: '',
|
|
33
|
+
headingTitle: '',
|
|
34
|
+
frontmatter
|
|
33
35
|
});
|
|
34
36
|
const vFile = await compiler.process({
|
|
35
37
|
value: preprocessedContent,
|
|
@@ -5,4 +5,4 @@ import type { Plugin } from 'unified';
|
|
|
5
5
|
* same as rehype-slug + rehype-autolink-headings, but support custom id.
|
|
6
6
|
*/
|
|
7
7
|
export declare const rehypeHeaderAnchor: Plugin<[], Root>;
|
|
8
|
-
export declare const collectHeaderText: (node: Element) => string[];
|
|
8
|
+
export declare const collectHeaderText: (node: Element, allowCustomId?: boolean) => string[];
|
|
@@ -13,18 +13,22 @@ const rehypeHeaderAnchor = ()=>{
|
|
|
13
13
|
});
|
|
14
14
|
};
|
|
15
15
|
};
|
|
16
|
-
const collectHeaderText = (node)=>{
|
|
16
|
+
const collectHeaderText = (node, allowCustomId = true)=>{
|
|
17
17
|
let text = '';
|
|
18
18
|
let id = '';
|
|
19
19
|
node.children.forEach((child)=>{
|
|
20
20
|
if ('text' === child.type) {
|
|
21
|
-
const [textPart, idPart] = extractTextAndId(child.value)
|
|
21
|
+
const [textPart, idPart] = allowCustomId ? extractTextAndId(child.value) : [
|
|
22
|
+
child.value,
|
|
23
|
+
''
|
|
24
|
+
];
|
|
22
25
|
child.value = textPart;
|
|
23
26
|
text += textPart;
|
|
24
|
-
id = idPart;
|
|
25
|
-
} else if ('element' === child.type)
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
if (idPart) id = idPart;
|
|
28
|
+
} else if ('element' === child.type) {
|
|
29
|
+
const [childText] = collectHeaderText(child, false);
|
|
30
|
+
text += childText;
|
|
31
|
+
}
|
|
28
32
|
});
|
|
29
33
|
return [
|
|
30
34
|
text,
|
|
@@ -13,10 +13,11 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import type { Root } from 'mdast';
|
|
15
15
|
import type { Plugin } from 'unified';
|
|
16
|
-
export declare const DIRECTIVE_TYPES: readonly ['tip', 'note', 'warning', 'caution', 'danger', 'info', 'details'];
|
|
16
|
+
export declare const DIRECTIVE_TYPES: readonly ['tip', 'note', 'important', 'warning', 'caution', 'danger', 'info', 'details'];
|
|
17
17
|
export declare const REGEX_BEGIN: RegExp;
|
|
18
18
|
export declare const REGEX_END: RegExp;
|
|
19
19
|
export declare const REGEX_GH_BEGIN: RegExp;
|
|
20
|
+
export declare const REGEX_GH_MARKER: RegExp;
|
|
20
21
|
export declare const TITLE_REGEX_IN_MD: RegExp;
|
|
21
22
|
export declare const TITLE_REGEX_IN_MDX: RegExp;
|
|
22
23
|
export type DirectiveType = (typeof DIRECTIVE_TYPES)[number];
|
|
@@ -2,6 +2,7 @@ import { getNamedImportAstNode } from "../../utils/getImportAstNode.js";
|
|
|
2
2
|
const DIRECTIVE_TYPES = [
|
|
3
3
|
'tip',
|
|
4
4
|
'note',
|
|
5
|
+
'important',
|
|
5
6
|
'warning',
|
|
6
7
|
'caution',
|
|
7
8
|
'danger',
|
|
@@ -10,7 +11,8 @@ const DIRECTIVE_TYPES = [
|
|
|
10
11
|
];
|
|
11
12
|
const REGEX_BEGIN = /^\s*:::\s*(\w+)\s*(.*)?/;
|
|
12
13
|
const REGEX_END = /\s*:::$/;
|
|
13
|
-
const REGEX_GH_BEGIN = /^\s*\
|
|
14
|
+
const REGEX_GH_BEGIN = /^\s*\[!(\w+)\]/;
|
|
15
|
+
const REGEX_GH_MARKER = /^\s*\[!\w+\][^\S\n]*\n?/;
|
|
14
16
|
const TITLE_REGEX_IN_MD = /{\s*title=["']?(.+)}\s*/;
|
|
15
17
|
const TITLE_REGEX_IN_MDX = /\s*title=["']?(.+)\s*/;
|
|
16
18
|
const CALLOUT_COMPONENT = '$$$callout$$$';
|
|
@@ -50,7 +52,9 @@ function transformer(tree, warnUnknownType) {
|
|
|
50
52
|
if (DIRECTIVE_TYPES.includes(type)) tree.children.splice(i, 1, createContainer(type, node.attributes?.title ?? type.toUpperCase(), node.children));
|
|
51
53
|
else warnUnknownType(type);
|
|
52
54
|
} else if ('blockquote' === node.type && node.children[0]?.type === 'paragraph' && node.children[0].children?.[0] && 'value' in node.children[0].children[0]) {
|
|
53
|
-
const
|
|
55
|
+
const firstParagraph = node.children[0];
|
|
56
|
+
const firstTextNode = firstParagraph.children[0];
|
|
57
|
+
const initiatorTag = firstTextNode.value;
|
|
54
58
|
const match = initiatorTag.match(REGEX_GH_BEGIN);
|
|
55
59
|
if (match) {
|
|
56
60
|
const [, type] = match;
|
|
@@ -59,8 +63,10 @@ function transformer(tree, warnUnknownType) {
|
|
|
59
63
|
i++;
|
|
60
64
|
continue;
|
|
61
65
|
}
|
|
62
|
-
|
|
63
|
-
const
|
|
66
|
+
firstTextNode.value = initiatorTag.replace(REGEX_GH_MARKER, '');
|
|
67
|
+
const isFirstParagraphEmpty = firstParagraph.children.every((child)=>'text' === child.type && '' === child.value.trim());
|
|
68
|
+
const children = isFirstParagraphEmpty ? node.children.slice(1) : node.children;
|
|
69
|
+
const newChild = createContainer(type.toLowerCase(), type.toUpperCase(), children);
|
|
64
70
|
tree.children.splice(i, 1, newChild);
|
|
65
71
|
}
|
|
66
72
|
}
|
|
@@ -184,13 +190,14 @@ const remarkContainerSyntax = ()=>{
|
|
|
184
190
|
};
|
|
185
191
|
return (tree)=>{
|
|
186
192
|
transformer(tree, warnUnknownType);
|
|
187
|
-
tree.children.unshift(getNamedImportAstNode('Callout', CALLOUT_COMPONENT, '@theme'));
|
|
193
|
+
tree.children.unshift(getNamedImportAstNode('Callout', CALLOUT_COMPONENT, '@rspress/core/theme'));
|
|
188
194
|
};
|
|
189
195
|
};
|
|
190
196
|
var containerSyntax_DIRECTIVE_TYPES = void 0;
|
|
191
197
|
var containerSyntax_REGEX_BEGIN = void 0;
|
|
192
198
|
var containerSyntax_REGEX_END = void 0;
|
|
193
199
|
var containerSyntax_REGEX_GH_BEGIN = void 0;
|
|
200
|
+
var containerSyntax_REGEX_GH_MARKER = void 0;
|
|
194
201
|
var containerSyntax_TITLE_REGEX_IN_MD = void 0;
|
|
195
202
|
var containerSyntax_TITLE_REGEX_IN_MDX = void 0;
|
|
196
|
-
export { containerSyntax_DIRECTIVE_TYPES as DIRECTIVE_TYPES, containerSyntax_REGEX_BEGIN as REGEX_BEGIN, containerSyntax_REGEX_END as REGEX_END, containerSyntax_REGEX_GH_BEGIN as REGEX_GH_BEGIN, containerSyntax_TITLE_REGEX_IN_MD as TITLE_REGEX_IN_MD, containerSyntax_TITLE_REGEX_IN_MDX as TITLE_REGEX_IN_MDX, remarkContainerSyntax };
|
|
203
|
+
export { containerSyntax_DIRECTIVE_TYPES as DIRECTIVE_TYPES, containerSyntax_REGEX_BEGIN as REGEX_BEGIN, containerSyntax_REGEX_END as REGEX_END, containerSyntax_REGEX_GH_BEGIN as REGEX_GH_BEGIN, containerSyntax_REGEX_GH_MARKER as REGEX_GH_MARKER, containerSyntax_TITLE_REGEX_IN_MD as TITLE_REGEX_IN_MD, containerSyntax_TITLE_REGEX_IN_MDX as TITLE_REGEX_IN_MDX, remarkContainerSyntax };
|
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
import { __webpack_require__ } from "../../../0~rslib-runtime.js";
|
|
2
2
|
import "../../../7986.js";
|
|
3
|
-
import { normalizeHref, node_path, addLeadingSlash, logger, visit, isExternalUrl, isProduction, parseUrl, withBase } from "../../../3358.js";
|
|
3
|
+
import { normalizeHref, node_path, addLeadingSlash, logger, visit, isExternalUrl, isProduction, parseUrl, MDX_OR_MD_REGEXP, withBase } from "../../../3358.js";
|
|
4
4
|
import { hintRelativeMarkdownLink } from "../../logger/hint.js";
|
|
5
5
|
import { createError } from "../../utils/error.js";
|
|
6
6
|
const picocolors = __webpack_require__("../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js");
|
|
7
7
|
var picocolors_default = /*#__PURE__*/ __webpack_require__.n(picocolors);
|
|
8
|
-
function
|
|
9
|
-
const
|
|
10
|
-
const excludes = 'object' == typeof checkDeadLinks ? checkDeadLinks.excludes : void 0;
|
|
8
|
+
function createExcluder(checkOption) {
|
|
9
|
+
const excludes = 'object' == typeof checkOption ? checkOption.excludes : void 0;
|
|
11
10
|
const excludesUrl = Array.isArray(excludes) ? new Set(excludes) : void 0;
|
|
12
11
|
const excludesFn = 'function' == typeof excludes ? excludes : void 0;
|
|
12
|
+
return (url)=>Boolean(excludesUrl?.has(url) || excludesFn?.(url));
|
|
13
|
+
}
|
|
14
|
+
function link_checkDeadLinks(checkDeadLinks, internalLinks, file, lint) {
|
|
15
|
+
const errorInfos = [];
|
|
16
|
+
const isExcluded = createExcluder(checkDeadLinks);
|
|
13
17
|
let possibleBreakingChange = false;
|
|
14
18
|
[
|
|
15
19
|
...internalLinks.entries()
|
|
16
20
|
].forEach(([nodeUrl, link])=>{
|
|
17
|
-
if (
|
|
18
|
-
if (excludesFn?.(nodeUrl)) return;
|
|
21
|
+
if (isExcluded(nodeUrl)) return;
|
|
19
22
|
if (!nodeUrl.startsWith('/') && /^\w/.test(nodeUrl)) possibleBreakingChange = true;
|
|
20
23
|
errorInfos.push([
|
|
21
24
|
nodeUrl,
|
|
@@ -33,6 +36,52 @@ ${errorInfos.map(([nodeUrl, link])=>` ${picocolors_default().green(`"[..](${nod
|
|
|
33
36
|
}
|
|
34
37
|
}
|
|
35
38
|
}
|
|
39
|
+
function checkDeadAnchors(checkAnchors, anchorLinks, routeService, file, lint) {
|
|
40
|
+
const errorInfos = [];
|
|
41
|
+
const isExcluded = createExcluder(checkAnchors);
|
|
42
|
+
[
|
|
43
|
+
...anchorLinks.entries()
|
|
44
|
+
].forEach(([nodeUrl, link])=>{
|
|
45
|
+
if (isExcluded(nodeUrl) || !link.hash || !link.routePath) return;
|
|
46
|
+
const routePage = routeService.getRoutePageByRouteLink(link.routePath);
|
|
47
|
+
if (!routePage) return;
|
|
48
|
+
if (!MDX_OR_MD_REGEXP.test(routePage.routeMeta.absolutePath)) return;
|
|
49
|
+
const anchorIds = routeService.getRouteAnchorIds(link.routePath);
|
|
50
|
+
if (anchorIds) return void collectDeadAnchor(errorInfos, anchorIds, nodeUrl, link);
|
|
51
|
+
routeService.onRouteAnchorIds(link.routePath, (targetAnchorIds)=>{
|
|
52
|
+
const deferredErrorInfos = [];
|
|
53
|
+
collectDeadAnchor(deferredErrorInfos, targetAnchorIds, nodeUrl, link);
|
|
54
|
+
reportDeadAnchors(deferredErrorInfos, file, lint);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
reportDeadAnchors(errorInfos, file, lint);
|
|
58
|
+
}
|
|
59
|
+
function collectDeadAnchor(errorInfos, anchorIds, nodeUrl, link) {
|
|
60
|
+
if (!link.hash || !link.routePath) return;
|
|
61
|
+
const hash = decodeHash(link.hash);
|
|
62
|
+
if (!anchorIds.has(hash)) errorInfos.push([
|
|
63
|
+
nodeUrl,
|
|
64
|
+
`${link.routePath}#${link.hash}`
|
|
65
|
+
]);
|
|
66
|
+
}
|
|
67
|
+
function reportDeadAnchors(errorInfos, file, lint) {
|
|
68
|
+
if (errorInfos.length > 0) {
|
|
69
|
+
const message = `Dead anchors found${lint ? '' : ` in ${picocolors_default().cyan(file.path)}`}:
|
|
70
|
+
${errorInfos.map(([nodeUrl, link])=>` ${picocolors_default().green(`"[..](${nodeUrl})"`)} ${picocolors_default().gray(link)}`).join('\n')}`;
|
|
71
|
+
if (lint) file.message(message);
|
|
72
|
+
else {
|
|
73
|
+
logger.error(message);
|
|
74
|
+
if (isProduction()) throw createError('Dead anchor found');
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function decodeHash(hash) {
|
|
79
|
+
try {
|
|
80
|
+
return decodeURIComponent(hash);
|
|
81
|
+
} catch {
|
|
82
|
+
return hash;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
36
85
|
function looseMarkdownLink(url, routeService, filePath) {
|
|
37
86
|
if (!routeService.isInDocsDir(filePath)) return url;
|
|
38
87
|
const [versionPart, langPart, pureRoute] = routeService.splitRoutePathParts(url);
|
|
@@ -51,10 +100,23 @@ function looseMarkdownLink(url, routeService, filePath) {
|
|
|
51
100
|
return url;
|
|
52
101
|
}
|
|
53
102
|
function normalizeLink(nodeUrl, routeService, filePath, cleanUrls, autoPrefix, deadLinks, __base) {
|
|
54
|
-
if (!nodeUrl) return
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (
|
|
103
|
+
if (!nodeUrl) return {
|
|
104
|
+
url: ''
|
|
105
|
+
};
|
|
106
|
+
if (nodeUrl.startsWith('#')) {
|
|
107
|
+
const routePath = routeService?.getRoutePageByFilePath(filePath)?.routeMeta.routePath;
|
|
108
|
+
return {
|
|
109
|
+
url: nodeUrl,
|
|
110
|
+
routePath,
|
|
111
|
+
hash: nodeUrl.slice(1)
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
if (isExternalUrl(nodeUrl)) return {
|
|
115
|
+
url: nodeUrl
|
|
116
|
+
};
|
|
117
|
+
if (!routeService) return {
|
|
118
|
+
url: nodeUrl
|
|
119
|
+
};
|
|
58
120
|
let { url, hash, search } = parseUrl(nodeUrl);
|
|
59
121
|
if (url.startsWith('/')) {
|
|
60
122
|
if (autoPrefix) url = looseMarkdownLink(url, routeService, filePath);
|
|
@@ -68,34 +130,47 @@ function normalizeLink(nodeUrl, routeService, filePath, cleanUrls, autoPrefix, d
|
|
|
68
130
|
url = normalizeHref(url, cleanUrls);
|
|
69
131
|
if (!routeService.isExistRoute(url)) {
|
|
70
132
|
deadLinks.set(nodeUrl, url);
|
|
71
|
-
return
|
|
133
|
+
return {
|
|
134
|
+
url: nodeUrl
|
|
135
|
+
};
|
|
72
136
|
}
|
|
73
137
|
} else {
|
|
74
138
|
url = normalizeHref(url, false);
|
|
75
139
|
if (!routeService.isExistRoute(url)) {
|
|
76
140
|
deadLinks.set(nodeUrl, url);
|
|
77
|
-
return
|
|
141
|
+
return {
|
|
142
|
+
url: nodeUrl
|
|
143
|
+
};
|
|
78
144
|
}
|
|
79
145
|
url = url.replace(/\.html$/, cleanUrls);
|
|
80
146
|
}
|
|
147
|
+
const routePath = url;
|
|
81
148
|
if (search) url += `?${search}`;
|
|
82
149
|
if (hash) url += `#${hash}`;
|
|
83
150
|
if (__base) url = withBase(url, __base);
|
|
84
|
-
return
|
|
151
|
+
return {
|
|
152
|
+
url,
|
|
153
|
+
routePath,
|
|
154
|
+
hash
|
|
155
|
+
};
|
|
85
156
|
}
|
|
86
157
|
const remarkLink = ({ cleanUrls, routeService, remarkLinkOptions, lint, __base })=>(tree, file)=>{
|
|
87
|
-
const { checkDeadLinks: shouldCheckDeadLinks = true, autoPrefix = true } = remarkLinkOptions ?? {};
|
|
158
|
+
const { checkAnchors: shouldCheckAnchors = false, checkDeadLinks: shouldCheckDeadLinks = true, autoPrefix = true } = remarkLinkOptions ?? {};
|
|
88
159
|
const deadLinks = new Map();
|
|
160
|
+
const anchorLinks = new Map();
|
|
89
161
|
visit(tree, 'link', (node)=>{
|
|
90
162
|
const { url: nodeUrl } = node;
|
|
91
163
|
const link = normalizeLink(nodeUrl, routeService, file.path, cleanUrls, autoPrefix, deadLinks, __base);
|
|
92
|
-
|
|
164
|
+
if (link.hash) anchorLinks.set(nodeUrl, link);
|
|
165
|
+
node.url = link.url;
|
|
93
166
|
});
|
|
94
167
|
visit(tree, 'definition', (node)=>{
|
|
95
168
|
const { url: nodeUrl } = node;
|
|
96
169
|
const link = normalizeLink(nodeUrl, routeService, file.path, cleanUrls, autoPrefix, deadLinks, __base);
|
|
97
|
-
|
|
170
|
+
if (link.hash) anchorLinks.set(nodeUrl, link);
|
|
171
|
+
node.url = link.url;
|
|
98
172
|
});
|
|
99
173
|
if (shouldCheckDeadLinks && routeService) link_checkDeadLinks(shouldCheckDeadLinks, deadLinks, file, lint);
|
|
174
|
+
if (shouldCheckAnchors && routeService) checkDeadAnchors(shouldCheckAnchors, anchorLinks, routeService, file, lint);
|
|
100
175
|
};
|
|
101
176
|
export { remarkLink };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Root as HastRoot } from 'hast';
|
|
2
2
|
import type { Root as MdastRoot } from 'mdast';
|
|
3
3
|
import type { Plugin } from 'unified';
|
|
4
|
+
import type { RouteService } from '../../route/RouteService.js';
|
|
4
5
|
export interface TocItem {
|
|
5
6
|
id: string;
|
|
6
7
|
text: string;
|
|
@@ -9,5 +10,11 @@ export interface TocItem {
|
|
|
9
10
|
export declare const parseToc: (tree: MdastRoot | HastRoot) => {
|
|
10
11
|
title: string;
|
|
11
12
|
toc: TocItem[];
|
|
13
|
+
anchorIds: string[];
|
|
12
14
|
};
|
|
13
|
-
|
|
15
|
+
interface RemarkTocOptions {
|
|
16
|
+
routeService?: RouteService | null;
|
|
17
|
+
fallbackHeadingTitle?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export declare const remarkToc: Plugin<[RemarkTocOptions?], HastRoot>;
|
|
20
|
+
export {};
|
|
@@ -1,20 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
const extractChildText = (child)=>{
|
|
3
|
-
if ('link' === child.type) return child.children?.map(extractChildText).join('') ?? '';
|
|
4
|
-
if ('strong' === child.type)
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { visitChildren, extractTextAndId, github_slugger, slug } from "../../../8005.js";
|
|
2
|
+
const extractChildText = (child, preserveInlineMarkdown = true)=>{
|
|
3
|
+
if ('link' === child.type) return child.children?.map((child)=>extractChildText(child, preserveInlineMarkdown)).join('') ?? '';
|
|
4
|
+
if ('strong' === child.type) {
|
|
5
|
+
const text = child.children?.map((child)=>extractChildText(child, preserveInlineMarkdown)).join('') ?? '';
|
|
6
|
+
return preserveInlineMarkdown ? `**${text}**` : text;
|
|
7
|
+
}
|
|
8
|
+
if ('emphasis' === child.type) {
|
|
9
|
+
const text = child.children?.map((child)=>extractChildText(child, preserveInlineMarkdown)).join('') ?? '';
|
|
10
|
+
return preserveInlineMarkdown ? `*${text}*` : text;
|
|
11
|
+
}
|
|
12
|
+
if ('delete' === child.type) {
|
|
13
|
+
const text = child.children?.map((child)=>extractChildText(child, preserveInlineMarkdown)).join('') ?? '';
|
|
14
|
+
return preserveInlineMarkdown ? `~~${text}~~` : text;
|
|
15
|
+
}
|
|
7
16
|
if ('text' === child.type) return child.value;
|
|
8
|
-
if ('inlineCode' === child.type) return `\`${child.value}
|
|
17
|
+
if ('inlineCode' === child.type) return preserveInlineMarkdown ? `\`${child.value}\`` : child.value;
|
|
9
18
|
return '';
|
|
10
19
|
};
|
|
11
20
|
const parseToc = (tree)=>{
|
|
12
21
|
let title = '';
|
|
13
22
|
const toc = [];
|
|
23
|
+
const anchorIds = [];
|
|
14
24
|
const slugger = new github_slugger();
|
|
15
25
|
visitChildren((node)=>{
|
|
16
26
|
if ('heading' !== node.type || !node.depth || !node.children) return;
|
|
17
|
-
if (node.depth >= 1 && node.depth
|
|
27
|
+
if (node.depth >= 1 && node.depth <= 6) {
|
|
18
28
|
let customId = '';
|
|
19
29
|
const text = node.children.map((child)=>{
|
|
20
30
|
if ('text' === child.type) {
|
|
@@ -24,10 +34,18 @@ const parseToc = (tree)=>{
|
|
|
24
34
|
}
|
|
25
35
|
return extractChildText(child);
|
|
26
36
|
}).join('').trim();
|
|
37
|
+
const titleText = node.children.map((child)=>{
|
|
38
|
+
if ('text' === child.type) {
|
|
39
|
+
const [textPart] = extractTextAndId(child.value);
|
|
40
|
+
return textPart;
|
|
41
|
+
}
|
|
42
|
+
return extractChildText(child, false);
|
|
43
|
+
}).join('').trim();
|
|
44
|
+
const id = customId ? customId : slugger.slug(text);
|
|
45
|
+
anchorIds.push(id);
|
|
27
46
|
if (1 === node.depth) {
|
|
28
|
-
if (!title) title =
|
|
29
|
-
} else {
|
|
30
|
-
const id = customId ? customId : slugger.slug(text);
|
|
47
|
+
if (!title) title = titleText;
|
|
48
|
+
} else if (node.depth < 5) {
|
|
31
49
|
const { depth } = node;
|
|
32
50
|
toc.push({
|
|
33
51
|
id,
|
|
@@ -39,15 +57,26 @@ const parseToc = (tree)=>{
|
|
|
39
57
|
})(tree);
|
|
40
58
|
return {
|
|
41
59
|
title,
|
|
42
|
-
toc
|
|
60
|
+
toc,
|
|
61
|
+
anchorIds
|
|
43
62
|
};
|
|
44
63
|
};
|
|
45
|
-
const remarkToc = function() {
|
|
64
|
+
const remarkToc = function(options = {}) {
|
|
46
65
|
const data = this.data();
|
|
47
|
-
return (tree)=>{
|
|
48
|
-
const { toc, title } = parseToc(tree);
|
|
66
|
+
return (tree, file)=>{
|
|
67
|
+
const { toc, title, anchorIds } = parseToc(tree);
|
|
49
68
|
data.pageMeta.toc = toc;
|
|
50
69
|
if (title) data.pageMeta.title = title;
|
|
70
|
+
if (file.path) {
|
|
71
|
+
const registeredAnchorIds = new Set(anchorIds);
|
|
72
|
+
const fallbackHeadingTitle = data.pageMeta.frontmatter?.title;
|
|
73
|
+
if (!title && false !== options.fallbackHeadingTitle && 'string' == typeof fallbackHeadingTitle) {
|
|
74
|
+
const [fallbackHeadingText] = extractTextAndId(fallbackHeadingTitle);
|
|
75
|
+
const fallbackHeadingAnchorId = slug(fallbackHeadingText.trim());
|
|
76
|
+
if (fallbackHeadingAnchorId) registeredAnchorIds.add(fallbackHeadingAnchorId);
|
|
77
|
+
}
|
|
78
|
+
options.routeService?.setRouteAnchorIds(file.path, registeredAnchorIds);
|
|
79
|
+
}
|
|
51
80
|
};
|
|
52
81
|
};
|
|
53
82
|
export { parseToc, remarkToc };
|
|
@@ -6,6 +6,7 @@ interface InitOptions {
|
|
|
6
6
|
config: UserConfig;
|
|
7
7
|
externalPages: AdditionalPage[];
|
|
8
8
|
}
|
|
9
|
+
type RouteAnchorIdsConsumer = (anchorIds: Set<string>) => void;
|
|
9
10
|
export interface Route {
|
|
10
11
|
path: string;
|
|
11
12
|
element: React.ReactElement;
|
|
@@ -31,6 +32,11 @@ export declare class RouteService {
|
|
|
31
32
|
getRoutes(): RouteMeta[];
|
|
32
33
|
getRoutePages(): RoutePage[];
|
|
33
34
|
isExistRoute(link: string): boolean;
|
|
35
|
+
getRoutePageByRouteLink(link: string): RoutePage | undefined;
|
|
36
|
+
getRoutePageByFilePath(filePath: string): RoutePage | undefined;
|
|
37
|
+
setRouteAnchorIds(filePath: string, anchorIds: Set<string>): void;
|
|
38
|
+
getRouteAnchorIds(routeLink: string): Set<string> | undefined;
|
|
39
|
+
onRouteAnchorIds(routeLink: string, consumer: RouteAnchorIdsConsumer): void;
|
|
34
40
|
generateRoutesCode(): string;
|
|
35
41
|
private generateRoutesCodeByRouteMeta;
|
|
36
42
|
getRoutePathParts(relativePath: string): string[];
|