@rspress/core 2.0.11 → 2.0.13
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/{8857.js → 5580.js} +2 -2
- package/dist/{1688.js → 7275.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/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/useLinkNavigate.ts +2 -2
- 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 +17 -18
- package/dist/eject-theme/components/Search/SearchPanel.tsx +1 -6
- package/dist/eject-theme/components/Sidebar/SidebarItem.tsx +1 -1
- 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 +49 -42
- 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.d.ts +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 +5 -8
- 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/rehypePlugins/transformers/add-title.js +3 -6
- package/dist/node/mdx/remarkPlugins/builtin.js +1 -1
- package/dist/node/mdx/remarkPlugins/containerSyntax.d.ts +1 -1
- package/dist/node/mdx/remarkPlugins/fileCodeBlock.js +2 -2
- package/dist/node/mdx/remarkPlugins/image.d.ts +1 -1
- package/dist/node/mdx/remarkPlugins/image.js +4 -4
- package/dist/node/mdx/remarkPlugins/link.d.ts +1 -1
- 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 +147 -140
- 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.d.ts +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 +1 -1
- package/dist/node/serve.js +1 -1
- package/dist/node/ssg/renderPage.js +2 -2
- package/dist/node/ssg/renderPageWorker.js +2 -2
- package/dist/node/ssg/renderPages.js +3 -3
- package/dist/node/ssg/rsbuildPluginSSG.js +1 -1
- 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/CodeBlock/index.js +1 -1
- package/dist/theme/components/CodeButtonGroup/index.js +4 -2
- package/dist/theme/components/DocContent/docComponents/a.d.ts +1 -1
- package/dist/theme/components/DocContent/docComponents/hr.d.ts +1 -1
- package/dist/theme/components/DocContent/docComponents/img.d.ts +1 -1
- package/dist/theme/components/DocContent/docComponents/index.d.ts +18 -18
- package/dist/theme/components/DocContent/docComponents/list.d.ts +3 -3
- package/dist/theme/components/DocContent/docComponents/paragraph.d.ts +3 -3
- package/dist/theme/components/DocContent/docComponents/table.d.ts +3 -3
- package/dist/theme/components/DocContent/docComponents/title.d.ts +6 -6
- package/dist/theme/components/FallbackHeading/index.js +1 -1
- package/dist/theme/components/Link/useLinkNavigate.js +2 -2
- package/dist/theme/components/Nav/hooks.d.ts +1 -1
- 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 +18 -18
- package/dist/theme/components/Search/SearchPanel.js +1 -2
- package/dist/theme/components/Sidebar/SidebarItem.js +1 -0
- package/dist/theme/components/Steps/index.css +6 -4
- package/dist/theme/components/Tabs/index.d.ts +8 -4
- package/dist/theme/components/Tabs/index.js +20 -20
- package/dist/theme/layout/DocLayout/index.js +1 -1
- package/dist/theme/layout/HomeLayout/index.js +1 -1
- package/dist/theme/layout/Layout/index.js +1 -1
- package/package.json +9 -9
- package/dist/runtime/BrowserOnly.test.d.ts +0 -1
- /package/dist/{0~1402.js → 0~8787.js} +0 -0
- /package/dist/{5810.js → 2633.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/{9224.js → 559.js} +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
package/dist/0~execa.js
CHANGED
|
@@ -8,7 +8,7 @@ import { createReadStream, createWriteStream, readFileSync } from "node:fs";
|
|
|
8
8
|
import { setTimeout as promises_setTimeout } from "node:timers/promises";
|
|
9
9
|
import { debuglog } from "node:util";
|
|
10
10
|
import { __webpack_require__ } from "./0~rslib-runtime.js";
|
|
11
|
-
import "./
|
|
11
|
+
import "./2633.js";
|
|
12
12
|
__webpack_require__.add({
|
|
13
13
|
"../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/index.js" (module, __unused_rspack_exports, __webpack_require__) {
|
|
14
14
|
const cp = __webpack_require__("child_process");
|
package/dist/{8857.js → 5580.js}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
/*! LICENSE:
|
|
1
|
+
/*! LICENSE: 5580.js.LICENSE.txt */
|
|
2
2
|
import { __webpack_require__ } from "./0~rslib-runtime.js";
|
|
3
|
-
import "./
|
|
3
|
+
import "./2633.js";
|
|
4
4
|
import { createRequire as __rspack_createRequire } from "node:module";
|
|
5
5
|
const __rspack_createRequire_require = __rspack_createRequire(import.meta.url);
|
|
6
6
|
__webpack_require__.add({
|
package/dist/{1688.js → 7275.js}
RENAMED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
var package_namespaceObject = {
|
|
2
|
+
rE: "2.0.13"
|
|
3
|
+
};
|
|
1
4
|
async function pMap(iterable, mapper, { concurrency = 1 / 0, stopOnError = true, signal } = {}) {
|
|
2
5
|
return new Promise((resolve_, reject_)=>{
|
|
3
6
|
if (void 0 === iterable[Symbol.iterator] && void 0 === iterable[Symbol.asyncIterator]) throw new TypeError(`Expected \`input\` to be either an \`Iterable\` or \`AsyncIterable\`, got (${typeof iterable})`);
|
|
@@ -89,7 +92,9 @@ async function pMap(iterable, mapper, { concurrency = 1 / 0, stopOnError = true,
|
|
|
89
92
|
});
|
|
90
93
|
}
|
|
91
94
|
const pMapSkip = Symbol('skip');
|
|
95
|
+
export { createRequire } from "node:module";
|
|
96
|
+
export { default as node_path } from "node:path";
|
|
92
97
|
export { pathToFileURL } from "node:url";
|
|
93
98
|
export { logger } from "@rspress/shared/logger";
|
|
94
99
|
export { createHead, transformHtmlTemplate } from "@unhead/react/server";
|
|
95
|
-
export { pMap };
|
|
100
|
+
export { pMap, package_namespaceObject };
|
package/dist/{8006.js → 7986.js}
RENAMED
|
@@ -67,11 +67,6 @@ __webpack_require__.add({
|
|
|
67
67
|
module.exports.createColors = createColors;
|
|
68
68
|
}
|
|
69
69
|
});
|
|
70
|
-
var package_namespaceObject = {
|
|
71
|
-
rE: "2.0.11"
|
|
72
|
-
};
|
|
73
70
|
export { default as promises, readFile } from "node:fs/promises";
|
|
74
|
-
export {
|
|
71
|
+
export { join, relative } from "node:path";
|
|
75
72
|
export { logger } from "@rspress/shared/logger";
|
|
76
|
-
export { createRequire } from "node:module";
|
|
77
|
-
export { package_namespaceObject };
|
package/dist/cli/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { __webpack_require__ } from "../0~rslib-runtime.js";
|
|
2
|
-
import { node_path, logger, join, cac } from "../
|
|
3
|
-
import
|
|
2
|
+
import { node_path, logger, join, cac } from "../5580.js";
|
|
3
|
+
import "../7986.js";
|
|
4
|
+
import { package_namespaceObject } from "../7275.js";
|
|
4
5
|
import { loadConfigFile, resolveDocRoot } from "../config/loadConfigFile.js";
|
|
5
6
|
import { dev } from "../node/dev.js";
|
|
6
|
-
import { PUBLIC_DIR } from "../node/constants.js";
|
|
7
7
|
import { build } from "../node/build.js";
|
|
8
8
|
import { serve } from "../node/serve.js";
|
|
9
9
|
import { listComponents, ejectComponent } from "../node/eject.js";
|
|
@@ -54,7 +54,7 @@ cli.command('[root]', 'start dev server').alias('dev').option('--port [port]', '
|
|
|
54
54
|
'**/node_modules/**',
|
|
55
55
|
'**/.git/**',
|
|
56
56
|
'**/.DS_Store/**',
|
|
57
|
-
join(docDirectory,
|
|
57
|
+
join(docDirectory, "public")
|
|
58
58
|
]
|
|
59
59
|
});
|
|
60
60
|
cliWatcher.on('all', async (eventName, filepath)=>{
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { node_fs, node_path, logger, DEFAULT_CONFIG_NAME, DEFAULT_CONFIG_EXTENSIONS } from "../
|
|
1
|
+
import { node_fs, node_path, logger, DEFAULT_CONFIG_NAME, DEFAULT_CONFIG_EXTENSIONS } from "../5580.js";
|
|
2
2
|
const findConfig = (basePath)=>DEFAULT_CONFIG_EXTENSIONS.map((ext)=>basePath + ext).find(node_fs.existsSync);
|
|
3
3
|
async function loadConfigFile(customConfigFile) {
|
|
4
4
|
const baseDir = process.cwd();
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, rs } from '@rstest/core';
|
|
2
|
+
import { renderToMarkdownString } from 'react-render-to-markdown';
|
|
3
|
+
import { CodeBlock } from './index';
|
|
4
|
+
|
|
5
|
+
rs.mock('@rspress/core/theme', () => ({
|
|
6
|
+
CodeButtonGroup: () => null,
|
|
7
|
+
IconArrowDown: () => null,
|
|
8
|
+
SvgWrapper: () => null,
|
|
9
|
+
useCodeButtonGroup: () => ({
|
|
10
|
+
copyElementRef: { current: null },
|
|
11
|
+
toggleWrapCode: () => {},
|
|
12
|
+
wrapCode: false,
|
|
13
|
+
}),
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
const originalSsgMd = import.meta.env.SSG_MD;
|
|
17
|
+
|
|
18
|
+
const setSsgMd = (value: boolean | undefined) => {
|
|
19
|
+
if (value === undefined) {
|
|
20
|
+
delete (import.meta.env as unknown as Record<string, unknown>).SSG_MD;
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
(import.meta.env as unknown as Record<string, unknown>).SSG_MD = value;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
afterEach(() => {
|
|
28
|
+
setSsgMd(originalSsgMd);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe('CodeBlock', () => {
|
|
32
|
+
it('renders only its children when SSG_MD is enabled', async () => {
|
|
33
|
+
setSsgMd(true);
|
|
34
|
+
|
|
35
|
+
expect(
|
|
36
|
+
await renderToMarkdownString(
|
|
37
|
+
<CodeBlock title="example.ts">
|
|
38
|
+
<pre>const value = true;</pre>
|
|
39
|
+
</CodeBlock>,
|
|
40
|
+
),
|
|
41
|
+
).toMatchInlineSnapshot(`
|
|
42
|
+
"
|
|
43
|
+
\`\`\`\`
|
|
44
|
+
const value = true;
|
|
45
|
+
\`\`\`\`
|
|
46
|
+
"
|
|
47
|
+
`);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useSite } from '@rspress/core/runtime';
|
|
1
|
+
import { useI18n, useSite } from '@rspress/core/runtime';
|
|
2
2
|
import { IconWrap, IconWrapped, SvgWrapper } from '@rspress/core/theme';
|
|
3
3
|
import clsx from 'clsx';
|
|
4
4
|
import { useRef, useState } from 'react';
|
|
@@ -43,6 +43,8 @@ export function CodeButtonGroup({
|
|
|
43
43
|
showWrapCodeButton = true,
|
|
44
44
|
showCopyButton = true,
|
|
45
45
|
}: CodeButtonGroupProps) {
|
|
46
|
+
const t = useI18n();
|
|
47
|
+
|
|
46
48
|
return (
|
|
47
49
|
<>
|
|
48
50
|
<div className="rp-code-button-group">
|
|
@@ -54,7 +56,8 @@ export function CodeButtonGroup({
|
|
|
54
56
|
wrapCode && 'rp-code-wrap-button--wrapped',
|
|
55
57
|
)}
|
|
56
58
|
onClick={() => toggleWrapCode()}
|
|
57
|
-
title=
|
|
59
|
+
title={t('codeButtonGroupWrapButtonText')}
|
|
60
|
+
aria-label={t('codeButtonGroupWrapButtonText')}
|
|
58
61
|
>
|
|
59
62
|
<SvgWrapper
|
|
60
63
|
icon={IconWrapped}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, rs } from '@rstest/core';
|
|
2
|
+
import { renderToMarkdownString } from 'react-render-to-markdown';
|
|
3
|
+
import { FallbackHeading } from './index';
|
|
4
|
+
|
|
5
|
+
rs.mock('@rspress/core/theme', () => ({
|
|
6
|
+
getCustomMDXComponent: () => ({
|
|
7
|
+
a: 'a',
|
|
8
|
+
h1: 'h1',
|
|
9
|
+
h2: 'h2',
|
|
10
|
+
h3: 'h3',
|
|
11
|
+
h4: 'h4',
|
|
12
|
+
h5: 'h5',
|
|
13
|
+
h6: 'h6',
|
|
14
|
+
}),
|
|
15
|
+
renderInlineMarkdown: (text: string) => ({
|
|
16
|
+
dangerouslySetInnerHTML: { __html: text },
|
|
17
|
+
}),
|
|
18
|
+
}));
|
|
19
|
+
|
|
20
|
+
const originalSsgMd = import.meta.env.SSG_MD;
|
|
21
|
+
|
|
22
|
+
const setSsgMd = (value: boolean | undefined) => {
|
|
23
|
+
if (value === undefined) {
|
|
24
|
+
delete (import.meta.env as unknown as Record<string, unknown>).SSG_MD;
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
(import.meta.env as unknown as Record<string, unknown>).SSG_MD = value;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
afterEach(() => {
|
|
32
|
+
setSsgMd(originalSsgMd);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
describe('FallbackHeading', () => {
|
|
36
|
+
it('renders markdown when SSG_MD is enabled', async () => {
|
|
37
|
+
setSsgMd(true);
|
|
38
|
+
|
|
39
|
+
expect(
|
|
40
|
+
await renderToMarkdownString(
|
|
41
|
+
<FallbackHeading level={2} title="Getting Started" />,
|
|
42
|
+
),
|
|
43
|
+
).toBe('## Getting Started\n\n');
|
|
44
|
+
});
|
|
45
|
+
});
|
|
@@ -52,7 +52,7 @@ export function getHref(href: string): {
|
|
|
52
52
|
return { linkType: linkType, withBaseHref: href, removeBaseHref: href };
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
if (linkType === 'relative' && !
|
|
55
|
+
if (linkType === 'relative' && !import.meta.env.SSR) {
|
|
56
56
|
withBaseHref = new URL(href, window.location.href).pathname;
|
|
57
57
|
} else {
|
|
58
58
|
withBaseHref = withBase(cleanUrlByConfig(href));
|
|
@@ -84,7 +84,7 @@ export function useLinkNavigate(
|
|
|
84
84
|
|
|
85
85
|
const preloadChunkThenNavigate = async () => {
|
|
86
86
|
const inCurrPage = isActive(removeBaseHref, currPagePathname);
|
|
87
|
-
if (!
|
|
87
|
+
if (!import.meta.env.SSR && !inCurrPage) {
|
|
88
88
|
const matchedRoute = pathnameToRouteService(removeBaseHref);
|
|
89
89
|
if (matchedRoute) {
|
|
90
90
|
const timer = setTimeout(() => {
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, rs } from '@rstest/core';
|
|
2
|
+
import { renderToMarkdownString } from 'react-render-to-markdown';
|
|
3
|
+
import { Overview } from './index';
|
|
4
|
+
|
|
5
|
+
rs.mock('@rspress/core/runtime', () => ({
|
|
6
|
+
isEqualPath: (a: string, b: string) => a === b,
|
|
7
|
+
useI18n: () => (key: string) => key,
|
|
8
|
+
usePageData: () => ({
|
|
9
|
+
page: {
|
|
10
|
+
frontmatter: { overview: true },
|
|
11
|
+
routePath: '/guide/overview',
|
|
12
|
+
title: 'Guide Overview',
|
|
13
|
+
},
|
|
14
|
+
siteData: { pages: [] },
|
|
15
|
+
}),
|
|
16
|
+
useSidebar: () => [{ link: '/guide/overview', text: 'Overview' }],
|
|
17
|
+
}));
|
|
18
|
+
|
|
19
|
+
rs.mock('@rspress/core/theme', () => ({
|
|
20
|
+
FallbackHeading: ({ level, title }: { level: number; title: string }) =>
|
|
21
|
+
`${'#'.repeat(level)} ${title}\n\n`,
|
|
22
|
+
OverviewGroup: ({ group }: { group: { name: string } }) =>
|
|
23
|
+
`## ${group.name}\n\n`,
|
|
24
|
+
}));
|
|
25
|
+
|
|
26
|
+
const originalSsgMd = import.meta.env.SSG_MD;
|
|
27
|
+
|
|
28
|
+
const setSsgMd = (value: boolean | undefined) => {
|
|
29
|
+
if (value === undefined) {
|
|
30
|
+
delete (import.meta.env as unknown as Record<string, unknown>).SSG_MD;
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
(import.meta.env as unknown as Record<string, unknown>).SSG_MD = value;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
afterEach(() => {
|
|
38
|
+
setSsgMd(originalSsgMd);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
describe('Overview', () => {
|
|
42
|
+
it('renders heading and groups as markdown when SSG_MD is enabled', async () => {
|
|
43
|
+
setSsgMd(true);
|
|
44
|
+
|
|
45
|
+
expect(
|
|
46
|
+
await renderToMarkdownString(
|
|
47
|
+
<Overview groups={[{ name: 'Guides', items: [] }]} />,
|
|
48
|
+
),
|
|
49
|
+
).toMatchInlineSnapshot(`
|
|
50
|
+
"# Guide Overview
|
|
51
|
+
|
|
52
|
+
## Guides
|
|
53
|
+
|
|
54
|
+
"
|
|
55
|
+
`);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, rs } from '@rstest/core';
|
|
2
|
+
import { renderToMarkdownString } from 'react-render-to-markdown';
|
|
3
|
+
import { OverviewGroup, type Group } from './index';
|
|
4
|
+
|
|
5
|
+
rs.mock('@rspress/core/runtime', () => ({
|
|
6
|
+
routePathToMdPath: (routePath: string) => `${routePath}.md`,
|
|
7
|
+
}));
|
|
8
|
+
|
|
9
|
+
rs.mock('@rspress/core/theme', () => ({
|
|
10
|
+
FallbackHeading: () => null,
|
|
11
|
+
Link: 'a',
|
|
12
|
+
SvgWrapper: () => null,
|
|
13
|
+
renderInlineMarkdown: (text: string) => ({
|
|
14
|
+
dangerouslySetInnerHTML: { __html: text },
|
|
15
|
+
}),
|
|
16
|
+
}));
|
|
17
|
+
|
|
18
|
+
const originalSsgMd = import.meta.env.SSG_MD;
|
|
19
|
+
|
|
20
|
+
const setSsgMd = (value: boolean | undefined) => {
|
|
21
|
+
if (value === undefined) {
|
|
22
|
+
delete (import.meta.env as unknown as Record<string, unknown>).SSG_MD;
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
(import.meta.env as unknown as Record<string, unknown>).SSG_MD = value;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
afterEach(() => {
|
|
30
|
+
setSsgMd(originalSsgMd);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
describe('OverviewGroup', () => {
|
|
34
|
+
it('renders overview links as markdown when SSG_MD is enabled', async () => {
|
|
35
|
+
setSsgMd(true);
|
|
36
|
+
|
|
37
|
+
const group: Group = {
|
|
38
|
+
name: 'Guide',
|
|
39
|
+
items: [
|
|
40
|
+
{
|
|
41
|
+
text: 'Introduction',
|
|
42
|
+
link: '/guide/introduction',
|
|
43
|
+
headers: [{ id: 'install', text: 'Install', depth: 2 }],
|
|
44
|
+
items: [{ text: 'Configuration', link: '/guide/configuration' }],
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
expect(await renderToMarkdownString(<OverviewGroup group={group} />))
|
|
50
|
+
.toMatchInlineSnapshot(`
|
|
51
|
+
"## Guide
|
|
52
|
+
|
|
53
|
+
### [Introduction](/guide/introduction.md)
|
|
54
|
+
|
|
55
|
+
- [Install](/guide/introduction.md#install)
|
|
56
|
+
|
|
57
|
+
- [Configuration](/guide/configuration.md)
|
|
58
|
+
"
|
|
59
|
+
`);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, rs } from '@rstest/core';
|
|
2
|
+
import type { ReactNode } from 'react';
|
|
3
|
+
import { renderToMarkdownString } from 'react-render-to-markdown';
|
|
4
|
+
import { PackageManagerTabs } from './index';
|
|
5
|
+
|
|
6
|
+
rs.mock('@rspress/core/theme', () => ({
|
|
7
|
+
getCustomMDXComponent: () => ({
|
|
8
|
+
pre: 'pre',
|
|
9
|
+
}),
|
|
10
|
+
Tab: ({ children }: { children: ReactNode }) => children,
|
|
11
|
+
Tabs: ({ children }: { children: ReactNode }) => children,
|
|
12
|
+
}));
|
|
13
|
+
|
|
14
|
+
const originalSsgMd = import.meta.env.SSG_MD;
|
|
15
|
+
|
|
16
|
+
const setSsgMd = (value: boolean | undefined) => {
|
|
17
|
+
if (value === undefined) {
|
|
18
|
+
delete (import.meta.env as unknown as Record<string, unknown>).SSG_MD;
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
(import.meta.env as unknown as Record<string, unknown>).SSG_MD = value;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
afterEach(() => {
|
|
26
|
+
setSsgMd(originalSsgMd);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe('PackageManagerTabs', () => {
|
|
30
|
+
it('renders install commands as markdown code fences when SSG_MD is enabled', async () => {
|
|
31
|
+
setSsgMd(true);
|
|
32
|
+
|
|
33
|
+
expect(
|
|
34
|
+
await renderToMarkdownString(
|
|
35
|
+
<PackageManagerTabs
|
|
36
|
+
command={{
|
|
37
|
+
npm: 'npm install rspress',
|
|
38
|
+
pnpm: 'pnpm add rspress',
|
|
39
|
+
}}
|
|
40
|
+
/>,
|
|
41
|
+
),
|
|
42
|
+
).toMatchInlineSnapshot(`
|
|
43
|
+
"
|
|
44
|
+
\`\`\`sh [npm]
|
|
45
|
+
npm install rspress
|
|
46
|
+
\`\`\`
|
|
47
|
+
|
|
48
|
+
\`\`\`sh [pnpm]
|
|
49
|
+
pnpm add rspress
|
|
50
|
+
\`\`\`
|
|
51
|
+
"
|
|
52
|
+
`);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -218,7 +218,7 @@ export function PackageManagerTabs({
|
|
|
218
218
|
commandInfo = command;
|
|
219
219
|
}
|
|
220
220
|
|
|
221
|
-
if (
|
|
221
|
+
if (import.meta.env.SSG_MD) {
|
|
222
222
|
return Object.values(commandInfo).reduce((previous, current) => {
|
|
223
223
|
const [packageManager, command] = splitTo2Parts(current);
|
|
224
224
|
return (
|
|
@@ -231,27 +231,26 @@ export function PackageManagerTabs({
|
|
|
231
231
|
}
|
|
232
232
|
|
|
233
233
|
return (
|
|
234
|
-
<Tabs
|
|
235
|
-
groupId="package.manager"
|
|
236
|
-
values={Object.entries(commandInfo).map(([key]) => (
|
|
237
|
-
<div
|
|
238
|
-
key={key}
|
|
239
|
-
style={{
|
|
240
|
-
display: 'flex',
|
|
241
|
-
alignItems: 'center',
|
|
242
|
-
fontSize: 15,
|
|
243
|
-
}}
|
|
244
|
-
>
|
|
245
|
-
{packageMangerToIcon[key]}
|
|
246
|
-
<span style={{ marginLeft: 6, marginBottom: 2 }}>{key}</span>
|
|
247
|
-
</div>
|
|
248
|
-
))}
|
|
249
|
-
>
|
|
234
|
+
<Tabs groupId="package.manager">
|
|
250
235
|
{Object.entries(commandInfo).map(([key, value]) => {
|
|
251
236
|
const [packageManager, command] = splitTo2Parts(value);
|
|
252
237
|
|
|
253
238
|
return (
|
|
254
|
-
<Tab
|
|
239
|
+
<Tab
|
|
240
|
+
key={key}
|
|
241
|
+
label={
|
|
242
|
+
<div
|
|
243
|
+
style={{
|
|
244
|
+
display: 'flex',
|
|
245
|
+
alignItems: 'center',
|
|
246
|
+
fontSize: 15,
|
|
247
|
+
}}
|
|
248
|
+
>
|
|
249
|
+
{packageMangerToIcon[key]}
|
|
250
|
+
<span style={{ marginLeft: 6, marginBottom: 2 }}>{key}</span>
|
|
251
|
+
</div>
|
|
252
|
+
}
|
|
253
|
+
>
|
|
255
254
|
<Pre
|
|
256
255
|
lang="bash"
|
|
257
256
|
className="shiki css-variables"
|
|
@@ -388,15 +388,10 @@ export function SearchPanel({ focused, setFocused }: SearchPanelProps) {
|
|
|
388
388
|
);
|
|
389
389
|
}
|
|
390
390
|
|
|
391
|
-
const tabValues = result.map(item => {
|
|
392
|
-
return item.group;
|
|
393
|
-
});
|
|
394
|
-
|
|
395
391
|
const renderKey = 'render' as const;
|
|
396
392
|
|
|
397
393
|
return (
|
|
398
394
|
<Tabs
|
|
399
|
-
values={tabValues}
|
|
400
395
|
className="rp-search-panel__tabs"
|
|
401
396
|
onChange={index => {
|
|
402
397
|
setResultTabIndex(index);
|
|
@@ -406,7 +401,7 @@ export function SearchPanel({ focused, setFocused }: SearchPanelProps) {
|
|
|
406
401
|
ref={searchResultTabRef}
|
|
407
402
|
>
|
|
408
403
|
{result.map(item => (
|
|
409
|
-
<Tab key={item.group}>
|
|
404
|
+
<Tab key={item.group} label={item.group}>
|
|
410
405
|
{item.renderType === RenderType.Default &&
|
|
411
406
|
renderSearchResultItem(item.result, query, isSearching)}
|
|
412
407
|
{item.renderType === RenderType.Custom &&
|
|
@@ -56,7 +56,7 @@ export function SidebarItemRaw({
|
|
|
56
56
|
const innerContent = (
|
|
57
57
|
<>
|
|
58
58
|
<div className="rp-sidebar-item__left" ref={ref}>
|
|
59
|
-
<span {...renderInlineMarkdown(text)}></span>
|
|
59
|
+
<span className="rp-doc" {...renderInlineMarkdown(text)}></span>
|
|
60
60
|
{left}
|
|
61
61
|
</div>
|
|
62
62
|
<div className="rp-sidebar-item__right">
|
|
@@ -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
|
+
});
|