@rspress/core 2.0.16 → 2.0.18

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 (134) hide show
  1. package/bin/rspress.js +6 -1
  2. package/dist/0~execa.js +1 -1
  3. package/dist/{9882.js → 102.js} +1 -1
  4. package/dist/{9958.js → 3553.js} +2 -2
  5. package/dist/{5580.js → 5871.js} +2455 -6
  6. package/dist/cli/index.d.ts +8 -1
  7. package/dist/cli/index.js +105 -102
  8. package/dist/config/loadConfigFile.js +1 -1
  9. package/dist/eject-theme/components/DocContent/docComponents/title.tsx +1 -1
  10. package/dist/eject-theme/components/HomeFeature/index.scss +1 -0
  11. package/dist/eject-theme/components/HomeFeature/index.tsx +1 -1
  12. package/dist/eject-theme/components/HoverGroup/index.scss +9 -0
  13. package/dist/eject-theme/components/Link/index.tsx +1 -1
  14. package/dist/eject-theme/components/Link/useLinkNavigate.ts +17 -4
  15. package/dist/eject-theme/components/Llms/LlmsHiddenHint.test.tsx +23 -0
  16. package/dist/eject-theme/components/Llms/LlmsHiddenHint.tsx +15 -0
  17. package/dist/eject-theme/components/Llms/LlmsOpenRow.tsx +51 -64
  18. package/dist/eject-theme/components/Llms/LlmsViewOptions.tsx +65 -51
  19. package/dist/eject-theme/components/Llms/index.tsx +6 -1
  20. package/dist/eject-theme/components/Outline/index.tsx +1 -1
  21. package/dist/eject-theme/components/SocialLinks/GithubStars.test.tsx +48 -0
  22. package/dist/eject-theme/components/SocialLinks/GithubStars.tsx +35 -20
  23. package/dist/index.d.ts +3 -2
  24. package/dist/index.js +2 -1
  25. package/dist/node/PluginDriver.js +1 -1
  26. package/dist/node/auto-nav-sidebar/index.js +1 -1
  27. package/dist/node/auto-nav-sidebar/locales.js +1 -1
  28. package/dist/node/auto-nav-sidebar/normalize.js +2 -2
  29. package/dist/node/auto-nav-sidebar/utils.js +1 -1
  30. package/dist/node/auto-nav-sidebar/walk.js +1 -1
  31. package/dist/node/constants.js +1 -1
  32. package/dist/node/eject.js +2 -2
  33. package/dist/node/initRsbuild.js +19 -8
  34. package/dist/node/llms.d.ts +3 -0
  35. package/dist/node/llms.js +8 -0
  36. package/dist/node/logger/hint.js +1 -1
  37. package/dist/node/mdx/options.js +1 -1
  38. package/dist/node/mdx/processor.js +1 -1
  39. package/dist/node/mdx/rehypePlugins/codeMeta.js +1 -1
  40. package/dist/node/mdx/rehypePlugins/headerAnchor.js +1 -1
  41. package/dist/node/mdx/rehypePlugins/shiki.js +1 -1
  42. package/dist/node/mdx/remarkPlugins/builtin.js +1 -1
  43. package/dist/node/mdx/remarkPlugins/fileCodeBlock.js +2 -2
  44. package/dist/node/mdx/remarkPlugins/image.js +2 -2
  45. package/dist/node/mdx/remarkPlugins/link.js +2 -2
  46. package/dist/node/mdx/remarkPlugins/toc.js +1 -1
  47. package/dist/node/medium-zoom/index.js +1 -1
  48. package/dist/node/route/RoutePage.js +5 -3
  49. package/dist/node/route/RouteService.js +8 -3
  50. package/dist/node/route/extractPageData.js +1 -1
  51. package/dist/node/route/normalizeRoutePath.js +1 -1
  52. package/dist/node/route/routeChunkAssets.d.ts +15 -0
  53. package/dist/node/route/routeChunkAssets.js +56 -0
  54. package/dist/node/runtimeModule/i18n.js +3 -3
  55. package/dist/node/runtimeModule/pageData/createPageData.js +1 -1
  56. package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +1 -1
  57. package/dist/node/runtimeModule/searchHooks.js +1 -1
  58. package/dist/node/runtimeModule/siteData/createSiteData.js +6 -2
  59. package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +1 -1
  60. package/dist/node/runtimeModule/siteData/rsbuildPlugin.js +1 -1
  61. package/dist/node/serve.js +1 -1
  62. package/dist/node/ssg/alternateLinks.d.ts +7 -0
  63. package/dist/node/ssg/alternateLinks.js +40 -0
  64. package/dist/node/ssg/htmlFile.js +1 -1
  65. package/dist/node/ssg/renderHtmlTemplate.d.ts +3 -1
  66. package/dist/node/ssg/renderHtmlTemplate.js +25 -3
  67. package/dist/node/ssg/renderPage.d.ts +3 -1
  68. package/dist/node/ssg/renderPage.js +4 -4
  69. package/dist/node/ssg/renderPageWorker.js +5 -5
  70. package/dist/node/ssg/renderPages.d.ts +3 -2
  71. package/dist/node/ssg/renderPages.js +16 -11
  72. package/dist/node/ssg/rsbuildPluginCSR.d.ts +3 -1
  73. package/dist/node/ssg/rsbuildPluginCSR.js +2 -2
  74. package/dist/node/ssg/rsbuildPluginSSG.d.ts +3 -1
  75. package/dist/node/ssg/rsbuildPluginSSG.js +3 -3
  76. package/dist/node/ssg/ssgEnv.js +1 -1
  77. package/dist/node/ssg-md/llms/emitLlmsTxt.js +3 -3
  78. package/dist/node/ssg-md/llms/llmsTxt.d.ts +4 -4
  79. package/dist/node/ssg-md/llms/llmsTxt.js +54 -40
  80. package/dist/node/ssg-md/remarkSplitMdx.js +1 -1
  81. package/dist/node/ssg-md/renderPage.js +2 -2
  82. package/dist/node/ssg-md/renderPages.js +3 -3
  83. package/dist/node/ssg-md/rsbuildPluginSSGMD.js +1 -1
  84. package/dist/node/utils/checkLanguageParity.js +1 -1
  85. package/dist/node/utils/createHash.d.ts +1 -1
  86. package/dist/node/utils/createHash.js +3 -3
  87. package/dist/node/utils/error.js +1 -1
  88. package/dist/node/utils/flattenMdxContent.js +1 -1
  89. package/dist/node/utils/fs.js +1 -1
  90. package/dist/node/utils/getPageKey.js +1 -1
  91. package/dist/node/utils/normalizePath.js +1 -1
  92. package/dist/node/utils/reactAlias.js +2 -2
  93. package/dist/runtime/App.js +2 -0
  94. package/dist/runtime/ClientApp.js +3 -2
  95. package/dist/runtime/index.d.ts +1 -1
  96. package/dist/runtime/index.js +1 -1
  97. package/dist/runtime/route.js +2 -0
  98. package/dist/runtime/utils.d.ts +2 -1
  99. package/dist/runtime/utils.js +5 -2
  100. package/dist/theme/assets/anthropic.js +15 -0
  101. package/dist/theme/assets/open-in-chat.js +19 -0
  102. package/dist/theme/assets/openai.js +15 -0
  103. package/dist/theme/components/DocContent/docComponents/index.d.ts +25 -18
  104. package/dist/theme/components/DocContent/docComponents/title.js +1 -1
  105. package/dist/theme/components/HomeFeature/index.css +1 -0
  106. package/dist/theme/components/HomeFeature/index.js +32 -34
  107. package/dist/theme/components/HoverGroup/index.css +7 -0
  108. package/dist/theme/components/Link/index.d.ts +1 -1
  109. package/dist/theme/components/Link/useLinkNavigate.d.ts +1 -1
  110. package/dist/theme/components/Link/useLinkNavigate.js +13 -5
  111. package/dist/theme/components/Llms/LlmsHiddenHint.d.ts +1 -0
  112. package/dist/theme/components/Llms/LlmsHiddenHint.js +18 -0
  113. package/dist/theme/components/Llms/LlmsOpenRow.js +31 -57
  114. package/dist/theme/components/Llms/LlmsViewOptions.d.ts +6 -4
  115. package/dist/theme/components/Llms/LlmsViewOptions.js +28 -45
  116. package/dist/theme/components/Llms/index.d.ts +2 -1
  117. package/dist/theme/components/Llms/index.js +1 -0
  118. package/dist/theme/components/Outline/index.js +1 -1
  119. package/dist/theme/components/Search/SearchPanel.js +8 -8
  120. package/dist/theme/components/SocialLinks/GithubStars.js +27 -17
  121. package/dist/theme/icons.d.ts +4 -1
  122. package/dist/theme/icons.js +8 -2
  123. package/dist/theme/index.d.ts +1 -1
  124. package/dist/theme/index.js +1 -1
  125. package/dist/theme/logic/getCopyableText.js +1 -0
  126. package/package.json +11 -11
  127. package/dist/6010.js +0 -2461
  128. package/dist/{0~8787.js → 0~8016.js} +0 -0
  129. package/dist/{7986.js → 4538.js} +0 -0
  130. package/dist/{3358.js → 5357.js} +0 -0
  131. package/dist/{5580.js.LICENSE.txt → 5871.js.LICENSE.txt} +0 -0
  132. package/dist/{8005.js → 7748.js} +2 -2
  133. /package/dist/{6646.js → 9857.js} +0 -0
  134. /package/dist/{9283.js → 9940.js} +0 -0
@@ -1,6 +1,6 @@
1
1
  import { __webpack_require__ } from "../../../0~rslib-runtime.js";
2
- import "../../../7986.js";
3
- import { normalizeHref, node_path, addLeadingSlash, logger, visit, isExternalUrl, isProduction, parseUrl, MDX_OR_MD_REGEXP, withBase } from "../../../3358.js";
2
+ import "../../../4538.js";
3
+ import { normalizeHref, node_path, addLeadingSlash, logger, visit, isExternalUrl, isProduction, parseUrl, MDX_OR_MD_REGEXP, withBase } from "../../../5357.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");
@@ -1,4 +1,4 @@
1
- import { visitChildren, extractTextAndId, github_slugger, slug } from "../../../8005.js";
1
+ import { visitChildren, extractTextAndId, github_slugger, slug } from "../../../7748.js";
2
2
  const extractChildText = (child, preserveInlineMarkdown = true)=>{
3
3
  if ('link' === child.type) return child.children?.map((child)=>extractChildText(child, preserveInlineMarkdown)).join('') ?? '';
4
4
  if ('strong' === child.type) {
@@ -1,4 +1,4 @@
1
- import { node_path } from "../../0~8787.js";
1
+ import { node_path } from "../../0~8016.js";
2
2
  import { PACKAGE_ROOT } from "../constants.js";
3
3
  function pluginMediumZoom(options = {}) {
4
4
  return {
@@ -1,4 +1,4 @@
1
- import { node_path } from "../../6010.js";
1
+ import { node_path } from "../../5871.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";
@@ -23,9 +23,10 @@ class RoutePage {
23
23
  }
24
24
  static generateRouteMeta(routePath, filepath, docDir) {
25
25
  const routeService = RouteService.getInstance();
26
- const { routePath: normalizedPath, lang, version } = routeService.normalizeRoutePath(routePath);
26
+ const { routePath: normalizedPath, lang, pureRoutePath, version } = routeService.normalizeRoutePath(routePath);
27
27
  return {
28
28
  routePath: normalizedPath,
29
+ pureRoutePath,
29
30
  absolutePath: normalizePath(filepath),
30
31
  relativePath: absolutePathToRelativePath(filepath, docDir),
31
32
  pageName: getPageKey(routePath),
@@ -39,11 +40,12 @@ function absolutePathToRelativePath(absolutePath, docsDir) {
39
40
  }
40
41
  function absolutePathToRouteMeta(absolutePath, docsDir, routeService = RouteService.getInstance()) {
41
42
  const relativePath = absolutePathToRelativePath(absolutePath, docsDir);
42
- const { lang, routePath, version } = routeService.normalizeRoutePath(relativePath);
43
+ const { lang, pureRoutePath, routePath, version } = routeService.normalizeRoutePath(relativePath);
43
44
  return {
44
45
  pageName: getPageKey(relativePath),
45
46
  absolutePath,
46
47
  lang,
48
+ pureRoutePath,
47
49
  version,
48
50
  routePath,
49
51
  relativePath
@@ -1,6 +1,7 @@
1
- import { RSPRESS_TEMP_DIR, node_path, removeTrailingSlash, promises, addTrailingSlash, DEFAULT_PAGE_EXTENSIONS, glob } from "../../6010.js";
1
+ import { RSPRESS_TEMP_DIR, node_path, removeTrailingSlash, promises, addTrailingSlash, DEFAULT_PAGE_EXTENSIONS, glob } from "../../5871.js";
2
2
  import { RoutePage, absolutePathToRoutePath, absolutePathToRelativePath } from "./RoutePage.js";
3
3
  import { createError } from "../utils/error.js";
4
+ import { getRouteChunkName } from "./routeChunkAssets.js";
4
5
  import { getRoutePathParts, normalizeRoutePath, splitRoutePathParts } from "./normalizeRoutePath.js";
5
6
  class RouteService {
6
7
  routeData = new Map();
@@ -152,12 +153,16 @@ class RouteService {
152
153
  return `
153
154
  import React from 'react';
154
155
  import { lazyWithPreload } from "react-lazy-with-preload";
155
- ${routeMeta.map((route, index)=>`const Route${index} = lazyWithPreload(() => import('${route.absolutePath}'))`).join('\n')}
156
+ ${routeMeta.map((route, index)=>{
157
+ const chunkName = getRouteChunkName(route);
158
+ return `const loadRoute${index} = () => import(/* webpackChunkName: "${chunkName}" */ '${route.absolutePath}')
159
+ const Route${index} = lazyWithPreload(loadRoute${index})`;
160
+ }).join('\n')}
156
161
  export const routes = [
157
162
  ${routeMeta.map((route, index)=>{
158
163
  const preload = `async () => {
159
164
  await Route${index}.preload();
160
- return import("${route.absolutePath}");
165
+ return loadRoute${index}();
161
166
  }`;
162
167
  const component = `Route${index}`;
163
168
  return `{ path: '${route.routePath}', element: React.createElement(${component}), filePath: '${route.relativePath}', preload: ${preload}, lang: '${route.lang}', version: '${route.version}' }`;
@@ -1,4 +1,4 @@
1
- import { unified, node_path, promises, loadFrontMatter, remove, remark_gfm, MDX_OR_MD_REGEXP, remark_parse } from "../../6010.js";
1
+ import { unified, node_path, promises, loadFrontMatter, remove, remark_gfm, MDX_OR_MD_REGEXP, remark_parse } from "../../5871.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 "../../6010.js";
1
+ import { addTrailingSlash, DEFAULT_PAGE_EXTENSIONS, addLeadingSlash } from "../../5871.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 [
@@ -0,0 +1,15 @@
1
+ import type { Rspack } from '@rsbuild/core';
2
+ import type { RouteMeta } from '@rspress/shared';
3
+ import type { RouteService } from './RouteService.js';
4
+ export interface RouteChunkAssetsManifest {
5
+ assetPrefix: string;
6
+ assets: Record<string, string[]>;
7
+ }
8
+ export declare function getRouteChunkName(route: RouteMeta): string;
9
+ export declare class RouteChunkAssetsPlugin implements Rspack.RspackPluginInstance {
10
+ #private;
11
+ private readonly routeService;
12
+ constructor(routeService: RouteService);
13
+ apply(compiler: Rspack.Compiler): void;
14
+ getManifest(): RouteChunkAssetsManifest;
15
+ }
@@ -0,0 +1,56 @@
1
+ import { createHash } from "../utils/createHash.js";
2
+ const PLUGIN_NAME = 'RspressRouteChunkAssetsPlugin';
3
+ const JAVASCRIPT_ASSET_REGEXP = /\.[cm]?js$/;
4
+ const ROUTE_CHUNK_HASH_LENGTH = 12;
5
+ function getRouteChunkName(route) {
6
+ return `route-${createHash(route.relativePath, ROUTE_CHUNK_HASH_LENGTH)}`;
7
+ }
8
+ class RouteChunkAssetsPlugin {
9
+ routeService;
10
+ #assetPrefix = '/';
11
+ #chunks = new Map();
12
+ constructor(routeService){
13
+ this.routeService = routeService;
14
+ }
15
+ apply(compiler) {
16
+ compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation)=>{
17
+ this.#assetPrefix = 'string' == typeof compilation.outputOptions.publicPath ? compilation.outputOptions.publicPath : '/';
18
+ this.#chunks.clear();
19
+ const routePathsByChunkName = new Map();
20
+ for (const route of this.routeService.getRoutes()){
21
+ const chunkName = getRouteChunkName(route);
22
+ const routePaths = routePathsByChunkName.get(chunkName) ?? [];
23
+ routePaths.push(route.routePath);
24
+ routePathsByChunkName.set(chunkName, routePaths);
25
+ }
26
+ compilation.hooks.chunkAsset.tap(PLUGIN_NAME, (chunk)=>{
27
+ if (!chunk.name) return;
28
+ const routePaths = routePathsByChunkName.get(chunk.name);
29
+ if (!routePaths) return;
30
+ for (const routePath of routePaths){
31
+ const chunks = this.#chunks.get(routePath) ?? new Set();
32
+ chunks.add(chunk);
33
+ this.#chunks.set(routePath, chunks);
34
+ }
35
+ });
36
+ });
37
+ }
38
+ getManifest() {
39
+ return {
40
+ assetPrefix: this.#assetPrefix,
41
+ assets: Object.fromEntries([
42
+ ...this.#chunks
43
+ ].map(([routePath, chunks])=>{
44
+ const assets = new Set();
45
+ for (const chunk of chunks)for (const filename of chunk.files)if (JAVASCRIPT_ASSET_REGEXP.test(filename)) assets.add(filename);
46
+ return [
47
+ routePath,
48
+ [
49
+ ...assets
50
+ ]
51
+ ];
52
+ }))
53
+ };
54
+ }
55
+ }
56
+ export { RouteChunkAssetsPlugin, getRouteChunkName };
@@ -1,12 +1,12 @@
1
1
  import { __webpack_require__ } from "../../0~rslib-runtime.js";
2
- import "../../7986.js";
3
- import { external_node_module_createRequire, join, logger } from "../../6010.js";
2
+ import "../../4538.js";
3
+ import { createRequire, join, logger } from "../../5871.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";
7
7
  const picocolors = __webpack_require__("../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js");
8
8
  var picocolors_default = /*#__PURE__*/ __webpack_require__.n(picocolors);
9
- const i18n_require = external_node_module_createRequire(import.meta.url);
9
+ const i18n_require = createRequire(import.meta.url);
10
10
  const DEFAULT_I18N_SOURCE_PATH = join(process.cwd(), 'i18n.json');
11
11
  function mergeI18nData(...sources) {
12
12
  const result = {};
@@ -1,4 +1,4 @@
1
- import { SEARCH_INDEX_NAME, groupBy } from "../../../6010.js";
1
+ import { SEARCH_INDEX_NAME, groupBy } from "../../../5871.js";
2
2
  import { extractPageData } from "../../route/extractPageData.js";
3
3
  import { createHash } from "../../utils/createHash.js";
4
4
  function deletePrivateField(obj) {
@@ -1,4 +1,4 @@
1
- import { logger, pluginVirtualModule } from "../../../6010.js";
1
+ import { logger, pluginVirtualModule } from "../../../5871.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 "../../6010.js";
1
+ import { node_path } from "../../5871.js";
2
2
  const searchHookVMPlugin = (context)=>({
3
3
  ["virtual-search-hooks"]: ()=>{
4
4
  const { config } = context;
@@ -1,14 +1,18 @@
1
- import { getIconUrlPath } from "../../../6010.js";
1
+ import { getIconUrlPath } from "../../../5871.js";
2
2
  import { normalizeThemeConfig } from "./normalizeThemeConfig.js";
3
3
  async function createSiteData(userConfig) {
4
4
  const tempSearchObj = Object.assign({}, userConfig.search);
5
5
  if (tempSearchObj) tempSearchObj.searchHooks = void 0;
6
6
  const siteData = {
7
7
  base: userConfig.base ?? '/',
8
+ siteOrigin: userConfig.siteOrigin ?? '',
8
9
  title: userConfig?.title || '',
9
10
  description: userConfig?.description || '',
10
11
  icon: getIconUrlPath(userConfig?.icon) || '',
11
- route: userConfig?.route || {},
12
+ route: {
13
+ useTransitions: true,
14
+ ...userConfig?.route
15
+ },
12
16
  themeConfig: await normalizeThemeConfig(userConfig),
13
17
  lang: userConfig?.lang || '',
14
18
  locales: userConfig?.locales || userConfig.themeConfig?.locales || [],
@@ -1,4 +1,4 @@
1
- import { isExternalUrl, slash, addLeadingSlash, normalizeHref } from "../../../6010.js";
1
+ import { isExternalUrl, slash, addLeadingSlash, normalizeHref } from "../../../5871.js";
2
2
  import { getI18nData } from "../i18n.js";
3
3
  import { applyReplaceRules } from "../../utils/applyReplaceRules.js";
4
4
  async function normalizeThemeConfig(docConfig) {
@@ -1,4 +1,4 @@
1
- import { isProduction, logger } from "../../../6010.js";
1
+ import { isProduction, logger } from "../../../5871.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 "../6010.js";
1
+ import { mergeRsbuildConfig } from "../5871.js";
2
2
  import { PluginDriver } from "./PluginDriver.js";
3
3
  import { initRsbuild } from "./initRsbuild.js";
4
4
  import { RouteService } from "./route/RouteService.js";
@@ -0,0 +1,7 @@
1
+ import { type RouteMeta, type UserConfig } from '@rspress/shared';
2
+ export interface AlternateLink {
3
+ href: string;
4
+ hrefLang: string;
5
+ }
6
+ export type AlternateLinksByRoute = Partial<Record<string, AlternateLink[]>>;
7
+ export declare function createAlternateLinksByRoute(routes: RouteMeta[], config: UserConfig): AlternateLinksByRoute;
@@ -0,0 +1,40 @@
1
+ import { normalizeHref, removeTrailingSlash, addLeadingSlash, normalizePosixPath, withSiteOrigin } from "../../5871.js";
2
+ function createAlternateLinksByRoute(routes, config) {
3
+ const routeGroups = new Map();
4
+ for (const route of routes){
5
+ if (!route.lang) continue;
6
+ const groupKey = JSON.stringify([
7
+ route.version,
8
+ route.pureRoutePath
9
+ ]);
10
+ const routeGroup = routeGroups.get(groupKey) ?? [];
11
+ routeGroup.push(route);
12
+ routeGroups.set(groupKey, routeGroup);
13
+ }
14
+ const locales = config.locales ?? config.themeConfig?.locales ?? [];
15
+ const localeOrder = new Map(locales.map(({ lang }, index)=>[
16
+ lang,
17
+ index
18
+ ]));
19
+ const alternateLinksByRoute = {};
20
+ for (const routeGroup of routeGroups.values()){
21
+ const routesByLang = new Map(routeGroup.map((route)=>[
22
+ route.lang,
23
+ route
24
+ ]));
25
+ if (routesByLang.size < 2) continue;
26
+ const alternateRoutes = Array.from(routesByLang.values()).sort((a, b)=>(localeOrder.get(a.lang) ?? Number.MAX_SAFE_INTEGER) - (localeOrder.get(b.lang) ?? Number.MAX_SAFE_INTEGER) || a.lang.localeCompare(b.lang));
27
+ const alternateLinks = alternateRoutes.map((route)=>({
28
+ href: getRouteHref(route.routePath, config),
29
+ hrefLang: route.lang.replaceAll('_', '-')
30
+ }));
31
+ for (const route of alternateRoutes)alternateLinksByRoute[route.routePath] = alternateLinks;
32
+ }
33
+ return alternateLinksByRoute;
34
+ }
35
+ function getRouteHref(routePath, config) {
36
+ const normalizedHref = normalizeHref(routePath, config.route?.cleanUrls ?? false);
37
+ const normalizedBase = removeTrailingSlash(addLeadingSlash(normalizePosixPath(config.base ?? '/')));
38
+ return withSiteOrigin(`${normalizedBase}${normalizedHref}`, config.siteOrigin);
39
+ }
40
+ export { createAlternateLinksByRoute };
@@ -1,4 +1,4 @@
1
- import { external_node_path_resolve, relative, isAbsolute } from "../../9958.js";
1
+ import { external_node_path_resolve, relative, isAbsolute } from "../../3553.js";
2
2
  const routePath2HtmlFileName = (routePath)=>{
3
3
  let fileName = routePath;
4
4
  fileName = fileName.endsWith('/') ? `${routePath}index.html` : `${routePath}.html`;
@@ -1,2 +1,4 @@
1
1
  import type { RouteMeta, UserConfig } from '@rspress/shared';
2
- export declare function renderHtmlTemplate(htmlTemplate: string, head: UserConfig['head'], route: RouteMeta, appHtml?: string): Promise<string>;
2
+ import type { RouteChunkAssetsManifest } from '../route/routeChunkAssets.js';
3
+ import type { AlternateLink } from './alternateLinks.js';
4
+ export declare function renderHtmlTemplate(htmlTemplate: string, head: UserConfig['head'], route: RouteMeta, appHtml?: string, alternateLinks?: AlternateLink[], routeChunkAssets?: RouteChunkAssetsManifest): Promise<string>;
@@ -1,4 +1,6 @@
1
+ import { posix } from "../../3553.js";
1
2
  import { META_GENERATOR, RSPRESS_VERSION, APP_HTML_MARKER, HEAD_MARKER } from "../constants.js";
3
+ import { routePath2HtmlFileName } from "./htmlFile.js";
2
4
  import { createError } from "../utils/error.js";
3
5
  async function renderConfigHead(head, route) {
4
6
  if (!isRouteMeta(route)) return '';
@@ -14,18 +16,38 @@ async function renderConfigHead(head, route) {
14
16
  return `<${head[0]} ${renderAttrs(head[1])}>`;
15
17
  }).join('');
16
18
  }
17
- async function renderHtmlTemplate(htmlTemplate, head, route, appHtml = '') {
19
+ async function renderHtmlTemplate(htmlTemplate, head, route, appHtml = '', alternateLinks = [], routeChunkAssets) {
20
+ const alternateLinkTags = alternateLinks.map(({ href, hrefLang })=>`<link ${renderAttrs({
21
+ rel: 'alternate',
22
+ hreflang: hrefLang,
23
+ href
24
+ })}>`).join('');
25
+ const routePreloadLinks = renderRoutePreloadLinks(route, routeChunkAssets);
18
26
  const replacedHtmlTemplate = htmlTemplate.replace(APP_HTML_MARKER, ()=>appHtml).replace(META_GENERATOR, ()=>`<meta name="generator" content="Rspress v${RSPRESS_VERSION}">`).replace(HEAD_MARKER, [
19
- await renderConfigHead(head, route)
27
+ routePreloadLinks,
28
+ await renderConfigHead(head, route),
29
+ alternateLinkTags
20
30
  ].join(''));
21
31
  return replacedHtmlTemplate;
22
32
  }
33
+ function renderRoutePreloadLinks(route, manifest) {
34
+ if (!manifest) return '';
35
+ const assets = manifest.assets[route.routePath];
36
+ if (!assets) return '';
37
+ return assets.map((asset)=>{
38
+ const href = 'auto' === manifest.assetPrefix ? posix.relative(posix.dirname(routePath2HtmlFileName(route.routePath)), asset) : `${manifest.assetPrefix}${asset}`;
39
+ return `<link rel="preload" href="${escapeHtmlAttribute(href)}" as="script">`;
40
+ }).join('');
41
+ }
42
+ function escapeHtmlAttribute(value) {
43
+ return value.replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
44
+ }
23
45
  function renderAttrs(attrs) {
24
46
  return Object.entries(attrs).map(([key, value])=>{
25
47
  if ('boolean' == typeof value) return key;
26
48
  if ('string' == typeof value || 'number' == typeof value) return `${key}="${value}"`;
27
49
  throw createError(`Invalid value for attribute ${key}:${JSON.stringify(value)}`);
28
- }).join('');
50
+ }).join(' ');
29
51
  }
30
52
  function isRouteMeta(route) {
31
53
  return !!route && 'object' == typeof route && 'routePath' in route && 'absolutePath' in route;
@@ -1,2 +1,4 @@
1
1
  import type { RouteMeta, UserConfig } from '@rspress/shared';
2
- export declare function renderPage(route: RouteMeta, htmlTemplate: string, configHead: UserConfig['head'], ssrBundlePath: string): Promise<string>;
2
+ import type { RouteChunkAssetsManifest } from '../route/routeChunkAssets.js';
3
+ import type { AlternateLink } from './alternateLinks.js';
4
+ export declare function renderPage(route: RouteMeta, htmlTemplate: string, configHead: UserConfig['head'], ssrBundlePath: string, alternateLinks?: AlternateLink[], routeChunkAssets?: RouteChunkAssetsManifest): Promise<string>;
@@ -1,11 +1,11 @@
1
1
  import { __webpack_require__ } from "../../0~rslib-runtime.js";
2
- import "../../7986.js";
3
- import { createHead, logger, transformHtmlTemplate, pathToFileURL } from "../../9958.js";
2
+ import "../../4538.js";
3
+ import { createHead, logger, transformHtmlTemplate, pathToFileURL } from "../../3553.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");
7
7
  var picocolors_default = /*#__PURE__*/ __webpack_require__.n(picocolors);
8
- async function renderPage(route, htmlTemplate, configHead, ssrBundlePath) {
8
+ async function renderPage(route, htmlTemplate, configHead, ssrBundlePath, alternateLinks = [], routeChunkAssets) {
9
9
  let render;
10
10
  try {
11
11
  let { default: ssrExports } = await import(pathToFileURL(ssrBundlePath).toString());
@@ -31,7 +31,7 @@ ${absolutePath ? picocolors_default().gray(` File: ${absolutePath}\n`) : ''}
31
31
  throw e;
32
32
  }
33
33
  }
34
- const replacedHtmlTemplate = await renderHtmlTemplate(htmlTemplate, configHead, route, appHtml);
34
+ const replacedHtmlTemplate = await renderHtmlTemplate(htmlTemplate, configHead, route, appHtml, alternateLinks, routeChunkAssets);
35
35
  const html = await transformHtmlTemplate(head, replacedHtmlTemplate);
36
36
  return html;
37
37
  }
@@ -1,11 +1,11 @@
1
- import { writeFile, mkdir, dirname, workerData } from "../../6646.js";
1
+ import { writeFile, mkdir, dirname, workerData } from "../../9857.js";
2
2
  import { createError } from "../utils/error.js";
3
3
  import { resolveHtmlFilePath } from "./htmlFile.js";
4
- import { pMap } from "../../9958.js";
4
+ import { pMap } from "../../3553.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');
8
- const { htmlTemplate: htmlTemplate, head: head, ssrBundlePath: ssrBundlePath, distPath: distPath } = params;
8
+ const { htmlTemplate: htmlTemplate, head: head, ssrBundlePath: ssrBundlePath, alternateLinksByRoute: alternateLinksByRoute, distPath: distPath, routeChunkAssets: routeChunkAssets } = params;
9
9
  async function writeHtmlFile(routePath, html) {
10
10
  if (!distPath) return;
11
11
  const fileAbsolutePath = resolveHtmlFilePath(distPath, routePath);
@@ -17,7 +17,7 @@ async function writeHtmlFile(routePath, html) {
17
17
  const exportWorkerGlueFn = async ({ routes })=>{
18
18
  if (distPath) {
19
19
  await pMap(routes, async (route)=>{
20
- const html = await renderPage(route, htmlTemplate, head, ssrBundlePath);
20
+ const html = await renderPage(route, htmlTemplate, head, ssrBundlePath, alternateLinksByRoute[route.routePath] ?? [], routeChunkAssets);
21
21
  await writeHtmlFile(route.routePath, html);
22
22
  }, {
23
23
  concurrency: 10
@@ -25,7 +25,7 @@ const exportWorkerGlueFn = async ({ routes })=>{
25
25
  return [];
26
26
  }
27
27
  return pMap(routes, async (route)=>{
28
- const html = await renderPage(route, htmlTemplate, head, ssrBundlePath);
28
+ const html = await renderPage(route, htmlTemplate, head, ssrBundlePath, alternateLinksByRoute[route.routePath] ?? [], routeChunkAssets);
29
29
  return html;
30
30
  }, {
31
31
  concurrency: 10
@@ -1,4 +1,5 @@
1
1
  import type { UserConfig } from '@rspress/shared';
2
2
  import type { RouteService } from '../route/RouteService.js';
3
- export declare function renderPages(routeService: RouteService, config: UserConfig, ssrBundlePath: string, htmlTemplate: string, emitAsset: (assetName: string, content: string | Buffer) => void, workerOutputDistPath?: string): Promise<void>;
4
- export declare function renderCSRPages(routeService: RouteService, config: UserConfig, htmlTemplate: string, emitAsset: (assetName: string, content: string | Buffer) => void): Promise<void>;
3
+ import type { RouteChunkAssetsManifest } from '../route/routeChunkAssets.js';
4
+ export declare function renderPages(routeService: RouteService, config: UserConfig, ssrBundlePath: string, htmlTemplate: string, emitAsset: (assetName: string, content: string | Buffer) => void, workerOutputDistPath?: string, routeChunkAssets?: RouteChunkAssetsManifest): Promise<void>;
5
+ export declare function renderCSRPages(routeService: RouteService, config: UserConfig, htmlTemplate: string, emitAsset: (assetName: string, content: string | Buffer) => void, routeChunkAssets?: RouteChunkAssetsManifest): Promise<void>;
@@ -1,20 +1,22 @@
1
1
  /*! LICENSE: renderPages.js.LICENSE.txt */
2
2
  import { __webpack_require__ } from "../../0~rslib-runtime.js";
3
- import "../../7986.js";
4
- import { chunk, logger } from "../../6010.js";
3
+ import "../../4538.js";
4
+ import { chunk, logger } from "../../5871.js";
5
+ import { createAlternateLinksByRoute } from "./alternateLinks.js";
5
6
  import { SSGWorkerThreadTaskSize, getNumberOfThreads, SSGWorkerThreadRecyclerMaxMemory, SSGConcurrency } from "./ssgEnv.js";
6
7
  import { routePath2HtmlFileName } from "./htmlFile.js";
7
- import { pMap } from "../../9958.js";
8
+ import { pMap } from "../../3553.js";
8
9
  import { renderPage } from "./renderPage.js";
9
10
  import { hintSSGFailed } from "../logger/hint.js";
10
11
  import { renderHtmlTemplate } from "./renderHtmlTemplate.js";
11
12
  const picocolors = __webpack_require__("../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js");
12
13
  var picocolors_default = /*#__PURE__*/ __webpack_require__.n(picocolors);
13
- async function renderPages(routeService, config, ssrBundlePath, htmlTemplate, emitAsset, workerOutputDistPath) {
14
+ async function renderPages(routeService, config, ssrBundlePath, htmlTemplate, emitAsset, workerOutputDistPath, routeChunkAssets) {
14
15
  const startTime = Date.now();
15
16
  const ssg = config.ssg ?? true;
16
17
  try {
17
18
  const routes = routeService.getRoutes();
19
+ const alternateLinksByRoute = createAlternateLinksByRoute(routes, config);
18
20
  if (!routeService.isExistRoute('/404')) routes.push({
19
21
  routePath: '/404'
20
22
  });
@@ -28,7 +30,7 @@ async function renderPages(routeService, config, ssrBundlePath, htmlTemplate, em
28
30
  const ssgRoutes = [];
29
31
  for (const route of routes)if (shouldIgnoreRoutePaths.has(route.routePath) || shouldIgnoreRoutePathsRegExp.some((reg)=>reg.test(route.routePath))) {
30
32
  csrRoutes.push(route);
31
- promiseList.push(renderCSRPage(config.head, route, htmlTemplate, emitAsset));
33
+ promiseList.push(renderCSRPage(config.head, route, htmlTemplate, alternateLinksByRoute, emitAsset, routeChunkAssets));
32
34
  } else ssgRoutes.push(route);
33
35
  if (csrRoutes.length > 0) {
34
36
  const csrRoutePaths = csrRoutes.map((r)=>r.routePath);
@@ -60,7 +62,9 @@ async function renderPages(routeService, config, ssrBundlePath, htmlTemplate, em
60
62
  htmlTemplate,
61
63
  head: config.head,
62
64
  ssrBundlePath,
63
- distPath: workerOutputDistPath
65
+ alternateLinksByRoute,
66
+ distPath: workerOutputDistPath,
67
+ routeChunkAssets
64
68
  }
65
69
  }
66
70
  });
@@ -80,7 +84,7 @@ async function renderPages(routeService, config, ssrBundlePath, htmlTemplate, em
80
84
  } else {
81
85
  logger.info('Rendering pages...');
82
86
  await pMap(routes, async (route)=>{
83
- const html = await renderPage(route, htmlTemplate, config.head, ssrBundlePath);
87
+ const html = await renderPage(route, htmlTemplate, config.head, ssrBundlePath, alternateLinksByRoute[route.routePath] ?? [], routeChunkAssets);
84
88
  const fileName = routePath2HtmlFileName(route.routePath);
85
89
  emitAsset(fileName, html);
86
90
  }, {
@@ -98,16 +102,17 @@ async function renderPages(routeService, config, ssrBundlePath, htmlTemplate, em
98
102
  throw e;
99
103
  }
100
104
  }
101
- async function renderCSRPage(head, route, htmlTemplate, emitAsset) {
102
- const html = await renderHtmlTemplate(htmlTemplate, head, route, '');
105
+ async function renderCSRPage(head, route, htmlTemplate, alternateLinksByRoute, emitAsset, routeChunkAssets) {
106
+ const html = await renderHtmlTemplate(htmlTemplate, head, route, '', alternateLinksByRoute[route.routePath] ?? [], routeChunkAssets);
103
107
  const fileName = routePath2HtmlFileName(route.routePath);
104
108
  emitAsset(fileName, html);
105
109
  }
106
- async function renderCSRPages(routeService, config, htmlTemplate, emitAsset) {
110
+ async function renderCSRPages(routeService, config, htmlTemplate, emitAsset, routeChunkAssets) {
107
111
  const routes = routeService.getRoutes();
112
+ const alternateLinksByRoute = createAlternateLinksByRoute(routes, config);
108
113
  if (!routeService.isExistRoute('/404')) routes.push({
109
114
  routePath: '/404'
110
115
  });
111
- await Promise.all(routes.map((route)=>renderCSRPage(config.head, route, htmlTemplate, emitAsset)));
116
+ await Promise.all(routes.map((route)=>renderCSRPage(config.head, route, htmlTemplate, alternateLinksByRoute, emitAsset, routeChunkAssets)));
112
117
  }
113
118
  export { renderCSRPages, renderPages };
@@ -1,7 +1,9 @@
1
1
  import type { RsbuildPlugin } from '@rsbuild/core';
2
2
  import type { UserConfig } from '@rspress/shared';
3
3
  import type { RouteService } from '../route/RouteService.js';
4
- export declare const rsbuildPluginCSR: ({ routeService, config, }: {
4
+ import type { RouteChunkAssetsPlugin } from '../route/routeChunkAssets.js';
5
+ export declare const rsbuildPluginCSR: ({ routeService, config, routeChunkAssets, }: {
5
6
  routeService: RouteService;
6
7
  config: UserConfig;
8
+ routeChunkAssets: RouteChunkAssetsPlugin;
7
9
  }) => RsbuildPlugin;
@@ -1,5 +1,5 @@
1
1
  import { renderCSRPages } from "./renderPages.js";
2
- const rsbuildPluginCSR = ({ routeService, config })=>({
2
+ const rsbuildPluginCSR = ({ routeService, config, routeChunkAssets })=>({
3
3
  name: 'rspress-inner-rsbuild-plugin-csr',
4
4
  async setup (api) {
5
5
  api.onBeforeBuild(()=>{
@@ -20,7 +20,7 @@ const rsbuildPluginCSR = ({ routeService, config })=>({
20
20
  compilation.deleteAsset(assetName);
21
21
  break;
22
22
  }
23
- await renderCSRPages(routeService, config, htmlTemplate, emitAsset);
23
+ await renderCSRPages(routeService, config, htmlTemplate, emitAsset, routeChunkAssets.getManifest());
24
24
  });
25
25
  });
26
26
  }
@@ -1,7 +1,9 @@
1
1
  import type { RsbuildPlugin } from '@rsbuild/core';
2
2
  import { type UserConfig } from '@rspress/shared';
3
3
  import type { RouteService } from '../route/RouteService.js';
4
- export declare const rsbuildPluginSSG: ({ routeService, config, }: {
4
+ import type { RouteChunkAssetsPlugin } from '../route/routeChunkAssets.js';
5
+ export declare const rsbuildPluginSSG: ({ routeService, config, routeChunkAssets, }: {
5
6
  routeService: RouteService;
6
7
  config: UserConfig;
8
+ routeChunkAssets: RouteChunkAssetsPlugin;
7
9
  }) => RsbuildPlugin;
@@ -1,7 +1,7 @@
1
- import { logger, writeFile, mkdir, rm, join, isDebugMode } from "../../6010.js";
1
+ import { logger, writeFile, mkdir, rm, join, isDebugMode } from "../../5871.js";
2
2
  import { NODE_SSG_BUNDLE_FOLDER, NODE_SSG_BUNDLE_NAME } from "../constants.js";
3
3
  import { renderPages } from "./renderPages.js";
4
- const rsbuildPluginSSG = ({ routeService, config })=>({
4
+ const rsbuildPluginSSG = ({ routeService, config, routeChunkAssets })=>({
5
5
  name: 'rspress-inner-rsbuild-plugin-ssg',
6
6
  async setup (api) {
7
7
  api.onBeforeBuild(()=>{
@@ -75,7 +75,7 @@ const rsbuildPluginSSG = ({ routeService, config })=>({
75
75
  }));
76
76
  await indexHtmlEmittedInWeb;
77
77
  if (hasError) return;
78
- await renderPages(routeService, config, mainCjsAbsolutePath, htmlTemplate, emitAsset, distPath);
78
+ await renderPages(routeService, config, mainCjsAbsolutePath, htmlTemplate, emitAsset, distPath, routeChunkAssets.getManifest());
79
79
  if (!isDebugMode()) await rm(ssgFolderPath, {
80
80
  recursive: true
81
81
  });
@@ -1,5 +1,5 @@
1
1
  /*! LICENSE: ssgEnv.js.LICENSE.txt */
2
- import { node_os } from "../../6010.js";
2
+ import { node_os } from "../../5871.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
@@ -1,4 +1,4 @@
1
- import { matchPath, getSidebarDataGroup } from "../../../6010.js";
1
+ import { matchPath, getSidebarDataGroup } from "../../../5871.js";
2
2
  import { generateLlmsTxt, generateLlmsFullTxt } from "./llmsTxt.js";
3
3
  async function emitLlmsTxt(config, routeService, emitAsset, mdContents) {
4
4
  const base = config.base ?? '/';
@@ -56,8 +56,8 @@ async function emitLlmsTxt(config, routeService, emitAsset, mdContents) {
56
56
  others.push(routePath);
57
57
  });
58
58
  for (const routeGroup of routeGroups)organizeBySidebar(sidebar, routeGroup);
59
- const llmsTxtContent = await generateLlmsTxt(routeGroups, others, navList, config.title, config.description, config.base, routeService);
60
- const llmsFullTxtContent = generateLlmsFullTxt(routeGroups, navList, others, base, mdContents);
59
+ const llmsTxtContent = await generateLlmsTxt(routeGroups, others, navList, config.title, config.description, base, config.siteOrigin, routeService, lang, version, 'object' == typeof config.llms ? config.llms.llmsTxt : void 0);
60
+ const llmsFullTxtContent = generateLlmsFullTxt(routeGroups, navList, others, base, config.siteOrigin, mdContents);
61
61
  const langPrefix = defaultLang === lang ? '' : `${lang}/`;
62
62
  const versionPrefix = isMultiVersion && version !== defaultVersion ? `${version}/` : '';
63
63
  const prefix = `${versionPrefix}${langPrefix}`;