@rspress/core 2.0.12 → 2.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/0~execa.js +1 -1
- package/dist/0~rslib-runtime.js +9 -5
- package/dist/{2235.js → 4942.js} +12 -9
- package/dist/{8857.js → 5580.js} +3 -3
- package/dist/6646.js +3 -0
- package/dist/{1688.js → 7261.js} +6 -1
- package/dist/{8006.js → 7986.js} +1 -6
- package/dist/cli/index.js +4 -4
- package/dist/config/loadConfigFile.js +1 -1
- package/dist/eject-theme/components/Banner/index.scss +11 -0
- package/dist/eject-theme/components/Banner/index.tsx +5 -1
- package/dist/eject-theme/components/CodeBlock/index.test.tsx +49 -0
- package/dist/eject-theme/components/CodeBlock/index.tsx +1 -1
- package/dist/eject-theme/components/CodeButtonGroup/index.tsx +5 -2
- package/dist/eject-theme/components/FallbackHeading/index.test.tsx +45 -0
- package/dist/eject-theme/components/FallbackHeading/index.tsx +1 -1
- package/dist/eject-theme/components/Link/index.tsx +6 -0
- package/dist/eject-theme/components/Link/useLinkNavigate.ts +2 -2
- package/dist/eject-theme/components/Outline/index.tsx +0 -6
- package/dist/eject-theme/components/Overview/index.test.tsx +57 -0
- package/dist/eject-theme/components/Overview/index.tsx +1 -1
- package/dist/eject-theme/components/OverviewGroup/index.test.tsx +61 -0
- package/dist/eject-theme/components/OverviewGroup/index.tsx +1 -1
- package/dist/eject-theme/components/PackageManagerTabs/index.test.tsx +54 -0
- package/dist/eject-theme/components/PackageManagerTabs/index.tsx +1 -1
- package/dist/eject-theme/components/Search/SearchPanel.tsx +1 -0
- package/dist/eject-theme/components/Search/logic/search.ts +15 -16
- package/dist/eject-theme/components/SidebarMenu/index.tsx +10 -3
- package/dist/eject-theme/components/SidebarMenu/useSidebarMenu.tsx +12 -3
- package/dist/eject-theme/components/SocialLinks/GithubStars.tsx +120 -0
- package/dist/eject-theme/components/SocialLinks/SocialLink.tsx +5 -0
- package/dist/eject-theme/components/SocialLinks/index.scss +17 -0
- package/dist/eject-theme/components/Steps/index.scss +6 -4
- package/dist/eject-theme/components/Tabs/index.test.tsx +51 -0
- package/dist/eject-theme/components/Tabs/index.tsx +1 -1
- package/dist/eject-theme/components/Tag/index.test.tsx +55 -0
- package/dist/eject-theme/components/Tag/index.tsx +19 -5
- package/dist/index.js +1 -1
- package/dist/node/PluginDriver.js +1 -1
- package/dist/node/auto-nav-sidebar/index.js +1 -1
- package/dist/node/auto-nav-sidebar/locales.js +1 -1
- package/dist/node/auto-nav-sidebar/normalize.js +3 -4
- package/dist/node/auto-nav-sidebar/utils.js +1 -1
- package/dist/node/auto-nav-sidebar/walk.js +1 -1
- package/dist/node/constants.js +3 -3
- package/dist/node/eject.js +2 -2
- package/dist/node/initRsbuild.js +20 -14
- package/dist/node/logger/hint.js +1 -1
- package/dist/node/mdx/options.js +1 -1
- package/dist/node/mdx/processor.js +1 -1
- package/dist/node/mdx/rehypePlugins/codeMeta.js +1 -1
- package/dist/node/mdx/rehypePlugins/headerAnchor.js +1 -1
- package/dist/node/mdx/rehypePlugins/shiki.js +1 -1
- package/dist/node/mdx/remarkPlugins/builtin.js +1 -1
- package/dist/node/mdx/remarkPlugins/fileCodeBlock.js +2 -2
- package/dist/node/mdx/remarkPlugins/image.js +3 -4
- package/dist/node/mdx/remarkPlugins/link.js +2 -2
- package/dist/node/mdx/remarkPlugins/toc.js +1 -1
- package/dist/node/medium-zoom/index.js +1 -1
- package/dist/node/route/RoutePage.js +1 -1
- package/dist/node/route/RouteService.js +2 -3
- package/dist/node/route/extractPageData.js +1 -1
- package/dist/node/route/normalizeRoutePath.js +1 -1
- package/dist/node/runtimeModule/DEFAULT_I18N_TEXT.d.ts +119 -112
- package/dist/node/runtimeModule/DEFAULT_I18N_TEXT.js +7 -0
- package/dist/node/runtimeModule/i18n.js +2 -2
- package/dist/node/runtimeModule/pageData/createPageData.js +1 -1
- package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +1 -1
- package/dist/node/runtimeModule/searchHooks.js +1 -1
- package/dist/node/runtimeModule/siteData/createSiteData.js +1 -1
- package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +1 -1
- package/dist/node/runtimeModule/siteData/rsbuildPlugin.js +33 -9
- package/dist/node/serve.js +1 -1
- package/dist/node/ssg/htmlFile.d.ts +2 -0
- package/dist/node/ssg/htmlFile.js +14 -0
- package/dist/node/ssg/renderPage.js +2 -2
- package/dist/node/ssg/renderPageWorker.d.ts +3 -6
- package/dist/node/ssg/renderPageWorker.js +24 -4
- package/dist/node/ssg/renderPages.d.ts +1 -1
- package/dist/node/ssg/renderPages.js +19 -18
- package/dist/node/ssg/rsbuildPluginSSG.js +2 -2
- package/dist/node/ssg/ssgEnv.js +1 -1
- package/dist/node/ssg-md/llms/emitLlmsTxt.js +1 -1
- package/dist/node/ssg-md/llms/llmsTxt.js +1 -1
- package/dist/node/ssg-md/remarkSplitMdx.js +1 -1
- package/dist/node/ssg-md/renderPage.js +2 -2
- package/dist/node/ssg-md/renderPages.js +3 -3
- package/dist/node/ssg-md/rsbuildPluginSSGMD.js +1 -1
- package/dist/node/utils/checkLanguageParity.js +1 -1
- package/dist/node/utils/createHash.js +1 -1
- package/dist/node/utils/error.js +1 -1
- package/dist/node/utils/flattenMdxContent.js +1 -1
- package/dist/node/utils/fs.js +1 -1
- package/dist/node/utils/getPageKey.js +1 -1
- package/dist/node/utils/normalizePath.js +1 -1
- package/dist/node/utils/reactAlias.js +2 -2
- package/dist/runtime/App.js +1 -1
- package/dist/theme/components/Banner/index.css +11 -0
- package/dist/theme/components/Banner/index.js +1 -0
- package/dist/theme/components/CodeBlock/index.js +1 -1
- package/dist/theme/components/CodeButtonGroup/index.js +4 -2
- package/dist/theme/components/FallbackHeading/index.js +1 -1
- package/dist/theme/components/Link/index.js +6 -0
- package/dist/theme/components/Link/useLinkNavigate.js +2 -2
- package/dist/theme/components/Outline/index.js +1 -3
- package/dist/theme/components/Overview/index.js +1 -1
- package/dist/theme/components/OverviewGroup/index.js +1 -1
- package/dist/theme/components/PackageManagerTabs/index.js +1 -1
- package/dist/theme/components/Search/SearchPanel.js +1 -0
- package/dist/theme/components/Search/logic/search.js +12 -7
- package/dist/theme/components/SidebarMenu/index.d.ts +3 -0
- package/dist/theme/components/SidebarMenu/index.js +4 -3
- package/dist/theme/components/SidebarMenu/useSidebarMenu.d.ts +2 -1
- package/dist/theme/components/SidebarMenu/useSidebarMenu.js +7 -3
- package/dist/theme/components/SocialLinks/GithubStars.d.ts +7 -0
- package/dist/theme/components/SocialLinks/GithubStars.js +85 -0
- package/dist/theme/components/SocialLinks/SocialLink.js +5 -0
- package/dist/theme/components/SocialLinks/index.css +19 -0
- package/dist/theme/components/Steps/index.css +6 -4
- package/dist/theme/components/Tabs/index.js +1 -1
- package/dist/theme/components/Tag/index.js +9 -5
- package/dist/theme/layout/DocLayout/index.js +2 -2
- package/dist/theme/layout/HomeLayout/index.js +1 -1
- package/dist/theme/layout/Layout/index.js +1 -1
- package/package.json +13 -14
- package/dist/9224.js +0 -1
- package/dist/runtime/BrowserOnly.test.d.ts +0 -1
- /package/dist/{0~1402.js → 0~8787.js} +0 -0
- /package/dist/{3323.js → 3358.js} +0 -0
- /package/dist/{8857.js.LICENSE.txt → 5580.js.LICENSE.txt} +0 -0
- /package/dist/{3294.js → 8005.js} +0 -0
- /package/dist/{6162.js → 9283.js} +0 -0
- /package/dist/{8474.js → 9882.js} +0 -0
|
@@ -213,24 +213,23 @@ export class PageSearcher {
|
|
|
213
213
|
highlightStartIndex + THRESHOLD_CONTENT_LENGTH,
|
|
214
214
|
);
|
|
215
215
|
const statement = content.slice(statementStartIndex, statementEndIndex);
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
)
|
|
225
|
-
.map(match => {
|
|
216
|
+
|
|
217
|
+
const highlightInfoList: Array<{ start: number; length: number }> = [];
|
|
218
|
+
const limitIndex = highlightStartIndex + THRESHOLD_CONTENT_LENGTH;
|
|
219
|
+
for (const match of (item as RemotePageInfo)._matchesPosition?.content ||
|
|
220
|
+
[]) {
|
|
221
|
+
const { start, length } = match;
|
|
222
|
+
|
|
223
|
+
if (start >= highlightStartIndex && start + length <= limitIndex) {
|
|
226
224
|
const startCharIndex =
|
|
227
|
-
byteToCharIndex(content,
|
|
228
|
-
|
|
229
|
-
|
|
225
|
+
byteToCharIndex(content, start) - statementStartIndex + 3; // prefix `...` length is 3
|
|
226
|
+
|
|
227
|
+
highlightInfoList.push({
|
|
230
228
|
start: startCharIndex,
|
|
231
|
-
length
|
|
232
|
-
};
|
|
233
|
-
}
|
|
229
|
+
length,
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
}
|
|
234
233
|
|
|
235
234
|
matchedResult.push({
|
|
236
235
|
type: 'content',
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
useActiveAnchor,
|
|
9
9
|
useDynamicToc,
|
|
10
10
|
} from '@rspress/core/theme';
|
|
11
|
-
import { forwardRef, useEffect, useRef } from 'react';
|
|
11
|
+
import { forwardRef, type ReactNode, useEffect, useRef } from 'react';
|
|
12
12
|
import { createPortal } from 'react-dom';
|
|
13
13
|
import './index.scss';
|
|
14
14
|
|
|
@@ -20,11 +20,15 @@ export const SidebarMenu = forwardRef(
|
|
|
20
20
|
onIsSidebarOpenChange,
|
|
21
21
|
isOutlineOpen,
|
|
22
22
|
onIsOutlineOpenChange,
|
|
23
|
+
beforeOutline,
|
|
24
|
+
afterOutline,
|
|
23
25
|
}: {
|
|
24
26
|
isSidebarOpen: boolean;
|
|
25
27
|
onIsSidebarOpenChange: (isOpen: boolean) => void;
|
|
26
28
|
isOutlineOpen: boolean;
|
|
27
29
|
onIsOutlineOpenChange: (isOpen: boolean) => void;
|
|
30
|
+
beforeOutline?: ReactNode;
|
|
31
|
+
afterOutline?: ReactNode;
|
|
28
32
|
},
|
|
29
33
|
forwardedRef,
|
|
30
34
|
) => {
|
|
@@ -36,6 +40,9 @@ export const SidebarMenu = forwardRef(
|
|
|
36
40
|
const headers = useDynamicToc();
|
|
37
41
|
const { scrolledHeader } = useActiveAnchor(headers);
|
|
38
42
|
|
|
43
|
+
const outlineDisabled =
|
|
44
|
+
!beforeOutline && !afterOutline && headers.length === 0;
|
|
45
|
+
|
|
39
46
|
const {
|
|
40
47
|
frontmatter: {
|
|
41
48
|
sidebar: sidebarConfig = true,
|
|
@@ -98,7 +105,7 @@ export const SidebarMenu = forwardRef(
|
|
|
98
105
|
{showOutline ? (
|
|
99
106
|
<button
|
|
100
107
|
type="button"
|
|
101
|
-
disabled={
|
|
108
|
+
disabled={outlineDisabled}
|
|
102
109
|
onClick={e => {
|
|
103
110
|
e.preventDefault();
|
|
104
111
|
e.stopPropagation();
|
|
@@ -118,7 +125,7 @@ export const SidebarMenu = forwardRef(
|
|
|
118
125
|
)}
|
|
119
126
|
<ReadPercent size={14} strokeWidth={2} />
|
|
120
127
|
{/* TODO: discussion */}
|
|
121
|
-
{
|
|
128
|
+
{!outlineDisabled && (
|
|
122
129
|
<SvgWrapper
|
|
123
130
|
icon={IconArrowRight}
|
|
124
131
|
className="rp-sidebar-menu__right__icon"
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { clearAllBodyScrollLocks, disableBodyScroll } from 'body-scroll-lock';
|
|
2
|
-
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { type ReactNode, useEffect, useMemo, useRef, useState } from 'react';
|
|
3
3
|
import { SidebarMenu } from '.';
|
|
4
4
|
import { useClickOutside } from './useClickOutside';
|
|
5
5
|
|
|
6
|
-
function useSidebarMenu() {
|
|
6
|
+
function useSidebarMenu(beforeOutline?: ReactNode, afterOutline?: ReactNode) {
|
|
7
7
|
const [isSidebarOpen, setIsSidebarOpen] = useState(false);
|
|
8
8
|
const [isOutlineOpen, setIsOutlineOpen] = useState(false);
|
|
9
9
|
|
|
@@ -39,9 +39,18 @@ function useSidebarMenu() {
|
|
|
39
39
|
isOutlineOpen={isOutlineOpen}
|
|
40
40
|
onIsOutlineOpenChange={setIsOutlineOpen}
|
|
41
41
|
ref={sidebarMenuRef}
|
|
42
|
+
beforeOutline={beforeOutline}
|
|
43
|
+
afterOutline={afterOutline}
|
|
42
44
|
/>
|
|
43
45
|
);
|
|
44
|
-
}, [
|
|
46
|
+
}, [
|
|
47
|
+
isOutlineOpen,
|
|
48
|
+
isSidebarOpen,
|
|
49
|
+
setIsOutlineOpen,
|
|
50
|
+
setIsSidebarOpen,
|
|
51
|
+
beforeOutline,
|
|
52
|
+
afterOutline,
|
|
53
|
+
]);
|
|
45
54
|
|
|
46
55
|
return {
|
|
47
56
|
sidebarMenu,
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { type ReactNode, useEffect, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
const TTL_MS = 60 * 60 * 1000;
|
|
4
|
+
|
|
5
|
+
type Cached = { count: number; fetchedAt: number };
|
|
6
|
+
|
|
7
|
+
function storageKey(repo: string) {
|
|
8
|
+
return `rp-github-stars:${repo}`;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function parseRepo(content: string): string | null {
|
|
12
|
+
try {
|
|
13
|
+
const url = new URL(content);
|
|
14
|
+
const host = url.hostname.replace(/^www\./, '');
|
|
15
|
+
if (host !== 'github.com') return null;
|
|
16
|
+
const match = url.pathname.match(/^\/([^/]+)\/([^/]+)/);
|
|
17
|
+
if (!match) return null;
|
|
18
|
+
return `${match[1]}/${match[2].replace(/\.git$/, '')}`;
|
|
19
|
+
} catch {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function readCache(repo: string): Cached | null {
|
|
25
|
+
if (typeof localStorage === 'undefined') return null;
|
|
26
|
+
try {
|
|
27
|
+
const raw = localStorage.getItem(storageKey(repo));
|
|
28
|
+
if (!raw) return null;
|
|
29
|
+
const parsed = JSON.parse(raw) as Cached;
|
|
30
|
+
if (
|
|
31
|
+
typeof parsed?.count !== 'number' ||
|
|
32
|
+
typeof parsed?.fetchedAt !== 'number'
|
|
33
|
+
) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
return parsed;
|
|
37
|
+
} catch {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function writeCache(repo: string, count: number) {
|
|
43
|
+
if (typeof localStorage === 'undefined') return;
|
|
44
|
+
try {
|
|
45
|
+
localStorage.setItem(
|
|
46
|
+
storageKey(repo),
|
|
47
|
+
JSON.stringify({ count, fetchedAt: Date.now() }),
|
|
48
|
+
);
|
|
49
|
+
} catch {
|
|
50
|
+
// Storage may be full or disabled (private mode); ignore.
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function formatCount(count: number): string {
|
|
55
|
+
if (count >= 1_000_000) {
|
|
56
|
+
return `${(count / 1_000_000).toFixed(1)}M`;
|
|
57
|
+
}
|
|
58
|
+
if (count >= 1000) {
|
|
59
|
+
return `${(count / 1000).toFixed(1)}K`;
|
|
60
|
+
}
|
|
61
|
+
return String(count);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
interface GithubStarsProps {
|
|
65
|
+
content: string;
|
|
66
|
+
icon: ReactNode;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export const GithubStars = (props: GithubStarsProps) => {
|
|
70
|
+
const { content, icon } = props;
|
|
71
|
+
const repo = parseRepo(content);
|
|
72
|
+
|
|
73
|
+
const [count, setCount] = useState<number | null>(() =>
|
|
74
|
+
repo ? (readCache(repo)?.count ?? null) : null,
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
if (!repo) return;
|
|
79
|
+
const cached = readCache(repo);
|
|
80
|
+
if (cached && Date.now() - cached.fetchedAt < TTL_MS) return;
|
|
81
|
+
|
|
82
|
+
let cancelled = false;
|
|
83
|
+
fetch(`https://api.github.com/repos/${repo}`)
|
|
84
|
+
.then(res => (res.ok ? res.json() : Promise.reject(res.status)))
|
|
85
|
+
.then((data: { stargazers_count: number }) => {
|
|
86
|
+
if (cancelled) return;
|
|
87
|
+
if (typeof data?.stargazers_count === 'number') {
|
|
88
|
+
setCount(data.stargazers_count);
|
|
89
|
+
writeCache(repo, data.stargazers_count);
|
|
90
|
+
}
|
|
91
|
+
})
|
|
92
|
+
.catch(() => {
|
|
93
|
+
// GitHub API failed (network, rate limit). Fall back to icon-only.
|
|
94
|
+
});
|
|
95
|
+
return () => {
|
|
96
|
+
cancelled = true;
|
|
97
|
+
};
|
|
98
|
+
}, [repo]);
|
|
99
|
+
|
|
100
|
+
return (
|
|
101
|
+
<a
|
|
102
|
+
href={content}
|
|
103
|
+
target="_blank"
|
|
104
|
+
rel="noopener noreferrer"
|
|
105
|
+
className="rp-social-links__item rp-social-links__github-stars"
|
|
106
|
+
aria-label={
|
|
107
|
+
count == null
|
|
108
|
+
? 'GitHub repository'
|
|
109
|
+
: `GitHub repository, ${count.toLocaleString()} stars`
|
|
110
|
+
}
|
|
111
|
+
>
|
|
112
|
+
<div className="rp-social-links__icon">{icon}</div>
|
|
113
|
+
{count != null && (
|
|
114
|
+
<span className="rp-social-links__github-stars-count">
|
|
115
|
+
{formatCount(count)}
|
|
116
|
+
</span>
|
|
117
|
+
)}
|
|
118
|
+
</a>
|
|
119
|
+
);
|
|
120
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { SocialLink as ISocialLink } from '@rspress/core';
|
|
2
2
|
import iconMap from 'virtual-social-links';
|
|
3
3
|
import './index.scss';
|
|
4
|
+
import { GithubStars } from './GithubStars';
|
|
4
5
|
import { useHoverGroup } from '../HoverGroup/useHoverGroup';
|
|
5
6
|
|
|
6
7
|
interface SocialLinkProps {
|
|
@@ -55,6 +56,10 @@ export const SocialLink = (props: SocialLinkProps) => {
|
|
|
55
56
|
);
|
|
56
57
|
}
|
|
57
58
|
|
|
59
|
+
if (mode === 'github-stars') {
|
|
60
|
+
return <GithubStars content={content} icon={IconComp} />;
|
|
61
|
+
}
|
|
62
|
+
|
|
58
63
|
if (mode === 'text') {
|
|
59
64
|
return (
|
|
60
65
|
<div
|
|
@@ -36,4 +36,21 @@
|
|
|
36
36
|
flex-wrap: nowrap;
|
|
37
37
|
gap: 1rem;
|
|
38
38
|
}
|
|
39
|
+
&__github-stars {
|
|
40
|
+
flex-direction: row;
|
|
41
|
+
gap: 6px;
|
|
42
|
+
text-decoration: none;
|
|
43
|
+
color: var(--rp-c-text-2);
|
|
44
|
+
transition: color 0.2s ease;
|
|
45
|
+
|
|
46
|
+
&:hover {
|
|
47
|
+
color: var(--rp-c-text-1);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
&__github-stars-count {
|
|
51
|
+
font-size: 13px;
|
|
52
|
+
font-weight: 500;
|
|
53
|
+
line-height: 1;
|
|
54
|
+
font-variant-numeric: tabular-nums;
|
|
55
|
+
}
|
|
39
56
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
:root {
|
|
2
2
|
--rp-steps-gap: 24px;
|
|
3
3
|
--rp-steps-size: 30px;
|
|
4
|
+
--rp-steps-offset-y: 4px;
|
|
4
5
|
}
|
|
5
6
|
|
|
6
7
|
.rp-steps {
|
|
@@ -14,16 +15,15 @@
|
|
|
14
15
|
counter-increment: step;
|
|
15
16
|
margin-top: 0;
|
|
16
17
|
position: relative;
|
|
17
|
-
|
|
18
|
-
align-items: center;
|
|
19
|
-
min-height: 30px;
|
|
18
|
+
min-height: var(--rp-steps-size);
|
|
20
19
|
|
|
21
20
|
&::before {
|
|
22
21
|
// position
|
|
23
22
|
content: counter(step);
|
|
24
23
|
position: absolute;
|
|
24
|
+
top: calc(var(--rp-steps-size) / 2 + var(--rp-steps-offset-y));
|
|
25
25
|
left: calc(-1 * var(--rp-steps-gap));
|
|
26
|
-
transform: translate(-50%,
|
|
26
|
+
transform: translate(-50%, -50%);
|
|
27
27
|
|
|
28
28
|
// size
|
|
29
29
|
width: var(--rp-steps-size);
|
|
@@ -48,7 +48,9 @@
|
|
|
48
48
|
/* anchor link: move to the front and ensure it's clickable */
|
|
49
49
|
.rp-header-anchor {
|
|
50
50
|
position: absolute;
|
|
51
|
+
top: calc(var(--rp-steps-size) / 2 + var(--rp-steps-offset-y));
|
|
51
52
|
left: calc(-1 * var(--rp-steps-gap) - var(--rp-steps-size) / 2);
|
|
53
|
+
transform: translate(0, -50%);
|
|
52
54
|
}
|
|
53
55
|
}
|
|
54
56
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, rs } from '@rstest/core';
|
|
2
|
+
import { renderToMarkdownString } from 'react-render-to-markdown';
|
|
3
|
+
import { Tab, Tabs } from './index';
|
|
4
|
+
|
|
5
|
+
rs.mock('@rspress/core/theme', () => ({
|
|
6
|
+
useStorageValue: () => ['0', () => {}],
|
|
7
|
+
}));
|
|
8
|
+
|
|
9
|
+
const originalSsgMd = import.meta.env.SSG_MD;
|
|
10
|
+
|
|
11
|
+
const setSsgMd = (value: boolean | undefined) => {
|
|
12
|
+
if (value === undefined) {
|
|
13
|
+
delete (import.meta.env as unknown as Record<string, unknown>).SSG_MD;
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
(import.meta.env as unknown as Record<string, unknown>).SSG_MD = value;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
afterEach(() => {
|
|
21
|
+
setSsgMd(originalSsgMd);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
describe('Tabs', () => {
|
|
25
|
+
it('renders every tab as markdown when SSG_MD is enabled', async () => {
|
|
26
|
+
setSsgMd(true);
|
|
27
|
+
|
|
28
|
+
expect(
|
|
29
|
+
await renderToMarkdownString(
|
|
30
|
+
<Tabs>
|
|
31
|
+
<Tab label="npm" value="npm">
|
|
32
|
+
npm install
|
|
33
|
+
</Tab>
|
|
34
|
+
<Tab label="pnpm" value="pnpm">
|
|
35
|
+
pnpm install
|
|
36
|
+
</Tab>
|
|
37
|
+
</Tabs>,
|
|
38
|
+
),
|
|
39
|
+
).toMatchInlineSnapshot(`
|
|
40
|
+
"
|
|
41
|
+
**npm**
|
|
42
|
+
|
|
43
|
+
npm install
|
|
44
|
+
|
|
45
|
+
**pnpm**
|
|
46
|
+
|
|
47
|
+
pnpm install
|
|
48
|
+
"
|
|
49
|
+
`);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { describe, expect, it, rs } from '@rstest/core';
|
|
2
|
+
import { renderToStaticMarkup } from 'react-dom/server';
|
|
3
|
+
import { Tag } from './index';
|
|
4
|
+
|
|
5
|
+
rs.mock('@rspress/core/runtime', () => ({
|
|
6
|
+
isDataUrl: (url: string) => url.startsWith('data:'),
|
|
7
|
+
isExternalUrl: (url: string) => /^https?:\/\//.test(url),
|
|
8
|
+
normalizeImagePath: (url: string) =>
|
|
9
|
+
url.startsWith('/') ? `/base${url}` : url,
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
rs.mock('@rspress/core/theme', () => ({
|
|
13
|
+
Badge: ({
|
|
14
|
+
children,
|
|
15
|
+
text,
|
|
16
|
+
type,
|
|
17
|
+
}: {
|
|
18
|
+
children?: React.ReactNode;
|
|
19
|
+
text?: string;
|
|
20
|
+
type?: string;
|
|
21
|
+
}) => (
|
|
22
|
+
<span data-badge-type={type} data-text={text}>
|
|
23
|
+
{children}
|
|
24
|
+
</span>
|
|
25
|
+
),
|
|
26
|
+
IconDeprecated: 'deprecated-icon',
|
|
27
|
+
IconExperimental: 'experimental-icon',
|
|
28
|
+
SvgWrapper: ({ icon }: { icon: string }) => <span data-icon={icon} />,
|
|
29
|
+
Tag: ({ tag }: { tag?: string }) => <span data-tag={tag}>{tag}</span>,
|
|
30
|
+
}));
|
|
31
|
+
|
|
32
|
+
describe('Tag', () => {
|
|
33
|
+
it('renders inline svg strings before splitting comma-separated tags', () => {
|
|
34
|
+
const markup = renderToStaticMarkup(
|
|
35
|
+
<Tag tag='<svg xmlns="http://www.w3.org/2000/svg" width="30" height="20" transform="translate(0, 0)" stroke="white"><text x="0" y="15">test</text></svg>' />,
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
expect(markup).toContain('<svg');
|
|
39
|
+
expect(markup).toContain('transform="translate(0, 0)"');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('renders public folder image paths as images', () => {
|
|
43
|
+
const markup = renderToStaticMarkup(<Tag tag="/my.svg" />);
|
|
44
|
+
|
|
45
|
+
expect(markup).toContain('<img');
|
|
46
|
+
expect(markup).toContain('src="/base/my.svg"');
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('keeps rendering multiple common tags separated by commas', () => {
|
|
50
|
+
const markup = renderToStaticMarkup(<Tag tag="new, experimental" />);
|
|
51
|
+
|
|
52
|
+
expect(markup).toContain('data-tag="new"');
|
|
53
|
+
expect(markup).toContain('data-tag="experimental"');
|
|
54
|
+
});
|
|
55
|
+
});
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
isDataUrl,
|
|
3
|
+
isExternalUrl,
|
|
4
|
+
normalizeImagePath,
|
|
5
|
+
} from '@rspress/core/runtime';
|
|
2
6
|
import {
|
|
3
7
|
Badge,
|
|
4
8
|
IconDeprecated,
|
|
@@ -15,6 +19,8 @@ const BADGE_TAGS = {
|
|
|
15
19
|
danger: 'danger',
|
|
16
20
|
} as const;
|
|
17
21
|
|
|
22
|
+
const IMAGE_EXT_REGEXP = /\.(?:avif|gif|ico|jpe?g|png|svg|webp)(?:[?#].*)?$/i;
|
|
23
|
+
|
|
18
24
|
function parseCommonTagsArrayStr(tagStr: string): string[] | null {
|
|
19
25
|
const tags = tagStr
|
|
20
26
|
.split(',')
|
|
@@ -24,12 +30,20 @@ function parseCommonTagsArrayStr(tagStr: string): string[] | null {
|
|
|
24
30
|
return tags;
|
|
25
31
|
}
|
|
26
32
|
|
|
33
|
+
function isPublicFolderPath(tag: string): boolean {
|
|
34
|
+
return tag.startsWith('/');
|
|
35
|
+
}
|
|
36
|
+
|
|
27
37
|
const getTagType = (tag: string) => {
|
|
28
38
|
const normalizedTag = tag.trim();
|
|
29
39
|
const isSvgTagString = normalizedTag.startsWith('<svg');
|
|
30
|
-
const isPic =
|
|
40
|
+
const isPic =
|
|
41
|
+
isExternalUrl(normalizedTag) ||
|
|
42
|
+
isDataUrl(normalizedTag) ||
|
|
43
|
+
(isPublicFolderPath(normalizedTag) && IMAGE_EXT_REGEXP.test(normalizedTag));
|
|
31
44
|
|
|
32
|
-
const tagsArray =
|
|
45
|
+
const tagsArray =
|
|
46
|
+
isSvgTagString || isPic ? null : parseCommonTagsArrayStr(normalizedTag);
|
|
33
47
|
|
|
34
48
|
return {
|
|
35
49
|
isSvgTagString,
|
|
@@ -67,14 +81,14 @@ export const Tag = ({ tag }: { tag?: string }) => {
|
|
|
67
81
|
return (
|
|
68
82
|
<div
|
|
69
83
|
// eslint-disable-next-line react/no-danger
|
|
70
|
-
dangerouslySetInnerHTML={{ __html:
|
|
84
|
+
dangerouslySetInnerHTML={{ __html: normalizedTag }}
|
|
71
85
|
style={{ width: 20, marginRight: 4 }}
|
|
72
86
|
></div>
|
|
73
87
|
);
|
|
74
88
|
}
|
|
75
89
|
|
|
76
90
|
if (isPic) {
|
|
77
|
-
return <img src={
|
|
91
|
+
return <img src={normalizeImagePath(normalizedTag)} />;
|
|
78
92
|
}
|
|
79
93
|
|
|
80
94
|
if (normalizedTag === 'experimental') {
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { PluginDriver } from "./node/PluginDriver.js";
|
|
2
|
-
export { RSPRESS_TEMP_DIR, getIconUrlPath, getNodeAttribute, getSidebarDataGroup, logger, matchPath, mergeDocConfig, normalizeHref, normalizePosixPath, removeTrailingSlash, withBase } from "./
|
|
2
|
+
export { RSPRESS_TEMP_DIR, getIconUrlPath, getNodeAttribute, getSidebarDataGroup, logger, matchPath, mergeDocConfig, normalizeHref, normalizePosixPath, removeTrailingSlash, withBase } from "./9882.js";
|
|
3
3
|
export { RouteService } from "./node/route/RouteService.js";
|
|
4
4
|
export { build } from "./node/build.js";
|
|
5
5
|
export { defineConfig } from "./config/defineConfig.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { addTrailingSlash, node_path, addLeadingSlash } from "../
|
|
1
|
+
import { addTrailingSlash, node_path, addLeadingSlash } from "../4942.js";
|
|
2
2
|
import { createError } from "./utils/error.js";
|
|
3
3
|
import { haveNavSidebarConfig as auto_nav_sidebar_haveNavSidebarConfig } from "./auto-nav-sidebar/index.js";
|
|
4
4
|
class PluginDriver {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DEFAULT_PAGE_EXTENSIONS, node_path } from "../../
|
|
1
|
+
import { DEFAULT_PAGE_EXTENSIONS, node_path } from "../../4942.js";
|
|
2
2
|
import { processLocales, combineWalkResult } from "./locales.js";
|
|
3
3
|
import { walk } from "./walk.js";
|
|
4
4
|
async function runAutoNavSide(config, metaFileSet, mdFileSet) {
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { __webpack_require__ } from "../../0~rslib-runtime.js";
|
|
2
|
-
import "../../
|
|
3
|
-
import { extname, logger, promises_readdir, external_node_path_relative, isExternalUrl, slash, promises_stat, join } from "../../
|
|
2
|
+
import "../../7986.js";
|
|
3
|
+
import { extname, logger, promises_readdir, external_node_path_relative, isExternalUrl, slash, promises_stat, join } from "../../4942.js";
|
|
4
4
|
import { createError } from "../utils/error.js";
|
|
5
|
-
import { PUBLIC_DIR } from "../constants.js";
|
|
6
5
|
import { pathExists, extractInfoFromFrontmatterWithAbsolutePath, readJson } from "./utils.js";
|
|
7
6
|
import { absolutePathToRoutePath, addRoutePrefix } from "../route/RoutePage.js";
|
|
8
7
|
import { RouteService } from "../route/RouteService.js";
|
|
@@ -37,7 +36,7 @@ async function fsDirToMetaItems(workDir, docsDir, extensions) {
|
|
|
37
36
|
if ('_meta.json' === item) return null;
|
|
38
37
|
const stat = await promises_stat(join(workDir, item));
|
|
39
38
|
if (stat.isDirectory()) {
|
|
40
|
-
if (
|
|
39
|
+
if ("public" === item && workDir === docsDir) return null;
|
|
41
40
|
return {
|
|
42
41
|
type: 'dir',
|
|
43
42
|
name: item
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { node_path, extractTextAndId, promises, loadFrontMatter } from "../../
|
|
1
|
+
import { node_path, extractTextAndId, promises, loadFrontMatter } from "../../4942.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 "../../
|
|
1
|
+
import { isExternalUrl, node_path, promises } from "../../4942.js";
|
|
2
2
|
import { pathExists } from "../utils/fs.js";
|
|
3
3
|
import { readJson } from "./utils.js";
|
|
4
4
|
import { addRoutePrefix } from "../route/RoutePage.js";
|
package/dist/node/constants.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createRequire, node_path, package_namespaceObject } from "../
|
|
1
|
+
import { createRequire, node_path, package_namespaceObject } from "../7261.js";
|
|
2
2
|
const constants_require = createRequire(import.meta.url);
|
|
3
3
|
const RSPRESS_VERSION = package_namespaceObject.rE;
|
|
4
4
|
const APPEARANCE_KEY = 'rspress-theme-appearance';
|
|
@@ -25,9 +25,9 @@ const APP_HTML_MARKER = '<!--<?- DOC_CONTENT ?>-->';
|
|
|
25
25
|
const HEAD_MARKER = '<!--<?- HEAD ?>-->';
|
|
26
26
|
const META_GENERATOR = '<!--<?- GENERATOR ?>-->';
|
|
27
27
|
const DEFAULT_TITLE = 'Rspress';
|
|
28
|
-
const PUBLIC_DIR = 'public';
|
|
29
28
|
const NODE_SSG_BUNDLE_FOLDER = '__ssg__';
|
|
30
29
|
const NODE_SSG_BUNDLE_NAME = 'rspress-ssg-entry.cjs';
|
|
31
30
|
const NODE_SSG_MD_BUNDLE_FOLDER = '__ssg_md__';
|
|
32
31
|
const NODE_SSG_MD_BUNDLE_NAME = 'rspress-ssg-md-entry.cjs';
|
|
33
|
-
|
|
32
|
+
var constants_PUBLIC_DIR = "public";
|
|
33
|
+
export { APP_HTML_MARKER, CSR_CLIENT_ENTRY, DEFAULT_THEME, DEFAULT_TITLE, EJECTED_THEME, HEAD_MARKER, META_GENERATOR, NODE_SSG_BUNDLE_FOLDER, NODE_SSG_BUNDLE_NAME, NODE_SSG_MD_BUNDLE_FOLDER, NODE_SSG_MD_BUNDLE_NAME, OUTPUT_DIR, PACKAGE_ROOT, RSPRESS_VERSION, SSG_MD_SERVER_ENTRY, SSR_CLIENT_ENTRY, SSR_SERVER_ENTRY, TEMPLATE_PATH, constants_PUBLIC_DIR as PUBLIC_DIR, importStatementRegex, inlineThemeScript, isProduction };
|
package/dist/node/eject.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __webpack_require__ } from "../0~rslib-runtime.js";
|
|
2
|
-
import "../
|
|
3
|
-
import { node_path, logger, promises } from "../
|
|
2
|
+
import "../7986.js";
|
|
3
|
+
import { node_path, logger, promises } from "../5580.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);
|