@umijs/plugin-docs 4.0.47 → 4.0.48
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/NavBar.tsx +10 -14
- package/client/theme-doc/context.ts +44 -30
- package/dist/compiler.js +13 -5
- package/dist/index.js +19 -5
- package/package.json +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { useState } from 'react';
|
|
2
|
-
import { useThemeContext } from './context';
|
|
2
|
+
import { useThemeContext, type INav, type INavDropdown } from './context';
|
|
3
3
|
import ExternalLink from './icons/link.svg';
|
|
4
4
|
import useLanguage from './useLanguage';
|
|
5
5
|
|
|
@@ -14,25 +14,17 @@ export default () => {
|
|
|
14
14
|
);
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
interface
|
|
18
|
-
nav:
|
|
19
|
-
path: string;
|
|
20
|
-
title: string;
|
|
21
|
-
type?: 'nav' | 'link';
|
|
22
|
-
dropdown?: {
|
|
23
|
-
title: string;
|
|
24
|
-
path: string;
|
|
25
|
-
}[];
|
|
26
|
-
};
|
|
17
|
+
interface INavItemProps {
|
|
18
|
+
nav: INav;
|
|
27
19
|
}
|
|
28
20
|
|
|
29
|
-
function NavItem(props:
|
|
21
|
+
function NavItem(props: INavItemProps) {
|
|
30
22
|
const { components } = useThemeContext()!;
|
|
31
23
|
const { nav } = props;
|
|
32
24
|
const lang = useLanguage();
|
|
33
25
|
const [isExpanded, setExpanded] = useState(false);
|
|
34
26
|
|
|
35
|
-
const isExternalLink = (n:
|
|
27
|
+
const isExternalLink = (n: INavDropdown) => {
|
|
36
28
|
return (
|
|
37
29
|
n.type === 'link' && /(https|http):\/\/([\w.]+\/?)\S*/.test(nav.path)
|
|
38
30
|
);
|
|
@@ -54,7 +46,11 @@ function NavItem(props: NavItemProps) {
|
|
|
54
46
|
) : (
|
|
55
47
|
<components.Link
|
|
56
48
|
to={
|
|
57
|
-
|
|
49
|
+
nav.link
|
|
50
|
+
? nav.link
|
|
51
|
+
: lang.isFromPath
|
|
52
|
+
? lang.currentLanguage?.locale + nav.path
|
|
53
|
+
: nav.path
|
|
58
54
|
}
|
|
59
55
|
>
|
|
60
56
|
{lang.render(nav.title)}
|
|
@@ -1,37 +1,51 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
interface
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
export interface INavBaseProps {
|
|
4
|
+
path: string;
|
|
5
|
+
title: string;
|
|
6
|
+
type?: 'nav' | 'link';
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface INavDropdown extends INavBaseProps {}
|
|
10
|
+
|
|
11
|
+
export interface INav extends INavBaseProps {
|
|
12
|
+
/**
|
|
13
|
+
* 不使用 navigate 重定向,而是直接用 link 指定最终地址,否则会破坏 history 历史,导致无法返回
|
|
14
|
+
* https://github.com/umijs/umi/issues/10325
|
|
15
|
+
*/
|
|
16
|
+
link: string;
|
|
17
|
+
dropdown?: INavDropdown[];
|
|
18
|
+
children: any[];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface IThemeConfig {
|
|
22
|
+
title: string;
|
|
23
|
+
description?: string;
|
|
24
|
+
github: string;
|
|
25
|
+
// 键盘搜索的快捷键,参考 https://github.com/madrobby/keymaster
|
|
26
|
+
searchHotKey?: string | { macos: string; windows: string };
|
|
27
|
+
logo: string | React.ComponentType;
|
|
28
|
+
// 在设置文件中声明该项目的国际化功能支持的语言
|
|
29
|
+
i18n?: { locale: string; text: string }[];
|
|
30
|
+
// 插件会从 docs/locales 内将所有 json 文件注入到 themeConfig 中
|
|
31
|
+
// 供 useLanguage 使用
|
|
32
|
+
locales: { [locale: string]: { [key: string]: string } };
|
|
33
|
+
// 顶部导航栏右侧自定义组件
|
|
34
|
+
extraNavRight?: React.ComponentType;
|
|
35
|
+
// 底部导航栏左侧自定义组件
|
|
36
|
+
extraNavLeft?: React.ComponentType;
|
|
37
|
+
navs: INav[];
|
|
38
|
+
announcement?: {
|
|
7
39
|
title: string;
|
|
8
|
-
|
|
9
|
-
github: string;
|
|
10
|
-
// 键盘搜索的快捷键,参考 https://github.com/madrobby/keymaster
|
|
11
|
-
searchHotKey?: string | { macos: string; windows: string };
|
|
12
|
-
logo: string | React.ComponentType;
|
|
13
|
-
// 在设置文件中声明该项目的国际化功能支持的语言
|
|
14
|
-
i18n?: { locale: string; text: string }[];
|
|
15
|
-
// 插件会从 docs/locales 内将所有 json 文件注入到 themeConfig 中
|
|
16
|
-
// 供 useLanguage 使用
|
|
17
|
-
locales: { [locale: string]: { [key: string]: string } };
|
|
18
|
-
// 顶部导航栏右侧自定义组件
|
|
19
|
-
extraNavRight?: React.ComponentType;
|
|
20
|
-
// 底部导航栏左侧自定义组件
|
|
21
|
-
extraNavLeft?: React.ComponentType;
|
|
22
|
-
navs: {
|
|
23
|
-
path: string;
|
|
24
|
-
title: string;
|
|
25
|
-
type: 'nav' | 'link';
|
|
26
|
-
dropdown?: { title: string; path: string }[];
|
|
27
|
-
children: any[];
|
|
28
|
-
}[];
|
|
29
|
-
announcement?: {
|
|
30
|
-
title: string;
|
|
31
|
-
link?: string;
|
|
32
|
-
};
|
|
33
|
-
themeSwitch?: {};
|
|
40
|
+
link?: string;
|
|
34
41
|
};
|
|
42
|
+
themeSwitch?: {};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface IContext {
|
|
46
|
+
appData: any;
|
|
47
|
+
components: any;
|
|
48
|
+
themeConfig: IThemeConfig;
|
|
35
49
|
location: {
|
|
36
50
|
pathname: string;
|
|
37
51
|
search: string;
|
package/dist/compiler.js
CHANGED
|
@@ -16,7 +16,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
}
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
20
23
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
24
|
|
|
22
25
|
// src/compiler.ts
|
|
@@ -57,14 +60,16 @@ async function compile(opts) {
|
|
|
57
60
|
});
|
|
58
61
|
try {
|
|
59
62
|
let result = String(await compiler.process(opts.content));
|
|
60
|
-
result = result.replace(
|
|
63
|
+
result = result.replace(
|
|
64
|
+
"function MDXContent(props = {}) {",
|
|
65
|
+
`
|
|
61
66
|
import { useEffect } from 'react';
|
|
62
67
|
|
|
63
68
|
function MDXContent(props = {}) {
|
|
64
69
|
|
|
65
70
|
useEffect(() => {
|
|
66
71
|
if (window.location.hash.length !== 0) {
|
|
67
|
-
//
|
|
72
|
+
// 为了右侧内容区能正常跳转
|
|
68
73
|
const hash = decodeURIComponent(window.location.hash);
|
|
69
74
|
setTimeout(() => {
|
|
70
75
|
document.getElementById(hash.slice(1))?.scrollIntoView();
|
|
@@ -78,12 +83,15 @@ function MDXContent(props = {}) {
|
|
|
78
83
|
});
|
|
79
84
|
}, []);
|
|
80
85
|
|
|
81
|
-
`
|
|
86
|
+
`
|
|
87
|
+
);
|
|
82
88
|
return { result };
|
|
83
89
|
} catch (e) {
|
|
84
90
|
import_plugin_utils.logger.error(e.reason);
|
|
85
91
|
import_plugin_utils.logger.error(`Above error occurred in ${opts.fileName} at line ${e.line}`);
|
|
86
|
-
import_plugin_utils.logger.error(
|
|
92
|
+
import_plugin_utils.logger.error(
|
|
93
|
+
opts.content.split("\n").filter((_, i) => i == e.line - 1).join("\n")
|
|
94
|
+
);
|
|
87
95
|
import_plugin_utils.logger.error(" ".repeat(e.column - 1) + "^");
|
|
88
96
|
if (process.env.NODE_ENV === "production") {
|
|
89
97
|
throw new Error("compile error", { cause: e });
|
package/dist/index.js
CHANGED
|
@@ -16,7 +16,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
}
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
20
23
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
24
|
|
|
22
25
|
// src/index.ts
|
|
@@ -82,7 +85,10 @@ var src_default = (api) => {
|
|
|
82
85
|
for (const route in r) {
|
|
83
86
|
if (r[route].path.match(/^[a-z]{2}-[A-Z]{2}\/.*/))
|
|
84
87
|
continue;
|
|
85
|
-
const defaultLangFile = r[route].file.replace(
|
|
88
|
+
const defaultLangFile = r[route].file.replace(
|
|
89
|
+
/(.[a-z]{2}-[A-Z]{2})?.md$/,
|
|
90
|
+
""
|
|
91
|
+
);
|
|
86
92
|
Object.keys(locales).map((l) => {
|
|
87
93
|
if (r[defaultLangFile] && !r[defaultLangFile + "." + l]) {
|
|
88
94
|
r[defaultLangFile + "." + l] = {
|
|
@@ -111,7 +117,9 @@ var src_default = (api) => {
|
|
|
111
117
|
api.writeTmpFile({
|
|
112
118
|
path: "index.ts",
|
|
113
119
|
content: `
|
|
114
|
-
export { ${exports.filter((item) => !item.startsWith("$")).join(", ")} } from '${(0, import_utils.winPath)(
|
|
120
|
+
export { ${exports.filter((item) => !item.startsWith("$")).join(", ")} } from '${(0, import_utils.winPath)(
|
|
121
|
+
require.resolve("../client/theme-doc/index.ts")
|
|
122
|
+
)}';
|
|
115
123
|
`
|
|
116
124
|
});
|
|
117
125
|
api.writeTmpFile({
|
|
@@ -119,7 +127,9 @@ export { ${exports.filter((item) => !item.startsWith("$")).join(", ")} } from '$
|
|
|
119
127
|
content: `
|
|
120
128
|
import React from 'react';
|
|
121
129
|
import { useOutlet, useAppData, useLocation, Link, history } from 'umi';
|
|
122
|
-
import { $Layout as Layout } from '${(0, import_utils.winPath)(
|
|
130
|
+
import { $Layout as Layout } from '${(0, import_utils.winPath)(
|
|
131
|
+
require.resolve("../client/theme-doc/index.ts")
|
|
132
|
+
)}';
|
|
123
133
|
${themeExists ? `import themeConfig from '${themeConfigPath}'` : `const themeConfig = {}`}
|
|
124
134
|
|
|
125
135
|
${injectLocale}
|
|
@@ -150,7 +160,11 @@ export default () => {
|
|
|
150
160
|
});
|
|
151
161
|
};
|
|
152
162
|
function withTmpPath(opts) {
|
|
153
|
-
return (0, import_path.join)(
|
|
163
|
+
return (0, import_path.join)(
|
|
164
|
+
opts.api.paths.absTmpPath,
|
|
165
|
+
opts.api.plugin.key && !opts.noPluginDir ? `plugin-${opts.api.plugin.key}` : "",
|
|
166
|
+
opts.path
|
|
167
|
+
);
|
|
154
168
|
}
|
|
155
169
|
// Annotate the CommonJS export names for ESM import in node:
|
|
156
170
|
0 && (module.exports = {});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/plugin-docs",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.48",
|
|
4
4
|
"description": "@umijs/plugin-docs",
|
|
5
5
|
"homepage": "https://github.com/umijs/umi/tree/master/packages/plugin-docs#readme",
|
|
6
6
|
"bugs": "https://github.com/umijs/umi/issues",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"rehype-slug": "5.0.1",
|
|
44
44
|
"remark-gfm": "^3.0.1",
|
|
45
45
|
"tailwindcss": "^3.2.4",
|
|
46
|
-
"umi": "4.0.
|
|
46
|
+
"umi": "4.0.48"
|
|
47
47
|
},
|
|
48
48
|
"publishConfig": {
|
|
49
49
|
"access": "public"
|