@umijs/plugin-docs 4.0.6 → 4.0.9
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/client/theme-doc/Search.tsx +2 -2
- package/client/theme-doc/Toc.tsx +3 -2
- package/client/theme-doc/components/Tabbed.tsx +78 -0
- package/client/theme-doc/index.ts +1 -0
- package/client/theme-doc/tailwind.css +25 -9
- package/dist/compiler.js +70 -61
- package/dist/index.js +134 -128
- package/dist/loader.js +41 -21
- package/dist/markdown.js +42 -20
- package/package.json +7 -5
- package/client/theme-doc/tailwind.out.css +0 -2662
- package/client/theme-doc/utils/getLinkFromTitle.ts +0 -15
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import cx from 'classnames';
|
|
2
|
+
import slugger from 'github-slugger';
|
|
2
3
|
import key from 'keymaster';
|
|
3
4
|
import React, { Fragment, useEffect, useState } from 'react';
|
|
4
5
|
import { useThemeContext } from './context';
|
|
5
6
|
import useLanguage from './useLanguage';
|
|
6
|
-
import getLinkFromTitle from './utils/getLinkFromTitle';
|
|
7
7
|
|
|
8
8
|
export default () => {
|
|
9
9
|
const { components } = useThemeContext()!;
|
|
@@ -168,7 +168,7 @@ function search(routes: any, keyword: string): SearchResultItem[] {
|
|
|
168
168
|
.join(' > ') +
|
|
169
169
|
' > ' +
|
|
170
170
|
title.title,
|
|
171
|
-
href: '/' + path + '#' +
|
|
171
|
+
href: '/' + path + '#' + slugger.slug(title.title),
|
|
172
172
|
});
|
|
173
173
|
}
|
|
174
174
|
});
|
package/client/theme-doc/Toc.tsx
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import GithubSlugger from 'github-slugger';
|
|
1
2
|
import React from 'react';
|
|
2
3
|
import { Helmet } from 'react-helmet';
|
|
3
4
|
import { useThemeContext } from './context';
|
|
4
5
|
import useLanguage from './useLanguage';
|
|
5
|
-
import getLinkFromTitle from './utils/getLinkFromTitle';
|
|
6
6
|
import getTocTitle from './utils/getTocTitle';
|
|
7
7
|
|
|
8
8
|
export default () => {
|
|
9
|
+
const slugger = new GithubSlugger();
|
|
9
10
|
const { location, appData, themeConfig } = useThemeContext()!;
|
|
10
11
|
const lang = useLanguage();
|
|
11
12
|
const route =
|
|
@@ -48,7 +49,7 @@ export default () => {
|
|
|
48
49
|
className={`${
|
|
49
50
|
item.level > 2 ? 'text-sm' : 'text-base'
|
|
50
51
|
} break-all 2xl:break-words`}
|
|
51
|
-
href={'#' +
|
|
52
|
+
href={'#' + slugger.slug(item.title)}
|
|
52
53
|
>
|
|
53
54
|
{getTocTitle(item.title)}
|
|
54
55
|
</a>
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import React, { FC, PropsWithChildren, ReactNode, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
type Pane = {
|
|
4
|
+
title: ReactNode;
|
|
5
|
+
content: ReactNode;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
type TabbedProps = {
|
|
9
|
+
panes?: Pane[];
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export default function Tabbed(props: PropsWithChildren<TabbedProps>) {
|
|
13
|
+
const { children } = props;
|
|
14
|
+
|
|
15
|
+
const [activeTab, setActiveTab] = useState(0);
|
|
16
|
+
|
|
17
|
+
let tabs: ReactNode[] = [];
|
|
18
|
+
let content: ReactNode = null;
|
|
19
|
+
|
|
20
|
+
if (props.panes && props.panes.length > 0) {
|
|
21
|
+
tabs = props.panes.map((pane) => {
|
|
22
|
+
return pane.title;
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
content = props.panes[activeTab].content;
|
|
26
|
+
} else {
|
|
27
|
+
// Guess pane from children, make mdx more idiomatic
|
|
28
|
+
const childrenArray = React.Children.toArray(children) || [];
|
|
29
|
+
|
|
30
|
+
tabs = childrenArray.filter((_, index) => index % 2 === 0);
|
|
31
|
+
const contents = childrenArray.filter((_, index) => index % 2 === 1);
|
|
32
|
+
|
|
33
|
+
content = contents[activeTab];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<div className="tabbed-code">
|
|
38
|
+
<Wrapper>
|
|
39
|
+
<Tabs tabs={tabs} setActiveTab={setActiveTab} activeTab={activeTab} />
|
|
40
|
+
</Wrapper>
|
|
41
|
+
{content || null}
|
|
42
|
+
</div>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
const Wrapper: FC<PropsWithChildren> = ({ children }) => {
|
|
46
|
+
return <div className={`w-full pt-5 pt-0 `}>{children}</div>;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const Tabs: FC<
|
|
50
|
+
PropsWithChildren<{
|
|
51
|
+
tabs: ReactNode[];
|
|
52
|
+
setActiveTab: Function;
|
|
53
|
+
activeTab: number;
|
|
54
|
+
}>
|
|
55
|
+
> = ({ tabs, activeTab, setActiveTab }) => {
|
|
56
|
+
return (
|
|
57
|
+
<ul className="cursor-pointer m-0 mt-4 px-0 list-none inline-flex flex-wrap rounded-t-lg text-sm font-small text-center text-gray-500 dark:text-gray-400">
|
|
58
|
+
{tabs.map((tab, index) => {
|
|
59
|
+
return (
|
|
60
|
+
<li key={index} className="mr-0 mt-0">
|
|
61
|
+
<button
|
|
62
|
+
onClick={() => setActiveTab(index)}
|
|
63
|
+
className={`tabbed-tab-button
|
|
64
|
+
hover:text-gray-700 hover:border-gray-300 dark:hover:text-gray-300
|
|
65
|
+
${
|
|
66
|
+
activeTab === index
|
|
67
|
+
? 'bg-zinc-900 text-white hover:text-neutral-300 dark:text-white'
|
|
68
|
+
: 'text-neutral-500 hover:text-gray-700 hover:border-gray-300 dark:hover:text-gray-300 '
|
|
69
|
+
}`}
|
|
70
|
+
>
|
|
71
|
+
{tab}
|
|
72
|
+
</button>
|
|
73
|
+
</li>
|
|
74
|
+
);
|
|
75
|
+
})}
|
|
76
|
+
</ul>
|
|
77
|
+
);
|
|
78
|
+
};
|
|
@@ -5,4 +5,5 @@ export { default as FeatureItem } from './components/FeatureItem';
|
|
|
5
5
|
export { default as Features } from './components/Features';
|
|
6
6
|
export { default as Hero } from './components/Hero';
|
|
7
7
|
export { default as Message } from './components/Message';
|
|
8
|
+
export { default as Tabbed } from './components/Tabbed';
|
|
8
9
|
export { default as $Layout } from './Layout';
|
|
@@ -77,6 +77,23 @@ article div[data-rehype-pretty-code-fragment] {
|
|
|
77
77
|
@apply my-4;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
+
article .tabbed-code div[data-rehype-pretty-code-fragment] {
|
|
81
|
+
@apply my-0;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
article .tabbed-code pre {
|
|
85
|
+
@apply rounded-none rounded-b-md rounded-tr-md;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
article .tabbed-code .tabbed-tab-button {
|
|
89
|
+
@apply inline-flex items-center rounded-t-lg px-4;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
article .tabbed-code .tabbed-tab-button * {
|
|
93
|
+
@apply mt-0;
|
|
94
|
+
color: inherit;
|
|
95
|
+
}
|
|
96
|
+
|
|
80
97
|
/* 代码块的标题部分 */
|
|
81
98
|
article
|
|
82
99
|
div[data-rehype-pretty-code-fragment]
|
|
@@ -223,7 +240,6 @@ h6 {
|
|
|
223
240
|
}
|
|
224
241
|
|
|
225
242
|
@layer components {
|
|
226
|
-
|
|
227
243
|
.title-link a {
|
|
228
244
|
float: left;
|
|
229
245
|
margin-top: 0.1em;
|
|
@@ -233,19 +249,19 @@ h6 {
|
|
|
233
249
|
line-height: 1;
|
|
234
250
|
box-sizing: border-box;
|
|
235
251
|
background: none;
|
|
236
|
-
opacity: 0
|
|
237
|
-
}
|
|
252
|
+
opacity: 0;
|
|
253
|
+
}
|
|
238
254
|
|
|
239
|
-
.title-link:hover a{
|
|
240
|
-
opacity: 1
|
|
255
|
+
.title-link:hover a {
|
|
256
|
+
opacity: 1;
|
|
241
257
|
}
|
|
242
258
|
|
|
243
|
-
.title-link span{
|
|
259
|
+
.title-link span {
|
|
244
260
|
display: none;
|
|
245
261
|
}
|
|
246
|
-
|
|
247
|
-
.title-link a::after{
|
|
248
|
-
content:
|
|
262
|
+
|
|
263
|
+
.title-link a::after {
|
|
264
|
+
content: '#';
|
|
249
265
|
display: inline-block;
|
|
250
266
|
vertical-align: middle;
|
|
251
267
|
font-size: 20px;
|
package/dist/compiler.js
CHANGED
|
@@ -1,60 +1,70 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
4
10
|
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
|
|
22
|
+
// compiler.ts
|
|
23
|
+
var compiler_exports = {};
|
|
24
|
+
__export(compiler_exports, {
|
|
25
|
+
compile: () => compile
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(compiler_exports);
|
|
28
|
+
var import_rehype_pretty_code = __toESM(require("rehype-pretty-code"));
|
|
29
|
+
var import_plugin_utils = require("umi/plugin-utils");
|
|
30
|
+
var import_mdx = require("../compiled/@mdx-js/mdx");
|
|
31
|
+
var import_rehype_slug = __toESM(require("../compiled/rehype-slug"));
|
|
32
|
+
var import_remark_gfm = __toESM(require("../compiled/remark-gfm"));
|
|
33
|
+
var import_rehype_autolink_headings = __toESM(require("../compiled/rehype-autolink-headings"));
|
|
34
|
+
var rehypePrettyCodeOptions = {
|
|
35
|
+
theme: "dark-plus",
|
|
36
|
+
onVisitLine(node) {
|
|
37
|
+
if (node.children.length === 0) {
|
|
38
|
+
node.children = [{ type: "text", value: " " }];
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
onVisitHighlightedLine(node) {
|
|
42
|
+
node.properties.className.push("highlighted");
|
|
43
|
+
},
|
|
44
|
+
onVisitHighlightedWord(node) {
|
|
45
|
+
node.properties.className = ["word"];
|
|
46
|
+
}
|
|
37
47
|
};
|
|
38
48
|
async function compile(opts) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
const compiler = (0, import_mdx.createProcessor)({
|
|
50
|
+
jsx: true,
|
|
51
|
+
remarkPlugins: [import_remark_gfm.default],
|
|
52
|
+
rehypePlugins: [
|
|
53
|
+
import_rehype_slug.default,
|
|
54
|
+
[import_rehype_pretty_code.default, rehypePrettyCodeOptions],
|
|
55
|
+
import_rehype_autolink_headings.default
|
|
56
|
+
]
|
|
57
|
+
});
|
|
58
|
+
try {
|
|
59
|
+
let result = String(await compiler.process(opts.content));
|
|
60
|
+
result = result.replace("function MDXContent(props = {}) {", `
|
|
51
61
|
import { useEffect } from 'react';
|
|
52
62
|
|
|
53
63
|
function MDXContent(props = {}) {
|
|
54
64
|
|
|
55
65
|
useEffect(() => {
|
|
56
66
|
if (window.location.hash.length !== 0) {
|
|
57
|
-
//
|
|
67
|
+
// \u4E3A\u4E86\u53F3\u4FA7\u5185\u5BB9\u533A\u80FD\u6B63\u5E38\u8DF3\u8F6C
|
|
58
68
|
const hash = decodeURIComponent(window.location.hash);
|
|
59
69
|
setTimeout(() => {
|
|
60
70
|
document.getElementById(hash.slice(1))?.scrollIntoView();
|
|
@@ -69,17 +79,16 @@ function MDXContent(props = {}) {
|
|
|
69
79
|
}, []);
|
|
70
80
|
|
|
71
81
|
`);
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
.join('\n'));
|
|
81
|
-
plugin_utils_1.logger.error(' '.repeat(e.column - 1) + '^');
|
|
82
|
-
return { result: '' };
|
|
83
|
-
}
|
|
82
|
+
return { result };
|
|
83
|
+
} catch (e) {
|
|
84
|
+
import_plugin_utils.logger.error(e.reason);
|
|
85
|
+
import_plugin_utils.logger.error(`Above error occurred in ${opts.fileName} at line ${e.line}`);
|
|
86
|
+
import_plugin_utils.logger.error(opts.content.split("\n").filter((_, i) => i == e.line - 1).join("\n"));
|
|
87
|
+
import_plugin_utils.logger.error(" ".repeat(e.column - 1) + "^");
|
|
88
|
+
return { result: "" };
|
|
89
|
+
}
|
|
84
90
|
}
|
|
85
|
-
|
|
91
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
92
|
+
0 && (module.exports = {
|
|
93
|
+
compile
|
|
94
|
+
});
|
package/dist/index.js
CHANGED
|
@@ -1,135 +1,141 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __spreadValues = (a, b) => {
|
|
13
|
+
for (var prop in b || (b = {}))
|
|
14
|
+
if (__hasOwnProp.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
if (__getOwnPropSymbols)
|
|
17
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
+
if (__propIsEnum.call(b, prop))
|
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
|
7
20
|
}
|
|
8
|
-
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
21
|
+
return a;
|
|
24
22
|
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
23
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
+
var __export = (target, all) => {
|
|
25
|
+
for (var name in all)
|
|
26
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
27
|
+
};
|
|
28
|
+
var __copyProps = (to, from, except, desc) => {
|
|
29
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
30
|
+
for (let key of __getOwnPropNames(from))
|
|
31
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
32
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
33
|
+
}
|
|
34
|
+
return to;
|
|
35
|
+
};
|
|
36
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
37
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
38
|
+
|
|
39
|
+
// index.ts
|
|
40
|
+
var src_exports = {};
|
|
41
|
+
__export(src_exports, {
|
|
42
|
+
default: () => src_default
|
|
43
|
+
});
|
|
44
|
+
module.exports = __toCommonJS(src_exports);
|
|
45
|
+
var import_bundler_utils = require("@umijs/bundler-utils");
|
|
46
|
+
var import_utils = require("@umijs/utils");
|
|
47
|
+
var import_fs = __toESM(require("fs"));
|
|
48
|
+
var import_path = require("path");
|
|
49
|
+
var import_markdown = require("./markdown");
|
|
50
|
+
var src_default = (api) => {
|
|
51
|
+
const locales = {};
|
|
52
|
+
const localesPath = (0, import_path.join)(api.cwd, "docs/locales");
|
|
53
|
+
if ((0, import_fs.existsSync)(localesPath)) {
|
|
54
|
+
import_fs.default.readdirSync(localesPath).forEach((file) => {
|
|
55
|
+
if (file.endsWith(".json")) {
|
|
56
|
+
const filePath = (0, import_path.join)(localesPath, file);
|
|
57
|
+
const content = import_fs.default.readFileSync(filePath).toString();
|
|
58
|
+
const json = JSON.parse(content);
|
|
59
|
+
const localeName = file.replace(".json", "");
|
|
60
|
+
locales[localeName] = json;
|
|
61
|
+
}
|
|
56
62
|
});
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
file: withTmpPath({ api, path: 'Layout.tsx' }),
|
|
62
|
-
},
|
|
63
|
-
];
|
|
63
|
+
}
|
|
64
|
+
api.modifyDefaultConfig((memo) => {
|
|
65
|
+
memo.conventionRoutes = __spreadProps(__spreadValues({}, memo.conventionRoutes), {
|
|
66
|
+
base: (0, import_path.join)(api.cwd, "docs")
|
|
64
67
|
});
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
68
|
+
memo.mdx = {
|
|
69
|
+
loader: require.resolve("./loader"),
|
|
70
|
+
loaderOptions: {}
|
|
71
|
+
};
|
|
72
|
+
return memo;
|
|
73
|
+
});
|
|
74
|
+
api.addLayouts(() => {
|
|
75
|
+
return [
|
|
76
|
+
{
|
|
77
|
+
id: "docs-layout",
|
|
78
|
+
file: withTmpPath({ api, path: "Layout.tsx" })
|
|
79
|
+
}
|
|
80
|
+
];
|
|
81
|
+
});
|
|
82
|
+
api.onPatchRoute(({ route }) => {
|
|
83
|
+
if (route.__content) {
|
|
84
|
+
route.titles = (0, import_markdown.parseTitle)({
|
|
85
|
+
content: route.__content
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
if (route.file.match(/.[a-z]{2}-[A-Z]{2}.md$/)) {
|
|
89
|
+
route.path = route.path.replace(/(.*).([a-z]{2}-[A-Z]{2})$/, "$2/$1");
|
|
90
|
+
if (route.path.endsWith("README")) {
|
|
91
|
+
route.path = route.path.replace(/README$/, "");
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
api.modifyRoutes((r) => {
|
|
96
|
+
if (!locales)
|
|
97
|
+
return r;
|
|
98
|
+
for (const route in r) {
|
|
99
|
+
if (r[route].path.match(/^[a-z]{2}-[A-Z]{2}\/.*/))
|
|
100
|
+
continue;
|
|
101
|
+
const defaultLangFile = r[route].file.replace(/(.[a-z]{2}-[A-Z]{2})?.md$/, "");
|
|
102
|
+
Object.keys(locales).map((l) => {
|
|
103
|
+
if (r[defaultLangFile] && !r[defaultLangFile + "." + l]) {
|
|
104
|
+
r[defaultLangFile + "." + l] = __spreadProps(__spreadValues({}, r[defaultLangFile]), {
|
|
105
|
+
path: `/${l}/${r[defaultLangFile].path}`
|
|
106
|
+
});
|
|
78
107
|
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
return r;
|
|
111
|
+
});
|
|
112
|
+
api.onGenerateFiles(() => {
|
|
113
|
+
var _a;
|
|
114
|
+
let theme = ((_a = api.config.docs) == null ? void 0 : _a.theme) || require.resolve("../client/theme-doc/index.ts");
|
|
115
|
+
if (theme === "blog") {
|
|
116
|
+
theme = require.resolve("../client/theme-blog/index.ts");
|
|
117
|
+
}
|
|
118
|
+
theme = (0, import_utils.winPath)(theme);
|
|
119
|
+
const themeConfigPath = (0, import_utils.winPath)((0, import_path.join)(api.cwd, "theme.config.ts"));
|
|
120
|
+
const themeExists = (0, import_fs.existsSync)(themeConfigPath);
|
|
121
|
+
let injectLocale = `themeConfig.locales = ${JSON.stringify(locales)};`;
|
|
122
|
+
const [_, exports] = (0, import_bundler_utils.parseModuleSync)({
|
|
123
|
+
content: (0, import_fs.readFileSync)(theme, "utf-8"),
|
|
124
|
+
path: theme
|
|
79
125
|
});
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (r[route].path.match(/^[a-z]{2}-[A-Z]{2}\/.*/))
|
|
86
|
-
continue;
|
|
87
|
-
const defaultLangFile = r[route].file.replace(/(.[a-z]{2}-[A-Z]{2})?.md$/, '');
|
|
88
|
-
Object.keys(locales).map((l) => {
|
|
89
|
-
if (r[defaultLangFile] && !r[defaultLangFile + '.' + l]) {
|
|
90
|
-
r[defaultLangFile + '.' + l] = {
|
|
91
|
-
...r[defaultLangFile],
|
|
92
|
-
path: `/${l}/${r[defaultLangFile].path}`,
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
return r;
|
|
126
|
+
api.writeTmpFile({
|
|
127
|
+
path: "index.ts",
|
|
128
|
+
content: `
|
|
129
|
+
export { ${exports.filter((item) => !item.startsWith("$")).join(", ")} } from '${(0, import_utils.winPath)(require.resolve("../client/theme-doc/index.ts"))}';
|
|
130
|
+
`
|
|
98
131
|
});
|
|
99
|
-
api.
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
let theme = ((_a = api.config.docs) === null || _a === void 0 ? void 0 : _a.theme) || require.resolve('../client/theme-doc/index.ts');
|
|
103
|
-
if (theme === 'blog') {
|
|
104
|
-
theme = require.resolve('../client/theme-blog/index.ts');
|
|
105
|
-
}
|
|
106
|
-
theme = (0, utils_1.winPath)(theme);
|
|
107
|
-
const themeConfigPath = (0, utils_1.winPath)((0, path_1.join)(api.cwd, 'theme.config.ts'));
|
|
108
|
-
const themeExists = (0, fs_1.existsSync)(themeConfigPath);
|
|
109
|
-
// 将 docs/locales 目录下的 json 文件注入到 themeConfig.locales 中
|
|
110
|
-
let injectLocale = `themeConfig.locales = ${JSON.stringify(locales)};`;
|
|
111
|
-
// exports don't start with $ will be MDX Component
|
|
112
|
-
const [_, exports] = (0, bundler_utils_1.parseModuleSync)({
|
|
113
|
-
content: (0, fs_1.readFileSync)(theme, 'utf-8'),
|
|
114
|
-
path: theme,
|
|
115
|
-
});
|
|
116
|
-
api.writeTmpFile({
|
|
117
|
-
path: 'index.ts',
|
|
118
|
-
content: `
|
|
119
|
-
export { ${exports
|
|
120
|
-
.filter((item) => !item.startsWith('$'))
|
|
121
|
-
.join(', ')} } from '${(0, utils_1.winPath)(require.resolve('../client/theme-doc/index.ts'))}';
|
|
122
|
-
`,
|
|
123
|
-
});
|
|
124
|
-
api.writeTmpFile({
|
|
125
|
-
path: 'Layout.tsx',
|
|
126
|
-
content: `
|
|
132
|
+
api.writeTmpFile({
|
|
133
|
+
path: "Layout.tsx",
|
|
134
|
+
content: `
|
|
127
135
|
import React from 'react';
|
|
128
136
|
import { useOutlet, useAppData, useLocation, Link, history } from 'umi';
|
|
129
|
-
import { $Layout as Layout } from '${(0,
|
|
130
|
-
${themeExists
|
|
131
|
-
? `import themeConfig from '${themeConfigPath}'`
|
|
132
|
-
: `const themeConfig = {}`}
|
|
137
|
+
import { $Layout as Layout } from '${(0, import_utils.winPath)(require.resolve("../client/theme-doc/index.ts"))}';
|
|
138
|
+
${themeExists ? `import themeConfig from '${themeConfigPath}'` : `const themeConfig = {}`}
|
|
133
139
|
|
|
134
140
|
${injectLocale}
|
|
135
141
|
|
|
@@ -143,12 +149,12 @@ export default () => {
|
|
|
143
149
|
</Layout>
|
|
144
150
|
);
|
|
145
151
|
};
|
|
146
|
-
|
|
147
|
-
});
|
|
152
|
+
`
|
|
148
153
|
});
|
|
154
|
+
});
|
|
149
155
|
};
|
|
150
156
|
function withTmpPath(opts) {
|
|
151
|
-
|
|
152
|
-
? `plugin-${opts.api.plugin.key}`
|
|
153
|
-
: '', opts.path);
|
|
157
|
+
return (0, import_path.join)(opts.api.paths.absTmpPath, opts.api.plugin.key && !opts.noPluginDir ? `plugin-${opts.api.plugin.key}` : "", opts.path);
|
|
154
158
|
}
|
|
159
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
160
|
+
0 && (module.exports = {});
|