@rspress/core 2.0.14 → 2.0.15

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 (169) hide show
  1. package/dist/0~execa.js +1 -1
  2. package/dist/3358.js +1 -1
  3. package/dist/5580.js +1 -1
  4. package/dist/{4942.js → 6010.js} +1 -1
  5. package/dist/8005.js +1 -1
  6. package/dist/{7261.js → 9958.js} +2 -1
  7. package/dist/cli/index.js +1 -1
  8. package/dist/eject-theme/components/DocContent/doc.scss +2 -2
  9. package/dist/eject-theme/components/HomeBackground/useNavTransparent.tsx +2 -2
  10. package/dist/eject-theme/components/HoverGroup/index.scss +1 -1
  11. package/dist/eject-theme/components/LastUpdated/index.tsx +8 -2
  12. package/dist/eject-theme/components/Nav/NavMenu.scss +1 -1
  13. package/dist/eject-theme/components/Nav/hooks.tsx +18 -14
  14. package/dist/eject-theme/components/Nav/index.tsx +4 -1
  15. package/dist/eject-theme/components/NavScreen/NavScreenAppearance.tsx +4 -1
  16. package/dist/eject-theme/components/NavScreen/NavScreenMenuItem.scss +3 -0
  17. package/dist/eject-theme/components/NavScreen/NavScreenMenuOthers.tsx +4 -1
  18. package/dist/eject-theme/components/Search/SearchPanel.tsx +23 -17
  19. package/dist/index.d.ts +1 -1
  20. package/dist/node/PluginDriver.js +4 -4
  21. package/dist/node/auto-nav-sidebar/index.js +1 -1
  22. package/dist/node/auto-nav-sidebar/locales.js +1 -1
  23. package/dist/node/auto-nav-sidebar/normalize.js +1 -1
  24. package/dist/node/auto-nav-sidebar/utils.js +1 -1
  25. package/dist/node/auto-nav-sidebar/walk.d.ts +4 -2
  26. package/dist/node/auto-nav-sidebar/walk.js +3 -3
  27. package/dist/node/constants.d.ts +2 -1
  28. package/dist/node/constants.js +12 -6
  29. package/dist/node/initRsbuild.js +8 -15
  30. package/dist/node/last-updated/index.d.ts +3 -3
  31. package/dist/node/last-updated/index.js +24 -9
  32. package/dist/node/mdx/options.js +8 -1
  33. package/dist/node/mdx/processor.js +3 -1
  34. package/dist/node/mdx/rehypePlugins/headerAnchor.d.ts +1 -1
  35. package/dist/node/mdx/rehypePlugins/headerAnchor.js +10 -6
  36. package/dist/node/mdx/remarkPlugins/link.js +91 -16
  37. package/dist/node/mdx/remarkPlugins/toc.d.ts +8 -1
  38. package/dist/node/mdx/remarkPlugins/toc.js +44 -15
  39. package/dist/node/route/RoutePage.js +1 -1
  40. package/dist/node/route/RouteService.d.ts +6 -0
  41. package/dist/node/route/RouteService.js +41 -7
  42. package/dist/node/route/extractPageData.js +1 -1
  43. package/dist/node/route/normalizeRoutePath.js +1 -1
  44. package/dist/node/runtimeModule/DEFAULT_I18N_TEXT.d.ts +7 -0
  45. package/dist/node/runtimeModule/DEFAULT_I18N_TEXT.js +7 -0
  46. package/dist/node/runtimeModule/i18n.js +1 -1
  47. package/dist/node/runtimeModule/pageData/createPageData.js +2 -1
  48. package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +1 -1
  49. package/dist/node/runtimeModule/searchHooks.js +1 -1
  50. package/dist/node/runtimeModule/siteData/createSiteData.js +1 -1
  51. package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +12 -2
  52. package/dist/node/runtimeModule/siteData/rsbuildPlugin.js +1 -1
  53. package/dist/node/serve.js +1 -1
  54. package/dist/node/ssg/htmlFile.js +1 -1
  55. package/dist/node/ssg/renderPage.js +1 -1
  56. package/dist/node/ssg/renderPageWorker.js +1 -1
  57. package/dist/node/ssg/renderPages.js +2 -2
  58. package/dist/node/ssg/rsbuildPluginCSR.js +2 -1
  59. package/dist/node/ssg/rsbuildPluginSSG.js +5 -3
  60. package/dist/node/ssg/ssgEnv.js +1 -1
  61. package/dist/node/ssg-md/llms/emitLlmsTxt.js +1 -1
  62. package/dist/node/ssg-md/llms/llmsTxt.js +1 -1
  63. package/dist/node/ssg-md/renderPage.js +1 -1
  64. package/dist/node/ssg-md/renderPages.js +2 -2
  65. package/dist/node/ssg-md/rsbuildPluginSSGMD.js +3 -2
  66. package/dist/node/utils/checkLanguageParity.js +1 -1
  67. package/dist/node/utils/createHash.js +1 -1
  68. package/dist/node/utils/flattenMdxContent.js +1 -1
  69. package/dist/node/utils/getPageKey.js +1 -1
  70. package/dist/node/utils/reactAlias.js +1 -1
  71. package/dist/runtime/App.d.ts +2 -1
  72. package/dist/runtime/ClientApp.d.ts +1 -1
  73. package/dist/runtime/Content.d.ts +1 -1
  74. package/dist/runtime/NoSSR.d.ts +1 -1
  75. package/dist/theme/components/Badge/index.d.ts +1 -1
  76. package/dist/theme/components/CodeBlock/index.d.ts +1 -1
  77. package/dist/theme/components/CodeButtonGroup/CopyCodeButton.d.ts +1 -1
  78. package/dist/theme/components/CodeButtonGroup/index.d.ts +1 -1
  79. package/dist/theme/components/DocContent/doc.css +2 -2
  80. package/dist/theme/components/DocContent/docComponents/a.d.ts +1 -1
  81. package/dist/theme/components/DocContent/docComponents/code.d.ts +1 -1
  82. package/dist/theme/components/DocContent/docComponents/hr.d.ts +1 -1
  83. package/dist/theme/components/DocContent/docComponents/img.d.ts +1 -1
  84. package/dist/theme/components/DocContent/docComponents/index.d.ts +18 -18
  85. package/dist/theme/components/DocContent/docComponents/list.d.ts +3 -3
  86. package/dist/theme/components/DocContent/docComponents/paragraph.d.ts +3 -3
  87. package/dist/theme/components/DocContent/docComponents/pre.d.ts +1 -1
  88. package/dist/theme/components/DocContent/docComponents/table.d.ts +3 -3
  89. package/dist/theme/components/DocContent/docComponents/title.d.ts +6 -6
  90. package/dist/theme/components/DocContent/index.d.ts +1 -1
  91. package/dist/theme/components/DocFooter/index.d.ts +1 -1
  92. package/dist/theme/components/EditLink/index.d.ts +1 -1
  93. package/dist/theme/components/FallbackHeading/index.d.ts +1 -1
  94. package/dist/theme/components/HomeBackground/index.d.ts +1 -1
  95. package/dist/theme/components/HomeBackground/useNavTransparent.d.ts +1 -1
  96. package/dist/theme/components/HomeBackground/useNavTransparent.js +2 -2
  97. package/dist/theme/components/HomeFeature/useCardAnimation.d.ts +1 -1
  98. package/dist/theme/components/HomeFooter/index.d.ts +1 -1
  99. package/dist/theme/components/HomeHero/index.d.ts +1 -1
  100. package/dist/theme/components/HoverGroup/index.css +1 -1
  101. package/dist/theme/components/HoverGroup/index.d.ts +1 -1
  102. package/dist/theme/components/HoverGroup/useHoverGroup.d.ts +1 -1
  103. package/dist/theme/components/LastUpdated/index.d.ts +1 -1
  104. package/dist/theme/components/LastUpdated/index.js +13 -3
  105. package/dist/theme/components/Llms/LlmsContainer.d.ts +1 -1
  106. package/dist/theme/components/Llms/LlmsCopyButton.d.ts +1 -1
  107. package/dist/theme/components/Llms/LlmsCopyRow.d.ts +1 -1
  108. package/dist/theme/components/Llms/LlmsOpenRow.d.ts +1 -1
  109. package/dist/theme/components/Llms/LlmsViewOptions.d.ts +1 -1
  110. package/dist/theme/components/Nav/NavMenu.css +1 -1
  111. package/dist/theme/components/Nav/NavMenu.d.ts +9 -9
  112. package/dist/theme/components/Nav/hooks.js +6 -3
  113. package/dist/theme/components/Nav/index.d.ts +1 -1
  114. package/dist/theme/components/Nav/index.js +2 -1
  115. package/dist/theme/components/NavHamburger/index.d.ts +1 -1
  116. package/dist/theme/components/NavScreen/NavScreenAppearance.d.ts +1 -1
  117. package/dist/theme/components/NavScreen/NavScreenAppearance.js +2 -1
  118. package/dist/theme/components/NavScreen/NavScreenLangs.d.ts +1 -1
  119. package/dist/theme/components/NavScreen/NavScreenMenu.d.ts +1 -1
  120. package/dist/theme/components/NavScreen/NavScreenMenuItem.css +10 -1
  121. package/dist/theme/components/NavScreen/NavScreenMenuItem.d.ts +5 -5
  122. package/dist/theme/components/NavScreen/NavScreenMenuOthers.d.ts +1 -1
  123. package/dist/theme/components/NavScreen/NavScreenMenuOthers.js +2 -1
  124. package/dist/theme/components/NavScreen/NavScreenVersions.d.ts +1 -1
  125. package/dist/theme/components/NavScreen/index.d.ts +2 -2
  126. package/dist/theme/components/NavTitle/index.d.ts +1 -1
  127. package/dist/theme/components/Outline/ScrollToTop.d.ts +1 -1
  128. package/dist/theme/components/Outline/index.d.ts +1 -1
  129. package/dist/theme/components/Overview/index.d.ts +1 -1
  130. package/dist/theme/components/OverviewGroup/index.d.ts +1 -1
  131. package/dist/theme/components/PackageManagerTabs/icons/Bun.d.ts +1 -1
  132. package/dist/theme/components/PackageManagerTabs/icons/Deno.d.ts +1 -1
  133. package/dist/theme/components/PackageManagerTabs/icons/Npm.d.ts +1 -1
  134. package/dist/theme/components/PackageManagerTabs/icons/Pnpm.d.ts +1 -1
  135. package/dist/theme/components/PackageManagerTabs/icons/Yarn.d.ts +1 -1
  136. package/dist/theme/components/PackageManagerTabs/index.d.ts +1 -1
  137. package/dist/theme/components/PrevNextPage/index.d.ts +1 -1
  138. package/dist/theme/components/Prompt/index.d.ts +1 -1
  139. package/dist/theme/components/ReadPercent/index.d.ts +1 -1
  140. package/dist/theme/components/Root/index.d.ts +1 -1
  141. package/dist/theme/components/Search/NoSearchResult.d.ts +1 -1
  142. package/dist/theme/components/Search/SearchButton.d.ts +1 -1
  143. package/dist/theme/components/Search/SearchPanel.d.ts +1 -1
  144. package/dist/theme/components/Search/SearchPanel.js +11 -7
  145. package/dist/theme/components/Search/SuggestItem.d.ts +1 -1
  146. package/dist/theme/components/Search/index.d.ts +1 -1
  147. package/dist/theme/components/Sidebar/SidebarDivider.d.ts +1 -1
  148. package/dist/theme/components/Sidebar/SidebarGroup.d.ts +1 -1
  149. package/dist/theme/components/Sidebar/SidebarItem.d.ts +2 -2
  150. package/dist/theme/components/Sidebar/SidebarSectionHeader.d.ts +1 -1
  151. package/dist/theme/components/Sidebar/index.d.ts +2 -2
  152. package/dist/theme/components/SidebarMenu/useSidebarMenu.d.ts +1 -1
  153. package/dist/theme/components/SocialLinks/GithubStars.d.ts +1 -1
  154. package/dist/theme/components/SocialLinks/SocialLink.d.ts +1 -1
  155. package/dist/theme/components/SocialLinks/index.d.ts +1 -1
  156. package/dist/theme/components/SourceCode/index.d.ts +1 -1
  157. package/dist/theme/components/Steps/index.d.ts +1 -1
  158. package/dist/theme/components/SvgWrapper/index.d.ts +1 -1
  159. package/dist/theme/components/SwitchAppearance/index.d.ts +1 -1
  160. package/dist/theme/components/Tag/index.d.ts +1 -1
  161. package/dist/theme/components/Toc/TocItem.d.ts +1 -1
  162. package/dist/theme/components/Toc/index.d.ts +1 -1
  163. package/dist/theme/layout/DocLayout/index.d.ts +1 -1
  164. package/dist/theme/layout/HomeLayout/index.d.ts +1 -1
  165. package/dist/theme/layout/Layout/index.d.ts +1 -1
  166. package/dist/theme/layout/NotFountLayout/index.d.ts +1 -1
  167. package/dist/theme/logic/useThemeState.d.ts +6 -7
  168. package/dist/theme/logic/useThemeState.js +19 -15
  169. package/package.json +17 -17
@@ -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) child.children.forEach((c)=>{
26
- if ('text' === c.type) text += c.value;
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,
@@ -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 link_checkDeadLinks(checkDeadLinks, internalLinks, file, lint) {
9
- const errorInfos = [];
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 (excludesUrl?.has(nodeUrl)) return;
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
- if (nodeUrl.startsWith('#')) return nodeUrl;
56
- if (isExternalUrl(nodeUrl)) return nodeUrl;
57
- if (!routeService) return nodeUrl;
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 nodeUrl;
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 nodeUrl;
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 url;
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
- node.url = link;
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
- node.url = link;
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
- export declare const remarkToc: Plugin<[], HastRoot>;
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 { github_slugger, visitChildren, extractTextAndId } from "../../../8005.js";
2
- const extractChildText = (child)=>{
3
- if ('link' === child.type) return child.children?.map(extractChildText).join('') ?? '';
4
- if ('strong' === child.type) return `**${child.children?.map(extractChildText).join('') ?? ''}**`;
5
- if ('emphasis' === child.type) return `*${child.children?.map(extractChildText).join('') ?? ''}*`;
6
- if ('delete' === child.type) return `~~${child.children?.map(extractChildText).join('') ?? ''}~~`;
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 < 5) {
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 = text;
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 };
@@ -1,4 +1,4 @@
1
- import { node_path } from "../../4942.js";
1
+ import { node_path } from "../../6010.js";
2
2
  import { RouteService } from "./RouteService.js";
3
3
  import { normalizePath, slash } from "../utils/normalizePath.js";
4
4
  import { getPageKey } from "../utils/getPageKey.js";
@@ -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[];
@@ -1,9 +1,12 @@
1
- import { RSPRESS_TEMP_DIR, node_path, removeTrailingSlash, promises, addTrailingSlash, DEFAULT_PAGE_EXTENSIONS, glob } from "../../4942.js";
1
+ import { RSPRESS_TEMP_DIR, node_path, removeTrailingSlash, promises, addTrailingSlash, DEFAULT_PAGE_EXTENSIONS, glob } from "../../6010.js";
2
2
  import { RoutePage, absolutePathToRoutePath, absolutePathToRelativePath } from "./RoutePage.js";
3
3
  import { createError } from "../utils/error.js";
4
4
  import { getRoutePathParts, normalizeRoutePath, splitRoutePathParts } from "./normalizeRoutePath.js";
5
5
  class RouteService {
6
6
  routeData = new Map();
7
+ #routeDataByFilePath = new Map();
8
+ #routeAnchorIds = new Map();
9
+ #routeAnchorIdsConsumers = new Map();
7
10
  #scanDir;
8
11
  #defaultLang;
9
12
  #defaultVersion;
@@ -99,6 +102,7 @@ class RouteService {
99
102
  const { routeMeta: { routePath } } = routePage;
100
103
  if (this.routeData.has(routePath)) throw createError(`routePath ${routePath} has already been added`);
101
104
  this.routeData.set(routePath, routePage);
105
+ this.#routeDataByFilePath.set(node_path.normalize(routePage.routeMeta.absolutePath), routePage);
102
106
  }
103
107
  getRoutes() {
104
108
  return Array.from(this.routeData.values()).map((i)=>i.routeMeta);
@@ -107,12 +111,39 @@ class RouteService {
107
111
  return Array.from(this.routeData.values());
108
112
  }
109
113
  isExistRoute(link) {
110
- function linkToRoutePath(routePath) {
111
- return decodeURIComponent(routePath.split('#')[0]).replace(/\.html$/, '').replace(/\/index$/, '/');
112
- }
113
- const cleanLinkPath = linkToRoutePath(link);
114
- if (!this.routeData.has(removeTrailingSlash(cleanLinkPath)) && !this.routeData.has(addTrailingSlash(cleanLinkPath))) return false;
115
- return true;
114
+ return Boolean(this.getRoutePageByRouteLink(link));
115
+ }
116
+ getRoutePageByRouteLink(link) {
117
+ const cleanLinkPath = this.#linkToRoutePath(link);
118
+ return this.routeData.get(removeTrailingSlash(cleanLinkPath)) ?? this.routeData.get(addTrailingSlash(cleanLinkPath));
119
+ }
120
+ getRoutePageByFilePath(filePath) {
121
+ return this.#routeDataByFilePath.get(node_path.normalize(filePath));
122
+ }
123
+ setRouteAnchorIds(filePath, anchorIds) {
124
+ const routePage = this.getRoutePageByFilePath(filePath);
125
+ if (!routePage) return;
126
+ const { routePath } = routePage.routeMeta;
127
+ this.#routeAnchorIds.set(routePath, anchorIds);
128
+ const consumers = this.#routeAnchorIdsConsumers.get(routePath);
129
+ if (!consumers) return;
130
+ this.#routeAnchorIdsConsumers.delete(routePath);
131
+ for (const consumer of consumers)consumer(anchorIds);
132
+ }
133
+ getRouteAnchorIds(routeLink) {
134
+ const routePage = this.getRoutePageByRouteLink(routeLink);
135
+ if (!routePage) return;
136
+ return this.#routeAnchorIds.get(routePage.routeMeta.routePath);
137
+ }
138
+ onRouteAnchorIds(routeLink, consumer) {
139
+ const routePage = this.getRoutePageByRouteLink(routeLink);
140
+ if (!routePage) return;
141
+ const { routePath } = routePage.routeMeta;
142
+ const anchorIds = this.#routeAnchorIds.get(routePath);
143
+ if (anchorIds) return void consumer(anchorIds);
144
+ const consumers = this.#routeAnchorIdsConsumers.get(routePath) ?? [];
145
+ consumers.push(consumer);
146
+ this.#routeAnchorIdsConsumers.set(routePath, consumers);
116
147
  }
117
148
  generateRoutesCode() {
118
149
  return this.generateRoutesCodeByRouteMeta(this.getRoutes());
@@ -158,6 +189,9 @@ ${routeMeta.map((route, index)=>{
158
189
  await promises.writeFile(tempFilePath, content);
159
190
  return tempFilePath;
160
191
  }
192
+ #linkToRoutePath(routePath) {
193
+ return decodeURIComponent(routePath.split('#')[0]).replace(/\.html$/, '').replace(/\/index$/, '/');
194
+ }
161
195
  getRoutePageByRoutePath(routePath) {
162
196
  return this.routeData.get(routePath);
163
197
  }
@@ -1,4 +1,4 @@
1
- import { unified, node_path, promises, loadFrontMatter, remove, remark_gfm, MDX_OR_MD_REGEXP, remark_parse } from "../../4942.js";
1
+ import { unified, node_path, promises, loadFrontMatter, remove, remark_gfm, MDX_OR_MD_REGEXP, remark_parse } from "../../6010.js";
2
2
  import { applyReplaceRules } from "../utils/applyReplaceRules.js";
3
3
  import { flattenMdxContent } from "../utils/flattenMdxContent.js";
4
4
  import { importStatementRegex } from "../constants.js";
@@ -1,4 +1,4 @@
1
- import { addTrailingSlash, DEFAULT_PAGE_EXTENSIONS, addLeadingSlash } from "../../4942.js";
1
+ import { addTrailingSlash, DEFAULT_PAGE_EXTENSIONS, addLeadingSlash } from "../../6010.js";
2
2
  const getRoutePathParts = (relativePath, lang, version, langs, versions)=>{
3
3
  const [versionPart, langPart, purePath] = splitRoutePathParts(relativePath, lang, version, langs, versions);
4
4
  return [
@@ -48,6 +48,13 @@ export declare const DEFAULT_I18N_TEXT: {
48
48
  readonly ko: '업데이트 날짜';
49
49
  readonly ru: 'Последнее обновление';
50
50
  };
51
+ readonly lastUpdatedAuthorText: {
52
+ readonly en: 'by';
53
+ readonly zh: '作者';
54
+ readonly ja: '更新者';
55
+ readonly ko: '작성자';
56
+ readonly ru: 'автор';
57
+ };
51
58
  readonly prevPageText: {
52
59
  readonly en: 'Previous page';
53
60
  readonly zh: '上一页';
@@ -48,6 +48,13 @@ const DEFAULT_I18N_TEXT = {
48
48
  ko: '업데이트 날짜',
49
49
  ru: 'Последнее обновление'
50
50
  },
51
+ lastUpdatedAuthorText: {
52
+ en: 'by',
53
+ zh: '作者',
54
+ ja: '更新者',
55
+ ko: '작성자',
56
+ ru: 'автор'
57
+ },
51
58
  prevPageText: {
52
59
  en: 'Previous page',
53
60
  zh: '上一页',
@@ -1,6 +1,6 @@
1
1
  import { __webpack_require__ } from "../../0~rslib-runtime.js";
2
2
  import "../../7986.js";
3
- import { external_node_module_createRequire, join, logger } from "../../4942.js";
3
+ import { external_node_module_createRequire, join, logger } from "../../6010.js";
4
4
  import { DEFAULT_I18N_TEXT } from "./DEFAULT_I18N_TEXT.js";
5
5
  import { createError } from "../utils/error.js";
6
6
  import { pathExists } from "../utils/fs.js";
@@ -1,4 +1,4 @@
1
- import { SEARCH_INDEX_NAME, groupBy } from "../../../4942.js";
1
+ import { SEARCH_INDEX_NAME, groupBy } from "../../../6010.js";
2
2
  import { extractPageData } from "../../route/extractPageData.js";
3
3
  import { createHash } from "../../utils/createHash.js";
4
4
  function deletePrivateField(obj) {
@@ -30,6 +30,7 @@ async function createPageData(context) {
30
30
  const versioned = 'boolean' != typeof userConfig.search && (userConfig.search?.versioned ?? true);
31
31
  const groupedPages = groupBy(pages, (page)=>{
32
32
  if (page.frontmatter?.pageType === 'home') return 'noindex';
33
+ if (page.frontmatter?.search === false) return 'noindex';
33
34
  const version = versioned ? page.version : '';
34
35
  const lang = page.lang || '';
35
36
  return `${version}###${lang}`;
@@ -1,4 +1,4 @@
1
- import { logger, pluginVirtualModule } from "../../../4942.js";
1
+ import { logger, pluginVirtualModule } from "../../../6010.js";
2
2
  import { createPageData } from "./createPageData.js";
3
3
  const rsbuildPluginDocVM = async ({ config, userDocRoot, routeService, pluginDriver })=>{
4
4
  const ref = {
@@ -1,4 +1,4 @@
1
- import { node_path } from "../../4942.js";
1
+ import { node_path } from "../../6010.js";
2
2
  const searchHookVMPlugin = (context)=>({
3
3
  ["virtual-search-hooks"]: ()=>{
4
4
  const { config } = context;
@@ -1,4 +1,4 @@
1
- import { getIconUrlPath } from "../../../4942.js";
1
+ import { getIconUrlPath } from "../../../6010.js";
2
2
  import { normalizeThemeConfig } from "./normalizeThemeConfig.js";
3
3
  async function createSiteData(userConfig) {
4
4
  const tempSearchObj = Object.assign({}, userConfig.search);
@@ -1,4 +1,4 @@
1
- import { isExternalUrl, slash, addLeadingSlash, normalizeHref } from "../../../4942.js";
1
+ import { isExternalUrl, slash, addLeadingSlash, normalizeHref } from "../../../6010.js";
2
2
  import { getI18nData } from "../i18n.js";
3
3
  import { applyReplaceRules } from "../../utils/applyReplaceRules.js";
4
4
  async function normalizeThemeConfig(docConfig) {
@@ -21,6 +21,13 @@ async function normalizeThemeConfig(docConfig) {
21
21
  const cleanUrls = false;
22
22
  const transformLink = (link, currentLang)=>normalizeHref(normalizeLinkPrefix(link, currentLang), cleanUrls);
23
23
  const textReplace = (text, currentLang)=>applyReplaceRules(getI18nText(text, currentLang), replaceRules);
24
+ const normalizeLastUpdated = (lastUpdated)=>{
25
+ if ('object' != typeof lastUpdated || null === lastUpdated) return lastUpdated;
26
+ return {
27
+ ...lastUpdated,
28
+ author: 'function' == typeof lastUpdated.author ? true : lastUpdated.author
29
+ };
30
+ };
24
31
  const normalizeSidebar = (sidebar, currentLang)=>{
25
32
  const normalizedSidebar = {};
26
33
  if (!sidebar) return {};
@@ -89,6 +96,9 @@ async function normalizeThemeConfig(docConfig) {
89
96
  themeConfig.sidebar = normalizeSidebar(themeConfig?.sidebar, '');
90
97
  themeConfig.nav = normalizeNav(themeConfig?.nav, '');
91
98
  }
92
- return themeConfig;
99
+ return {
100
+ ...themeConfig,
101
+ lastUpdated: normalizeLastUpdated(themeConfig.lastUpdated)
102
+ };
93
103
  }
94
104
  export { normalizeThemeConfig };
@@ -1,4 +1,4 @@
1
- import { isProduction, logger } from "../../../4942.js";
1
+ import { isProduction, logger } from "../../../6010.js";
2
2
  import { modifyConfigWithAutoNavSide } from "../../auto-nav-sidebar/index.js";
3
3
  import { createSiteData } from "./createSiteData.js";
4
4
  const siteDataVMPlugin = (context)=>{
@@ -1,4 +1,4 @@
1
- import { mergeRsbuildConfig } from "../4942.js";
1
+ import { mergeRsbuildConfig } from "../6010.js";
2
2
  import { PluginDriver } from "./PluginDriver.js";
3
3
  import { initRsbuild } from "./initRsbuild.js";
4
4
  import { RouteService } from "./route/RouteService.js";
@@ -1,4 +1,4 @@
1
- import { external_node_path_resolve, relative, isAbsolute } from "../../7261.js";
1
+ import { external_node_path_resolve, relative, isAbsolute } from "../../9958.js";
2
2
  const routePath2HtmlFileName = (routePath)=>{
3
3
  let fileName = routePath;
4
4
  fileName = fileName.endsWith('/') ? `${routePath}index.html` : `${routePath}.html`;
@@ -1,6 +1,6 @@
1
1
  import { __webpack_require__ } from "../../0~rslib-runtime.js";
2
2
  import "../../7986.js";
3
- import { createHead, logger, transformHtmlTemplate, pathToFileURL } from "../../7261.js";
3
+ import { createHead, logger, transformHtmlTemplate, pathToFileURL } from "../../9958.js";
4
4
  import { hintSSGFailed } from "../logger/hint.js";
5
5
  import { renderHtmlTemplate } from "./renderHtmlTemplate.js";
6
6
  const picocolors = __webpack_require__("../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js");
@@ -1,7 +1,7 @@
1
1
  import { writeFile, mkdir, dirname, workerData } from "../../6646.js";
2
2
  import { createError } from "../utils/error.js";
3
3
  import { resolveHtmlFilePath } from "./htmlFile.js";
4
- import { pMap } from "../../7261.js";
4
+ import { pMap } from "../../9958.js";
5
5
  import { renderPage } from "./renderPage.js";
6
6
  const params = workerData?.[1]?.params;
7
7
  if (!params) throw createError('SSG Worker Thread workerData params missing');
@@ -1,10 +1,10 @@
1
1
  /*! LICENSE: renderPages.js.LICENSE.txt */
2
2
  import { __webpack_require__ } from "../../0~rslib-runtime.js";
3
3
  import "../../7986.js";
4
- import { chunk, logger } from "../../4942.js";
4
+ import { chunk, logger } from "../../6010.js";
5
5
  import { SSGWorkerThreadTaskSize, getNumberOfThreads, SSGWorkerThreadRecyclerMaxMemory, SSGConcurrency } from "./ssgEnv.js";
6
6
  import { routePath2HtmlFileName } from "./htmlFile.js";
7
- import { pMap } from "../../7261.js";
7
+ import { pMap } from "../../9958.js";
8
8
  import { renderPage } from "./renderPage.js";
9
9
  import { hintSSGFailed } from "../logger/hint.js";
10
10
  import { renderHtmlTemplate } from "./renderHtmlTemplate.js";
@@ -14,7 +14,8 @@ const rsbuildPluginCSR = ({ routeService, config })=>({
14
14
  compilation.emitAsset(assetName, new compiler.webpack.sources.RawSource(content));
15
15
  };
16
16
  let htmlTemplate = '';
17
- for (const [assetName, assetSource] of Object.entries(assets))if ('index.html' === assetName) {
17
+ for (const assetName of Object.keys(assets))if ('index.html' === assetName) {
18
+ const assetSource = assets[assetName];
18
19
  htmlTemplate = assetSource.source().toString();
19
20
  compilation.deleteAsset(assetName);
20
21
  break;
@@ -1,4 +1,4 @@
1
- import { logger, writeFile, mkdir, rm, join, isDebugMode } from "../../4942.js";
1
+ import { logger, writeFile, mkdir, rm, join, isDebugMode } from "../../6010.js";
2
2
  import { NODE_SSG_BUNDLE_FOLDER, NODE_SSG_BUNDLE_NAME } from "../constants.js";
3
3
  import { renderPages } from "./renderPages.js";
4
4
  const rsbuildPluginSSG = ({ routeService, config })=>({
@@ -31,7 +31,8 @@ const rsbuildPluginSSG = ({ routeService, config })=>({
31
31
  resolveOnce();
32
32
  return;
33
33
  }
34
- for (const [assetName, assetSource] of Object.entries(assets))if ('index.html' === assetName) {
34
+ for (const assetName of Object.keys(assets))if ('index.html' === assetName) {
35
+ const assetSource = assets[assetName];
35
36
  htmlTemplate = assetSource.source().toString();
36
37
  compilation.deleteAsset(assetName);
37
38
  resolveOnce();
@@ -64,8 +65,9 @@ const rsbuildPluginSSG = ({ routeService, config })=>({
64
65
  await mkdir(ssgFolderPath, {
65
66
  recursive: true
66
67
  });
67
- await Promise.all(Object.entries(assets).map(async ([assetName, assetSource])=>{
68
+ await Promise.all(Object.keys(assets).map(async (assetName)=>{
68
69
  if (assetName.startsWith(`${NODE_SSG_BUNDLE_FOLDER}/`)) {
70
+ const assetSource = assets[assetName];
69
71
  const fileAbsolutePath = join(distPath, assetName);
70
72
  await writeFile(fileAbsolutePath, assetSource.source().toString());
71
73
  compilation.deleteAsset(assetName);
@@ -1,5 +1,5 @@
1
1
  /*! LICENSE: ssgEnv.js.LICENSE.txt */
2
- import { node_os } from "../../4942.js";
2
+ import { node_os } from "../../6010.js";
3
3
  /**
4
4
  * these codes are copied from
5
5
  * @link https://github.com/facebook/docusaurus/blob/45065e8d2b5831117b8d69fec1be28f5520cf105/packages/docusaurus/src/ssg/ssgEnv.ts#L11