@rspress/core 2.0.16 → 2.0.17

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 (86) 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 → 7448.js} +1 -1
  5. package/dist/{5580.js → 8629.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/Link/index.tsx +1 -1
  10. package/dist/eject-theme/components/Link/useLinkNavigate.ts +17 -4
  11. package/dist/eject-theme/components/SocialLinks/GithubStars.test.tsx +48 -0
  12. package/dist/eject-theme/components/SocialLinks/GithubStars.tsx +35 -20
  13. package/dist/index.d.ts +2 -1
  14. package/dist/index.js +2 -1
  15. package/dist/node/PluginDriver.js +1 -1
  16. package/dist/node/auto-nav-sidebar/index.js +1 -1
  17. package/dist/node/auto-nav-sidebar/locales.js +1 -1
  18. package/dist/node/auto-nav-sidebar/normalize.js +2 -2
  19. package/dist/node/auto-nav-sidebar/utils.js +1 -1
  20. package/dist/node/auto-nav-sidebar/walk.js +1 -1
  21. package/dist/node/constants.js +1 -1
  22. package/dist/node/eject.js +2 -2
  23. package/dist/node/initRsbuild.js +5 -5
  24. package/dist/node/logger/hint.js +1 -1
  25. package/dist/node/mdx/options.js +1 -1
  26. package/dist/node/mdx/processor.js +1 -1
  27. package/dist/node/mdx/rehypePlugins/codeMeta.js +1 -1
  28. package/dist/node/mdx/rehypePlugins/headerAnchor.js +1 -1
  29. package/dist/node/mdx/rehypePlugins/shiki.js +1 -1
  30. package/dist/node/mdx/remarkPlugins/builtin.js +1 -1
  31. package/dist/node/mdx/remarkPlugins/fileCodeBlock.js +2 -2
  32. package/dist/node/mdx/remarkPlugins/image.js +2 -2
  33. package/dist/node/mdx/remarkPlugins/link.js +2 -2
  34. package/dist/node/mdx/remarkPlugins/toc.js +1 -1
  35. package/dist/node/medium-zoom/index.js +1 -1
  36. package/dist/node/route/RoutePage.js +1 -1
  37. package/dist/node/route/RouteService.js +1 -1
  38. package/dist/node/route/extractPageData.js +1 -1
  39. package/dist/node/route/normalizeRoutePath.js +1 -1
  40. package/dist/node/runtimeModule/i18n.js +3 -3
  41. package/dist/node/runtimeModule/pageData/createPageData.js +1 -1
  42. package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +1 -1
  43. package/dist/node/runtimeModule/searchHooks.js +1 -1
  44. package/dist/node/runtimeModule/siteData/createSiteData.js +6 -2
  45. package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +1 -1
  46. package/dist/node/runtimeModule/siteData/rsbuildPlugin.js +1 -1
  47. package/dist/node/serve.js +1 -1
  48. package/dist/node/ssg/htmlFile.js +1 -1
  49. package/dist/node/ssg/renderPage.js +2 -2
  50. package/dist/node/ssg/renderPageWorker.js +2 -2
  51. package/dist/node/ssg/renderPages.js +3 -3
  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 +3 -3
  55. package/dist/node/ssg-md/llms/llmsTxt.d.ts +3 -3
  56. package/dist/node/ssg-md/llms/llmsTxt.js +8 -8
  57. package/dist/node/ssg-md/remarkSplitMdx.js +1 -1
  58. package/dist/node/ssg-md/renderPage.js +2 -2
  59. package/dist/node/ssg-md/renderPages.js +3 -3
  60. package/dist/node/ssg-md/rsbuildPluginSSGMD.js +1 -1
  61. package/dist/node/utils/checkLanguageParity.js +1 -1
  62. package/dist/node/utils/createHash.js +1 -1
  63. package/dist/node/utils/error.js +1 -1
  64. package/dist/node/utils/flattenMdxContent.js +1 -1
  65. package/dist/node/utils/fs.js +1 -1
  66. package/dist/node/utils/getPageKey.js +1 -1
  67. package/dist/node/utils/normalizePath.js +1 -1
  68. package/dist/node/utils/reactAlias.js +2 -2
  69. package/dist/runtime/ClientApp.js +3 -2
  70. package/dist/runtime/route.js +2 -0
  71. package/dist/theme/components/DocContent/docComponents/index.d.ts +25 -18
  72. package/dist/theme/components/Link/index.d.ts +1 -1
  73. package/dist/theme/components/Link/useLinkNavigate.d.ts +1 -1
  74. package/dist/theme/components/Link/useLinkNavigate.js +13 -5
  75. package/dist/theme/components/Search/SearchPanel.js +8 -8
  76. package/dist/theme/components/SocialLinks/GithubStars.js +27 -17
  77. package/dist/theme/logic/getCopyableText.js +1 -0
  78. package/package.json +9 -9
  79. package/dist/6010.js +0 -2461
  80. package/dist/{0~8787.js → 0~8016.js} +0 -0
  81. package/dist/{7986.js → 4538.js} +0 -0
  82. package/dist/{3358.js → 5357.js} +0 -0
  83. package/dist/{8005.js → 7748.js} +2 -2
  84. /package/dist/{5580.js.LICENSE.txt → 8629.js.LICENSE.txt} +0 -0
  85. /package/dist/{6646.js → 9857.js} +0 -0
  86. /package/dist/{9283.js → 9940.js} +0 -0
@@ -4,7 +4,7 @@ import { IconClose, IconLoading, IconSearch, SvgWrapper, Tab, Tabs, useLinkNavig
4
4
  import { debounce } from "@rspress/shared/lodash-es";
5
5
  import { useCallback, useEffect, useRef, useState } from "react";
6
6
  import { createPortal } from "react-dom";
7
- import * as __rspack_external_virtual_search_hooks_9d01d01f from "virtual-search-hooks";
7
+ import * as __rspack_external_virtual_search_hooks_705b6e40 from "virtual-search-hooks";
8
8
  import { PageSearcher } from "./logic/search.js";
9
9
  import { RenderType } from "./logic/types.js";
10
10
  import { NoSearchResult } from "./NoSearchResult.js";
@@ -204,24 +204,24 @@ function SearchPanel({ focused, setFocused }) {
204
204
  setQuery(newQuery);
205
205
  if (newQuery) {
206
206
  const searchResult = [];
207
- if ("beforeSearch" in __rspack_external_virtual_search_hooks_9d01d01f) {
207
+ if ("beforeSearch" in __rspack_external_virtual_search_hooks_705b6e40) {
208
208
  const key = 'beforeSearch';
209
- const transformedQuery = await __rspack_external_virtual_search_hooks_9d01d01f[key](newQuery);
209
+ const transformedQuery = await __rspack_external_virtual_search_hooks_705b6e40[key](newQuery);
210
210
  if (transformedQuery) newQuery = transformedQuery;
211
211
  }
212
212
  const defaultSearchResult = await pageSearcherRef.current?.match(newQuery);
213
213
  if (defaultSearchResult) searchResult.push(...defaultSearchResult);
214
- if ("onSearch" in __rspack_external_virtual_search_hooks_9d01d01f) {
214
+ if ("onSearch" in __rspack_external_virtual_search_hooks_705b6e40) {
215
215
  const key = 'onSearch';
216
- const customSearchResult = await __rspack_external_virtual_search_hooks_9d01d01f[key](newQuery, searchResult);
216
+ const customSearchResult = await __rspack_external_virtual_search_hooks_705b6e40[key](newQuery, searchResult);
217
217
  if (customSearchResult) searchResult.push(...customSearchResult.map((item)=>({
218
218
  renderType: RenderType.Custom,
219
219
  ...item
220
220
  })));
221
221
  }
222
- if ("afterSearch" in __rspack_external_virtual_search_hooks_9d01d01f) {
222
+ if ("afterSearch" in __rspack_external_virtual_search_hooks_705b6e40) {
223
223
  const key = 'afterSearch';
224
- await __rspack_external_virtual_search_hooks_9d01d01f[key](newQuery, searchResult);
224
+ await __rspack_external_virtual_search_hooks_705b6e40[key](newQuery, searchResult);
225
225
  }
226
226
  const currQuery = searchInputRef.current?.value;
227
227
  if (currQuery === newQuery) {
@@ -256,7 +256,7 @@ function SearchPanel({ focused, setFocused }) {
256
256
  label: item.group,
257
257
  children: [
258
258
  item.renderType === RenderType.Default && renderSearchResultItem(item.result, query, isSearching),
259
- item.renderType === RenderType.Custom && __rspack_external_virtual_search_hooks_9d01d01f[renderKey](item.result)
259
+ item.renderType === RenderType.Custom && __rspack_external_virtual_search_hooks_705b6e40[renderKey](item.result)
260
260
  ]
261
261
  }, item.group))
262
262
  });
@@ -1,5 +1,6 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { useEffect, useState } from "react";
3
+ import { useStorageValue } from "../../logic/useStorageValue.js";
3
4
  const TTL_MS = 3600000;
4
5
  function storageKey(repo) {
5
6
  return `rp-github-stars:${repo}`;
@@ -16,10 +17,8 @@ function parseRepo(content) {
16
17
  return null;
17
18
  }
18
19
  }
19
- function readCache(repo) {
20
- if ("u" < typeof localStorage) return null;
20
+ function parseCache(raw) {
21
21
  try {
22
- const raw = localStorage.getItem(storageKey(repo));
23
22
  if (!raw) return null;
24
23
  const parsed = JSON.parse(raw);
25
24
  if ('number' != typeof parsed?.count || 'number' != typeof parsed?.fetchedAt) return null;
@@ -28,14 +27,11 @@ function readCache(repo) {
28
27
  return null;
29
28
  }
30
29
  }
31
- function writeCache(repo, count) {
32
- if ("u" < typeof localStorage) return;
33
- try {
34
- localStorage.setItem(storageKey(repo), JSON.stringify({
35
- count,
36
- fetchedAt: Date.now()
37
- }));
38
- } catch {}
30
+ function createCacheValue(count) {
31
+ return JSON.stringify({
32
+ count,
33
+ fetchedAt: Date.now()
34
+ });
39
35
  }
40
36
  function formatCount(count) {
41
37
  if (count >= 1000000) return `${(count / 1000000).toFixed(1)}M`;
@@ -45,24 +41,38 @@ function formatCount(count) {
45
41
  const GithubStars = (props)=>{
46
42
  const { content, icon } = props;
47
43
  const repo = parseRepo(content);
48
- const [count, setCount] = useState(()=>repo ? readCache(repo)?.count ?? null : null);
44
+ const [rawCache, setRawCache] = useStorageValue(repo ? storageKey(repo) : '', null);
45
+ const [isMounted, setIsMounted] = useState(false);
46
+ const [count, setCount] = useState(null);
47
+ useEffect(()=>{
48
+ setIsMounted(true);
49
+ }, []);
49
50
  useEffect(()=>{
50
- if (!repo) return;
51
- const cached = readCache(repo);
52
- if (cached && Date.now() - cached.fetchedAt < TTL_MS) return;
51
+ if (!repo) return void setCount(null);
52
+ if (!isMounted) return;
53
+ const cached = parseCache(rawCache);
54
+ if (cached) {
55
+ setCount(cached.count);
56
+ if (Date.now() - cached.fetchedAt < TTL_MS) return;
57
+ } else setCount(null);
53
58
  let cancelled = false;
54
59
  fetch(`https://api.github.com/repos/${repo}`).then((res)=>res.ok ? res.json() : Promise.reject(res.status)).then((data)=>{
55
60
  if (cancelled) return;
56
61
  if ('number' == typeof data?.stargazers_count) {
57
62
  setCount(data.stargazers_count);
58
- writeCache(repo, data.stargazers_count);
63
+ try {
64
+ setRawCache(createCacheValue(data.stargazers_count));
65
+ } catch {}
59
66
  }
60
67
  }).catch(()=>{});
61
68
  return ()=>{
62
69
  cancelled = true;
63
70
  };
64
71
  }, [
65
- repo
72
+ isMounted,
73
+ rawCache,
74
+ repo,
75
+ setRawCache
66
76
  ]);
67
77
  return /*#__PURE__*/ jsxs("a", {
68
78
  href: content,
@@ -32,6 +32,7 @@ function getBlockElement(element, rootElement) {
32
32
  function toMarkdown(node, state) {
33
33
  if (node.nodeType !== Node.ELEMENT_NODE) return '';
34
34
  const element = node;
35
+ if (element.closest('pre') || element.closest('code')) return '';
35
36
  const listItem = element.closest('li');
36
37
  if (listItem && !state.seenNodes.has(listItem)) {
37
38
  state.seenNodes.add(listItem);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspress/core",
3
- "version": "2.0.16",
3
+ "version": "2.0.17",
4
4
  "description": "The Rspress Documentation Framework",
5
5
  "bugs": "https://github.com/web-infra-dev/rspress/issues",
6
6
  "repository": {
@@ -60,8 +60,8 @@
60
60
  "dependencies": {
61
61
  "@mdx-js/mdx": "^3.1.1",
62
62
  "@mdx-js/react": "^3.1.1",
63
- "@rsbuild/core": "^2.0.15",
64
- "@rsbuild/plugin-react": "~2.0.1",
63
+ "@rsbuild/core": "^2.1.5",
64
+ "@rsbuild/plugin-react": "~2.1.0",
65
65
  "@shikijs/rehype": "^4.2.0",
66
66
  "@types/unist": "^3.0.3",
67
67
  "@unhead/react": "^2.1.15",
@@ -95,13 +95,13 @@
95
95
  "unist-util-remove": "^4.0.0",
96
96
  "unist-util-visit": "^5.1.0",
97
97
  "unist-util-visit-children": "^3.0.0",
98
- "@rspress/shared": "2.0.16"
98
+ "@rspress/shared": "2.0.17"
99
99
  },
100
100
  "devDependencies": {
101
101
  "@microsoft/api-extractor": "^7.58.9",
102
102
  "@rsbuild/plugin-sass": "~1.5.3",
103
- "@rsbuild/plugin-svgr": "^2.0.4",
104
- "@rslib/core": "0.23.0",
103
+ "@rsbuild/plugin-svgr": "^2.0.5",
104
+ "@rslib/core": "0.23.2",
105
105
  "@types/body-scroll-lock": "^3.1.2",
106
106
  "@types/hast": "^3.0.4",
107
107
  "@types/mdast": "^4.0.4",
@@ -110,19 +110,19 @@
110
110
  "@types/react": "^19.2.17",
111
111
  "@types/react-dom": "^19.2.3",
112
112
  "@types/react-reconciler": "^0.33.0",
113
- "@types/web": "^0.0.351",
113
+ "@types/web": "^0.0.352",
114
114
  "cac": "^7.0.0",
115
115
  "chokidar": "^3.6.0",
116
116
  "execa": "8.0.1",
117
117
  "mdast-util-directive": "^3.1.0",
118
118
  "mdast-util-mdx-expression": "^2.0.1",
119
119
  "memfs": "^4.57.8",
120
- "p-map": "^7.0.4",
120
+ "p-map": "^7.0.5",
121
121
  "picocolors": "^1.1.1",
122
122
  "postcss": "8.5.16",
123
123
  "remark-directive": "^4.0.0",
124
124
  "rsbuild-plugin-publint": "^1.0.0",
125
- "rsbuild-plugin-virtual-module": "0.4.4",
125
+ "rsbuild-plugin-virtual-module": "0.4.5",
126
126
  "tinyglobby": "^0.2.17",
127
127
  "tinypool": "^1.1.1",
128
128
  "ts-json-schema-generator": "^2.9.0",