@rspress/core 2.0.19 → 2.0.21

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 (92) hide show
  1. package/dist/{6305~0.js → 2711~0.js} +1 -1
  2. package/dist/5357~0.js +1 -1
  3. package/dist/8472~0.js +2 -2
  4. package/dist/864~0.js +1 -1
  5. package/dist/cli/index.js +1 -1
  6. package/dist/config/loadConfigFile.js +2 -3
  7. package/dist/eject-theme/components/Banner/index.tsx +50 -9
  8. package/dist/eject-theme/components/Callout/index.scss +6 -1
  9. package/dist/eject-theme/components/CodeBlock/index.scss +2 -0
  10. package/dist/eject-theme/components/DocContent/doc.scss +2 -2
  11. package/dist/eject-theme/components/Link/getHref.test.ts +33 -0
  12. package/dist/eject-theme/components/Link/getHref.ts +60 -0
  13. package/dist/eject-theme/components/Link/index.tsx +7 -6
  14. package/dist/eject-theme/components/Link/useLinkNavigate.ts +6 -51
  15. package/dist/eject-theme/components/Llms/LlmsHint.test.tsx +1 -1
  16. package/dist/eject-theme/components/Llms/LlmsHint.tsx +10 -6
  17. package/dist/eject-theme/components/Nav/NavMenu.scss +16 -4
  18. package/dist/eject-theme/components/Nav/hooks.tsx +1 -2
  19. package/dist/eject-theme/components/Nav/index.scss +3 -1
  20. package/dist/eject-theme/components/Prompt/index.scss +2 -1
  21. package/dist/eject-theme/components/Search/logic/providers/LocalProvider.ts +1 -1
  22. package/dist/eject-theme/components/SwitchAppearance/global.scss +18 -0
  23. package/dist/eject-theme/components/SwitchAppearance/index.tsx +4 -9
  24. package/dist/node/PluginDriver.js +1 -1
  25. package/dist/node/auto-nav-sidebar/index.js +1 -1
  26. package/dist/node/auto-nav-sidebar/locales.js +1 -1
  27. package/dist/node/auto-nav-sidebar/normalize.js +2 -3
  28. package/dist/node/auto-nav-sidebar/utils.js +1 -1
  29. package/dist/node/auto-nav-sidebar/walk.js +1 -1
  30. package/dist/node/constants.js +1 -1
  31. package/dist/node/eject.js +1 -1
  32. package/dist/node/initRsbuild.js +3 -3
  33. package/dist/node/last-updated/index.js +2 -2
  34. package/dist/node/mdx/options.js +2 -1
  35. package/dist/node/mdx/remarkPlugins/link.d.ts +2 -1
  36. package/dist/node/mdx/remarkPlugins/link.js +6 -5
  37. package/dist/node/route/RoutePage.d.ts +0 -1
  38. package/dist/node/route/RoutePage.js +4 -6
  39. package/dist/node/route/RouteService.js +1 -1
  40. package/dist/node/route/extractPageData.js +1 -1
  41. package/dist/node/route/normalizeRoutePath.js +2 -3
  42. package/dist/node/runtimeModule/i18n.js +1 -1
  43. package/dist/node/runtimeModule/pageData/createPageData.js +1 -1
  44. package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +1 -1
  45. package/dist/node/runtimeModule/searchHooks.js +1 -1
  46. package/dist/node/runtimeModule/siteData/createSiteData.js +1 -1
  47. package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +1 -1
  48. package/dist/node/runtimeModule/siteData/rsbuildPlugin.js +1 -1
  49. package/dist/node/serve.js +1 -1
  50. package/dist/node/ssg/alternateLinks.js +1 -1
  51. package/dist/node/ssg/renderPages.js +2 -2
  52. package/dist/node/ssg/rsbuildPluginSSG.js +1 -1
  53. package/dist/node/ssg/ssgEnv.js +1 -1
  54. package/dist/node/ssg-md/llms/emitLlmsTxt.js +1 -1
  55. package/dist/node/ssg-md/llms/llmsTxt.js +1 -1
  56. package/dist/node/ssg-md/renderPage.js +1 -1
  57. package/dist/node/ssg-md/renderPages.js +1 -1
  58. package/dist/node/ssg-md/rsbuildPluginSSGMD.js +1 -1
  59. package/dist/node/utils/checkLanguageParity.js +1 -1
  60. package/dist/node/utils/createHash.js +1 -1
  61. package/dist/node/utils/flattenMdxContent.js +2 -2
  62. package/dist/node/utils/getPageKey.js +1 -1
  63. package/dist/node/utils/reactAlias.js +1 -1
  64. package/dist/runtime/csrClientEntry.js +7 -2
  65. package/dist/runtime/route.d.ts +10 -0
  66. package/dist/runtime/route.js +13 -2
  67. package/dist/runtime/ssrClientEntry.js +2 -0
  68. package/dist/theme/components/Banner/index.js +53 -9
  69. package/dist/theme/components/Callout/index.css +6 -1
  70. package/dist/theme/components/CodeBlock/index.css +2 -0
  71. package/dist/theme/components/DocContent/doc.css +2 -2
  72. package/dist/theme/components/Link/getHref.d.ts +8 -0
  73. package/dist/theme/components/Link/getHref.js +33 -0
  74. package/dist/theme/components/Link/index.js +7 -6
  75. package/dist/theme/components/Link/useLinkNavigate.d.ts +0 -7
  76. package/dist/theme/components/Link/useLinkNavigate.js +7 -31
  77. package/dist/theme/components/Llms/LlmsHint.js +6 -2
  78. package/dist/theme/components/Nav/NavMenu.css +15 -7
  79. package/dist/theme/components/Nav/hooks.js +1 -2
  80. package/dist/theme/components/Nav/index.css +3 -1
  81. package/dist/theme/components/Prompt/index.css +2 -1
  82. package/dist/theme/components/Search/logic/providers/LocalProvider.js +1 -1
  83. package/dist/theme/components/SwitchAppearance/global.css +10 -11
  84. package/dist/theme/components/SwitchAppearance/index.js +2 -8
  85. package/dist/theme/logic/applyThemeToDOM.d.ts +2 -0
  86. package/dist/theme/logic/applyThemeToDOM.js +17 -0
  87. package/dist/theme/logic/useThemeState.d.ts +1 -2
  88. package/dist/theme/logic/useThemeState.js +1 -7
  89. package/dist/theme/logic/utils.d.ts +4 -0
  90. package/dist/theme/logic/utils.js +23 -2
  91. package/dist/theme/styles/preflight.css +0 -2
  92. package/package.json +13 -13
@@ -1,6 +1,6 @@
1
1
  import { __webpack_require__ } from "../../rslib-runtime~0.js";
2
2
  import "../../4538~0.js";
3
- import { extname, logger, promises_readdir, external_node_path_relative, isExternalUrl, slash, promises_stat, join } from "../../6305~0.js";
3
+ import { extname, logger, promises_readdir, external_node_path_relative, isExternalUrl, slash, promises_stat, join } from "../../2711~0.js";
4
4
  import { createError } from "../utils/error.js";
5
5
  import { pathExists, extractInfoFromFrontmatterWithAbsolutePath, readJson } from "./utils.js";
6
6
  import { absolutePathToRoutePath, addRoutePrefix } from "../route/RoutePage.js";
@@ -75,8 +75,7 @@ async function detectFilePath(absolutePath, extensions) {
75
75
  throw createError(`${AUTO_NAV_SIDEBAR_ERROR_PREFIX}The file extension "${ext}" is not supported, please use one of the following extensions: ${extensions.join(', ')}`);
76
76
  }
77
77
  async function metaFileItemToSidebarItem(metaItemRaw, workDir, docsDir, extensions, mdFileSet) {
78
- let metaItem = null;
79
- metaItem = 'string' == typeof metaItemRaw ? {
78
+ const metaItem = 'string' == typeof metaItemRaw ? {
80
79
  name: metaItemRaw,
81
80
  type: 'file'
82
81
  } : metaItemRaw;
@@ -1,4 +1,4 @@
1
- import { node_path, extractTextAndId, promises, loadFrontMatter } from "../../6305~0.js";
1
+ import { node_path, extractTextAndId, promises, loadFrontMatter } from "../../2711~0.js";
2
2
  import { createError } from "../utils/error.js";
3
3
  async function pathExists(path) {
4
4
  try {
@@ -1,4 +1,4 @@
1
- import { isExternalUrl, node_path, promises } from "../../6305~0.js";
1
+ import { isExternalUrl, node_path, promises } from "../../2711~0.js";
2
2
  import { pathExists } from "../utils/fs.js";
3
3
  import { readJson } from "./utils.js";
4
4
  import { addRoutePrefix } from "../route/RoutePage.js";
@@ -38,7 +38,7 @@ const getInlineLocaleRedirectScript = (config)=>{
38
38
  ].filter(Boolean).join(', ');
39
39
  const replaceLocationScript = `
40
40
  var newPathname = '/' + newPathSegments.join('/'), trailingSlash = newPathname !== '/' && ${routePathname}.endsWith('/') ? '/' : ''
41
- window.location.replace(${base ? 'base + ' : ''}newPathname + trailingSlash + search)`;
41
+ window.location['replace'](${base ? 'base + ' : ''}newPathname + trailingSlash + search)`;
42
42
  const redirectScript = 'only-default-lang' === localeRedirect ? `if (currentLang === defaultLang && langs.includes(targetLang) && targetLang !== defaultLang) {
43
43
  var newPathSegments = pathSegments.slice()
44
44
  newPathSegments.splice(${langIndex}, 0, targetLang)
@@ -1,6 +1,6 @@
1
1
  import { __webpack_require__ } from "../rslib-runtime~0.js";
2
2
  import "../4538~0.js";
3
- import { node_path, logger, promises } from "../6305~0.js";
3
+ import { node_path, logger, promises } from "../2711~0.js";
4
4
  import { EJECTED_THEME } from "./constants.js";
5
5
  const picocolors = __webpack_require__("../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js");
6
6
  var picocolors_default = /*#__PURE__*/ __webpack_require__.n(picocolors);
@@ -1,4 +1,4 @@
1
- import { external_node_process_cwd, node_path, fileURLToPath, addTrailingSlash, PLUGIN_REACT_NAME, removeTrailingSlash, normalizeDarkMode, pluginVirtualModule, pluginReact, createRequire, MDX_OR_MD_REGEXP } from "../6305~0.js";
1
+ import { external_node_process_cwd, node_path, fileURLToPath, addTrailingSlash, PLUGIN_REACT_NAME, removeTrailingSlash, normalizeDarkMode, pluginVirtualModule, pluginReact, createRequire, MDX_OR_MD_REGEXP } from "../2711~0.js";
2
2
  import { createError } from "./utils/error.js";
3
3
  import { CSR_CLIENT_ENTRY, SSR_CLIENT_ENTRY, OUTPUT_DIR, SSG_MD_SERVER_ENTRY, NODE_SSG_BUNDLE_FOLDER, getInlineLocaleRedirectScript, 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 { isLlmsUIEnabled, isLlmsHintEnabled } from "./llms.js";
@@ -197,7 +197,7 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
197
197
  ...'false' !== process.env.RSPRESS_PERSISTENT_CACHE ? {
198
198
  buildCache: {
199
199
  buildDependencies: [
200
- new URL(import.meta.url).href,
200
+ fileURLToPath(import.meta.url),
201
201
  pluginDriver.getConfigFilePath()
202
202
  ],
203
203
  cacheDigest: [
@@ -241,7 +241,7 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
241
241
  chain.module.rule('mdx').test(MDX_OR_MD_REGEXP).resolve.merge({
242
242
  conditionNames: jsModuleRule.resolve.conditionNames.values(),
243
243
  mainFields: jsModuleRule.resolve.mainFields.values()
244
- }).end().oneOf('mdx-raw').type('asset/source').resourceQuery(RAW_QUERY_REGEXP).end().oneOf('mdx').type("javascript/auto").use('builtin:swc-loader').loader('builtin:swc-loader').options(swcLoaderOptions).end().use('mdx-loader').loader(fileURLToPath(new URL('./mdx/loader.js', import.meta.url))).options({
244
+ }).end().oneOf('mdx-raw').type('asset/source').resourceQuery(RAW_QUERY_REGEXP).end().oneOf('mdx').type("javascript/auto").use('builtin:swc-loader').loader('builtin:swc-loader').options(swcLoaderOptions).end().use('mdx-loader').loader(node_path.join(node_path.dirname(fileURLToPath(import.meta.url)), 'mdx/loader.js')).options({
245
245
  config,
246
246
  docDirectory: userDocRoot,
247
247
  routeService,
@@ -53,7 +53,7 @@ async function getRepoPrefix(dir) {
53
53
  cwd: dir
54
54
  });
55
55
  return stdout.trim();
56
- } catch (_e) {
56
+ } catch {
57
57
  return;
58
58
  }
59
59
  }
@@ -79,7 +79,7 @@ async function collectGitInfo(dir) {
79
79
  ], {
80
80
  cwd: dir
81
81
  }));
82
- } catch (_e) {
82
+ } catch {
83
83
  return infoByPath;
84
84
  }
85
85
  let commit;
@@ -55,7 +55,8 @@ async function createMDXOptions(options) {
55
55
  checkAnchors: false,
56
56
  autoPrefix: true
57
57
  },
58
- __base: config?.base
58
+ __base: config?.base,
59
+ __siteOrigin: config?.siteOrigin
59
60
  } : {
60
61
  cleanUrls: false,
61
62
  root: docDirectory,
@@ -7,10 +7,11 @@ import type { RouteService } from '../../route/RouteService.js';
7
7
  * 1. add version and lang prefix to the link
8
8
  * 2. checkDeadLinks
9
9
  */
10
- export declare const remarkLink: ({ cleanUrls, routeService, remarkLinkOptions, lint, __base, }: {
10
+ export declare const remarkLink: ({ cleanUrls, routeService, remarkLinkOptions, lint, __base, __siteOrigin, }: {
11
11
  cleanUrls: boolean | string;
12
12
  routeService: RouteService | null;
13
13
  remarkLinkOptions?: MarkdownOptions['link'];
14
14
  lint?: boolean;
15
15
  __base?: string;
16
+ __siteOrigin?: string;
16
17
  }) => (tree: Root, file: VFile) => void;
@@ -1,6 +1,6 @@
1
1
  import { __webpack_require__ } from "../../../rslib-runtime~0.js";
2
2
  import "../../../4538~0.js";
3
- import { normalizeHref, node_path, addLeadingSlash, logger, visit, isExternalUrl, isProduction, parseUrl, MDX_OR_MD_REGEXP, withBase } from "../../../5357~0.js";
3
+ import { normalizeHref, node_path, addLeadingSlash, logger, visit, isExternalUrl, isProduction, parseUrl, withSiteOrigin, MDX_OR_MD_REGEXP, withBase } from "../../../5357~0.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");
@@ -99,7 +99,7 @@ function looseMarkdownLink(url, routeService, filePath) {
99
99
  }
100
100
  return url;
101
101
  }
102
- function normalizeLink(nodeUrl, routeService, filePath, cleanUrls, autoPrefix, deadLinks, __base) {
102
+ function normalizeLink(nodeUrl, routeService, filePath, cleanUrls, autoPrefix, deadLinks, __base, __siteOrigin) {
103
103
  if (!nodeUrl) return {
104
104
  url: ''
105
105
  };
@@ -148,25 +148,26 @@ function normalizeLink(nodeUrl, routeService, filePath, cleanUrls, autoPrefix, d
148
148
  if (search) url += `?${search}`;
149
149
  if (hash) url += `#${hash}`;
150
150
  if (__base) url = withBase(url, __base);
151
+ if (__siteOrigin) url = withSiteOrigin(url, __siteOrigin);
151
152
  return {
152
153
  url,
153
154
  routePath,
154
155
  hash
155
156
  };
156
157
  }
157
- const remarkLink = ({ cleanUrls, routeService, remarkLinkOptions, lint, __base })=>(tree, file)=>{
158
+ const remarkLink = ({ cleanUrls, routeService, remarkLinkOptions, lint, __base, __siteOrigin })=>(tree, file)=>{
158
159
  const { checkAnchors: shouldCheckAnchors = false, checkDeadLinks: shouldCheckDeadLinks = true, autoPrefix = true } = remarkLinkOptions ?? {};
159
160
  const deadLinks = new Map();
160
161
  const anchorLinks = new Map();
161
162
  visit(tree, 'link', (node)=>{
162
163
  const { url: nodeUrl } = node;
163
- const link = normalizeLink(nodeUrl, routeService, file.path, cleanUrls, autoPrefix, deadLinks, __base);
164
+ const link = normalizeLink(nodeUrl, routeService, file.path, cleanUrls, autoPrefix, deadLinks, __base, __siteOrigin);
164
165
  if (link.hash) anchorLinks.set(nodeUrl, link);
165
166
  node.url = link.url;
166
167
  });
167
168
  visit(tree, 'definition', (node)=>{
168
169
  const { url: nodeUrl } = node;
169
- const link = normalizeLink(nodeUrl, routeService, file.path, cleanUrls, autoPrefix, deadLinks, __base);
170
+ const link = normalizeLink(nodeUrl, routeService, file.path, cleanUrls, autoPrefix, deadLinks, __base, __siteOrigin);
170
171
  if (link.hash) anchorLinks.set(nodeUrl, link);
171
172
  node.url = link.url;
172
173
  });
@@ -1,7 +1,6 @@
1
1
  import type { PageIndexInfo, RouteMeta } from '@rspress/shared';
2
2
  import { RouteService } from './RouteService.js';
3
3
  export declare class RoutePage {
4
- #private;
5
4
  routeMeta: RouteMeta;
6
5
  pageIndexInfo?: PageIndexInfo;
7
6
  setPageIndexInfo(info: PageIndexInfo): void;
@@ -1,25 +1,23 @@
1
- import { node_path } from "../../6305~0.js";
1
+ import { node_path } from "../../2711~0.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";
5
5
  class RoutePage {
6
6
  routeMeta;
7
- #docDir;
8
7
  pageIndexInfo;
9
8
  setPageIndexInfo(info) {
10
9
  this.pageIndexInfo = info;
11
10
  }
12
11
  static create(absolutePath, docsDir) {
13
12
  const routeMeta = absolutePathToRouteMeta(absolutePath, docsDir, RouteService.getInstance());
14
- return new RoutePage(routeMeta, docsDir);
13
+ return new RoutePage(routeMeta);
15
14
  }
16
15
  static createFromExternal(routePath, filepath, docDir) {
17
16
  const routeMeta = RoutePage.generateRouteMeta(routePath, filepath, docDir);
18
- return new RoutePage(routeMeta, node_path.dirname(filepath));
17
+ return new RoutePage(routeMeta);
19
18
  }
20
- constructor(routeMeta, docDir){
19
+ constructor(routeMeta){
21
20
  this.routeMeta = routeMeta;
22
- this.#docDir = docDir;
23
21
  }
24
22
  static generateRouteMeta(routePath, filepath, docDir) {
25
23
  const routeService = RouteService.getInstance();
@@ -1,4 +1,4 @@
1
- import { RSPRESS_TEMP_DIR, node_path, removeTrailingSlash, promises, addTrailingSlash, DEFAULT_PAGE_EXTENSIONS, glob } from "../../6305~0.js";
1
+ import { RSPRESS_TEMP_DIR, node_path, removeTrailingSlash, promises, addTrailingSlash, DEFAULT_PAGE_EXTENSIONS, glob } from "../../2711~0.js";
2
2
  import { RoutePage, absolutePathToRoutePath, absolutePathToRelativePath } from "./RoutePage.js";
3
3
  import { createError } from "../utils/error.js";
4
4
  import { getRouteChunkName } from "./routeChunkAssets.js";
@@ -1,4 +1,4 @@
1
- import { unified, node_path, promises, loadFrontMatter, remark_gfm, MDX_OR_MD_REGEXP, remark_parse } from "../../6305~0.js";
1
+ import { unified, node_path, promises, loadFrontMatter, remark_gfm, MDX_OR_MD_REGEXP, remark_parse } from "../../2711~0.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 "../../6305~0.js";
1
+ import { addTrailingSlash, DEFAULT_PAGE_EXTENSIONS, addLeadingSlash } from "../../2711~0.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 [
@@ -11,7 +11,6 @@ const splitRoutePathParts = (relativePath, lang, version, langs, versions)=>{
11
11
  const hasTrailSlash = relativePath.endsWith('/');
12
12
  let versionPart = '';
13
13
  let langPart = '';
14
- let purePathPart = '';
15
14
  const parts = relativePath.split('/').filter(Boolean);
16
15
  if (version) {
17
16
  const versionToMatch = parts[0];
@@ -21,7 +20,7 @@ const splitRoutePathParts = (relativePath, lang, version, langs, versions)=>{
21
20
  const langToMatch = parts[0];
22
21
  if (langs.includes(langToMatch)) langPart = parts.shift() ?? '';
23
22
  }
24
- purePathPart = parts.join('/');
23
+ const purePathPart = parts.join('/');
25
24
  return [
26
25
  versionPart,
27
26
  langPart,
@@ -1,6 +1,6 @@
1
1
  import { __webpack_require__ } from "../../rslib-runtime~0.js";
2
2
  import "../../4538~0.js";
3
- import { createRequire, join, logger } from "../../6305~0.js";
3
+ import { createRequire, join, logger } from "../../2711~0.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 "../../../6305~0.js";
1
+ import { SEARCH_INDEX_NAME, groupBy } from "../../../2711~0.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 "../../../6305~0.js";
1
+ import { logger, pluginVirtualModule } from "../../../2711~0.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 "../../6305~0.js";
1
+ import { node_path } from "../../2711~0.js";
2
2
  const searchHookVMPlugin = (context)=>({
3
3
  ["virtual-search-hooks"]: ()=>{
4
4
  const { config } = context;
@@ -1,4 +1,4 @@
1
- import { getIconUrlPath } from "../../../6305~0.js";
1
+ import { getIconUrlPath } from "../../../2711~0.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 "../../../6305~0.js";
1
+ import { isExternalUrl, slash, addLeadingSlash, normalizeHref } from "../../../2711~0.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 "../../../6305~0.js";
1
+ import { isProduction, logger } from "../../../2711~0.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 "../6305~0.js";
1
+ import { mergeRsbuildConfig } from "../2711~0.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 { normalizeHref, removeTrailingSlash, addLeadingSlash, normalizePosixPath, withSiteOrigin } from "../../6305~0.js";
1
+ import { normalizeHref, removeTrailingSlash, addLeadingSlash, normalizePosixPath, withSiteOrigin } from "../../2711~0.js";
2
2
  function createAlternateLinksByRoute(routes, config) {
3
3
  const routeGroups = new Map();
4
4
  for (const route of routes){
@@ -1,7 +1,7 @@
1
1
  /*! LICENSE: renderPages.js.LICENSE.txt */
2
2
  import { __webpack_require__ } from "../../rslib-runtime~0.js";
3
3
  import "../../4538~0.js";
4
- import { chunk, logger } from "../../6305~0.js";
4
+ import { node_path, fileURLToPath, logger, chunk } from "../../2711~0.js";
5
5
  import { createAlternateLinksByRoute } from "./alternateLinks.js";
6
6
  import { SSGWorkerThreadTaskSize, getNumberOfThreads, SSGWorkerThreadRecyclerMaxMemory, SSGConcurrency } from "./ssgEnv.js";
7
7
  import { routePath2HtmlFileName } from "./htmlFile.js";
@@ -48,7 +48,7 @@ async function renderPages(routeService, config, ssrBundlePath, htmlTemplate, em
48
48
  logger.info(`Rendering pages with experimental SSG worker (${picocolors_default().yellow(numberOfThreads)} threads)...`);
49
49
  const Tinypool = await import("../../tinypool~0.js").then((m)=>m.default);
50
50
  const pool = new Tinypool({
51
- filename: new URL('./renderPageWorker.js', import.meta.url).href,
51
+ filename: node_path.join(node_path.dirname(fileURLToPath(import.meta.url)), 'renderPageWorker.js'),
52
52
  concurrentTasksPerWorker: 1,
53
53
  minThreads: numberOfThreads,
54
54
  maxThreads: numberOfThreads,
@@ -1,4 +1,4 @@
1
- import { logger, writeFile, mkdir, rm, join, isDebugMode } from "../../6305~0.js";
1
+ import { logger, writeFile, mkdir, rm, join, isDebugMode } from "../../2711~0.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, routeChunkAssets })=>({
@@ -1,5 +1,5 @@
1
1
  /*! LICENSE: ssgEnv.js.LICENSE.txt */
2
- import { node_os } from "../../6305~0.js";
2
+ import { node_os } from "../../2711~0.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 "../../../6305~0.js";
1
+ import { matchPath, getSidebarDataGroup } from "../../../2711~0.js";
2
2
  import { generateLlmsTxt, generateLlmsFullTxt } from "./llmsTxt.js";
3
3
  async function emitLlmsTxt(config, routeService, emitAsset, mdContents) {
4
4
  const base = config.base ?? '/';
@@ -1,4 +1,4 @@
1
- import { normalizeHref, withSiteOrigin, logger, withBase } from "../../../6305~0.js";
1
+ import { normalizeHref, withSiteOrigin, logger, withBase } from "../../../2711~0.js";
2
2
  import { extractInfoFromFrontmatterWithAbsolutePath } from "../../auto-nav-sidebar/utils.js";
3
3
  function routePathToMdPath(routePath, base, siteOrigin) {
4
4
  let url = routePath;
@@ -1,6 +1,6 @@
1
1
  import { __webpack_require__ } from "../../rslib-runtime~0.js";
2
2
  import "../../4538~0.js";
3
- import { createHead, pathToFileURL, logger } from "../../6305~0.js";
3
+ import { createHead, pathToFileURL, logger } from "../../2711~0.js";
4
4
  import { hintSSGFailed } from "../logger/hint.js";
5
5
  const picocolors = __webpack_require__("../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js");
6
6
  var picocolors_default = /*#__PURE__*/ __webpack_require__.n(picocolors);
@@ -1,6 +1,6 @@
1
1
  import { __webpack_require__ } from "../../rslib-runtime~0.js";
2
2
  import "../../4538~0.js";
3
- import { logger } from "../../6305~0.js";
3
+ import { logger } from "../../2711~0.js";
4
4
  import { pMap } from "../../8472~0.js";
5
5
  import { renderPage } from "./renderPage.js";
6
6
  import { SSGConcurrency } from "../ssg/ssgEnv.js";
@@ -1,4 +1,4 @@
1
- import { writeFile, mkdir, rm, join, isDebugMode } from "../../6305~0.js";
1
+ import { writeFile, mkdir, rm, join, isDebugMode } from "../../2711~0.js";
2
2
  import { NODE_SSG_MD_BUNDLE_FOLDER, NODE_SSG_MD_BUNDLE_NAME } from "../constants.js";
3
3
  import { renderPages } from "./renderPages.js";
4
4
  import { emitLlmsTxt } from "./llms/emitLlmsTxt.js";
@@ -1,4 +1,4 @@
1
- import { node_path, logger, promises } from "../../6305~0.js";
1
+ import { node_path, logger, promises } from "../../2711~0.js";
2
2
  import { createError } from "./error.js";
3
3
  function normalizePath(filePath) {
4
4
  return filePath.split(node_path.sep).join('/');
@@ -1,4 +1,4 @@
1
- import { createHash as external_node_crypto_createHash } from "../../6305~0.js";
1
+ import { createHash as external_node_crypto_createHash } from "../../2711~0.js";
2
2
  function createHash(str, length = 8) {
3
3
  return external_node_crypto_createHash('sha256').update(str).digest('hex').slice(0, length);
4
4
  }
@@ -1,4 +1,4 @@
1
- import { node_fs, node_path, core_rspack, logger, createProcessor, MDX_OR_MD_REGEXP } from "../../6305~0.js";
1
+ import { node_fs, node_path, core_rspack, logger, createProcessor, MDX_OR_MD_REGEXP } from "../../2711~0.js";
2
2
  import { createError } from "./error.js";
3
3
  import { importStatementRegex } from "../constants.js";
4
4
  const RspackResolveFactory = core_rspack.experiments.resolver.ResolverFactory;
@@ -53,7 +53,7 @@ async function flattenMdxContent(content, basePath, alias) {
53
53
  let absoluteImportPath;
54
54
  try {
55
55
  absoluteImportPath = await resolveDepPath(importPath, node_path.dirname(basePath), alias);
56
- } catch (_e) {
56
+ } catch {
57
57
  continue;
58
58
  }
59
59
  if (MDX_OR_MD_REGEXP.test(absoluteImportPath)) {
@@ -1,4 +1,4 @@
1
- import { removeLeadingSlash } from "../../6305~0.js";
1
+ import { removeLeadingSlash } from "../../2711~0.js";
2
2
  function getPageKey(route) {
3
3
  const cleanRoute = removeLeadingSlash(route);
4
4
  return cleanRoute.replace(/\//g, '_').replace(/\.[^.]+$/, '') || 'index';
@@ -1,6 +1,6 @@
1
1
  import { __webpack_require__ } from "../../rslib-runtime~0.js";
2
2
  import "../../4538~0.js";
3
- import { node_path, core_rspack, logger } from "../../6305~0.js";
3
+ import { node_path, core_rspack, logger } from "../../2711~0.js";
4
4
  import { pathExists, readJson } from "./fs.js";
5
5
  import { PACKAGE_ROOT } from "../constants.js";
6
6
  import { hintReactVersion } from "../logger/hint.js";
@@ -1,5 +1,10 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import { createRoot } from "react-dom/client";
3
3
  import { ClientApp } from "./ClientApp.js";
4
- const container = document.getElementById('__rspress_root');
5
- createRoot(container).render(/*#__PURE__*/ jsx(ClientApp, {}));
4
+ import { redirectToCleanUrl } from "./route.js";
5
+ function renderInBrowser() {
6
+ redirectToCleanUrl(window.location, window.history);
7
+ const container = document.getElementById('__rspress_root');
8
+ createRoot(container).render(/*#__PURE__*/ jsx(ClientApp, {}));
9
+ }
10
+ renderInBrowser();
@@ -20,6 +20,16 @@ export declare function matchPath(pattern: string, pathname: string): {
20
20
  * @returns
21
21
  */
22
22
  export declare function pathnameToRouteService(pathname: string): Route | undefined;
23
+ /**
24
+ * Redirects a pathname to the matching route's canonical URL with the History
25
+ * API.
26
+ *
27
+ * The URL format follows the `cleanUrls` setting. Query strings, hashes, and
28
+ * history state are preserved.
29
+ *
30
+ * @returns Whether the URL was updated.
31
+ */
32
+ export declare function redirectToCleanUrl(location: Pick<Location, 'hash' | 'pathname' | 'search'>, history: Pick<History, 'replaceState' | 'state'>): boolean;
23
33
  /**
24
34
  * link: /api/config
25
35
  * currentPathname:
@@ -1,6 +1,7 @@
1
- import { cleanUrl } from "@rspress/shared";
1
+ import { cleanUrl, normalizeHref } from "@rspress/shared";
2
2
  import { routes } from "virtual-routes";
3
3
  import virtual_site_data from "virtual-site-data";
4
+ import { removeBase, removeTrailingSlash } from "./utils.js";
4
5
  function normalizeRoutePath(routePath) {
5
6
  return cleanUrl(decodeURIComponent(routePath)).replace(/\.html$/, '').replace(/\/index$/, '/').toLowerCase();
6
7
  }
@@ -43,6 +44,16 @@ function pathnameToRouteService(pathname) {
43
44
  if (route) cache.set(normalizedPathname, route);
44
45
  return route;
45
46
  }
47
+ function redirectToCleanUrl(location, history) {
48
+ if (virtual_site_data.route?.cleanUrlsRedirect === false) return false;
49
+ const matchedRoute = pathnameToRouteService(removeBase(location.pathname));
50
+ if (!matchedRoute) return false;
51
+ const canonicalRoutePath = normalizeHref(matchedRoute.path, Boolean(virtual_site_data.route?.cleanUrls));
52
+ const canonicalPathname = `${removeTrailingSlash(virtual_site_data.base)}${canonicalRoutePath}`;
53
+ if (location.pathname === canonicalPathname) return false;
54
+ history.replaceState(history.state, '', `${canonicalPathname}${location.search}${location.hash}`);
55
+ return true;
56
+ }
46
57
  function isActive(itemLink, currentPathname) {
47
58
  const linkMatched = matchPath(itemLink, currentPathname);
48
59
  return null !== linkMatched;
@@ -52,4 +63,4 @@ const preloadLink = (link)=>{
52
63
  const route = pathnameToRouteService(link);
53
64
  if (route) route.preload();
54
65
  };
55
- export { isActive, matchPath, pathnameToRouteService, preloadLink };
66
+ export { isActive, matchPath, pathnameToRouteService, preloadLink, redirectToCleanUrl };
@@ -4,7 +4,9 @@ import { startTransition } from "react";
4
4
  import { hydrateRoot } from "react-dom/client";
5
5
  import { ClientApp } from "./ClientApp.js";
6
6
  import { initPageData, setCurrentPageData } from "./initPageData.js";
7
+ import { redirectToCleanUrl } from "./route.js";
7
8
  async function renderInBrowser() {
9
+ redirectToCleanUrl(window.location, window.history);
8
10
  const container = document.getElementById('__rspress_root');
9
11
  const pathname = removeBase(window.location.pathname);
10
12
  const initialPageData = await initPageData(pathname);
@@ -1,24 +1,66 @@
1
1
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
2
  import { IconClose, Link, SvgWrapper, mergeRefs } from "@rspress/core/theme";
3
3
  import clsx from "clsx";
4
- import { forwardRef, useEffect, useState } from "react";
4
+ import { forwardRef, useEffect, useId, useState } from "react";
5
5
  import "./index.css";
6
+ const inlineStorageScript = `(function () {
7
+ var script = document.currentScript;
8
+ if (!script) return;
9
+ try {
10
+ var storage = window[script.dataset.rpBannerStorage];
11
+ var storageKey = script.dataset.rpBannerStorageKey;
12
+ var hiddenClass = script.dataset.rpBannerHiddenClass;
13
+ if (storage && storageKey && hiddenClass && storage.getItem(storageKey)) {
14
+ document.documentElement.classList.add(hiddenClass);
15
+ }
16
+ } catch (e) {}
17
+ })();`;
6
18
  const Banner = /*#__PURE__*/ forwardRef((props, forwardedRef)=>{
7
19
  const { href, message, display = true, className, storageKey = 'rp-banner-closed', storage = 'localStorage', customChildren } = props;
20
+ const isCustom = 'customChildren' in props;
8
21
  const [height, setHeight] = useState(36);
9
22
  const ref = mergeRefs(forwardedRef, (element)=>{
10
23
  if (element?.offsetHeight) setHeight(element?.offsetHeight);
11
24
  });
12
25
  const [disable, setDisable] = useState(false);
26
+ const bannerId = useId().replace(/[^a-zA-Z0-9_-]/g, '');
27
+ const bannerClass = `rp-banner-${bannerId}`;
28
+ const hiddenClass = `${bannerClass}-hidden`;
13
29
  useEffect(()=>{
14
- if ("u" < typeof window || !storage || !storageKey) return;
15
- setDisable(Boolean(window[storage].getItem(storageKey)));
16
- }, []);
30
+ let isDisabled = false;
31
+ if (!isCustom && "u" > typeof window && storage && storageKey) try {
32
+ isDisabled = Boolean(window[storage].getItem(storageKey));
33
+ } catch {
34
+ isDisabled = false;
35
+ }
36
+ document.documentElement.classList.toggle(hiddenClass, isDisabled);
37
+ setDisable(isDisabled);
38
+ return ()=>{
39
+ document.documentElement.classList.remove(hiddenClass);
40
+ };
41
+ }, [
42
+ hiddenClass,
43
+ isCustom,
44
+ storage,
45
+ storageKey
46
+ ]);
17
47
  if (!display || disable) return null;
18
48
  return /*#__PURE__*/ jsxs(Fragment, {
19
49
  children: [
50
+ !isCustom && storage && storageKey ? /*#__PURE__*/ jsx("script", {
51
+ "data-rp-banner-hidden-class": hiddenClass,
52
+ "data-rp-banner-storage": storage,
53
+ "data-rp-banner-storage-key": storageKey,
54
+ suppressHydrationWarning: true,
55
+ dangerouslySetInnerHTML: {
56
+ __html: inlineStorageScript
57
+ }
58
+ }) : null,
59
+ /*#__PURE__*/ jsx("style", {
60
+ children: `:root {--rp-banner-height: ${height}px;} :root.${hiddenClass} {--rp-banner-height: 0px;} :root.${hiddenClass} .${bannerClass} {display: none;}`
61
+ }),
20
62
  /*#__PURE__*/ jsx("div", {
21
- className: clsx('rp-banner', className),
63
+ className: clsx('rp-banner', bannerClass, className),
22
64
  ref: ref,
23
65
  children: customChildren ?? /*#__PURE__*/ jsxs(Fragment, {
24
66
  children: [
@@ -31,16 +73,18 @@ const Banner = /*#__PURE__*/ forwardRef((props, forwardedRef)=>{
31
73
  /*#__PURE__*/ jsx(SvgWrapper, {
32
74
  icon: IconClose,
33
75
  onClick: ()=>{
76
+ document.documentElement.classList.add(hiddenClass);
34
77
  setDisable(true);
35
- if (storage) window[storage].setItem(storageKey, 'true');
78
+ if (storage) try {
79
+ window[storage].setItem(storageKey, 'true');
80
+ } catch {
81
+ return;
82
+ }
36
83
  },
37
84
  className: "rp-banner__close"
38
85
  })
39
86
  ]
40
87
  })
41
- }),
42
- /*#__PURE__*/ jsx("style", {
43
- children: `:root {--rp-banner-height: ${height}px;}`
44
88
  })
45
89
  ]
46
90
  });
@@ -90,7 +90,12 @@
90
90
  }
91
91
 
92
92
  .rp-callout__content a {
93
- border-bottom: 1px solid;
93
+ text-underline-offset: 4px;
94
+ text-decoration: underline;
95
+ }
96
+
97
+ .rp-callout__content a:hover {
98
+ opacity: .85;
94
99
  }
95
100
 
96
101
  .rp-callout--note {