@umijs/plugin-docs 4.0.0-rc.1 → 4.0.0-rc.4
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-blog/index.ts +1 -0
- package/client/theme-doc/LangSwitch.tsx +1 -1
- package/client/theme-doc/Layout.tsx +46 -5
- package/client/theme-doc/Logo.tsx +7 -3
- package/client/theme-doc/ThemeSwitch.tsx +2 -2
- package/client/theme-doc/Toc.tsx +8 -2
- package/client/theme-doc/components/Announcement.tsx +7 -0
- package/client/theme-doc/components/FeatureItem.tsx +48 -0
- package/client/theme-doc/components/Features.tsx +44 -0
- package/client/theme-doc/components/Hero.tsx +10 -7
- package/client/theme-doc/components/Message.tsx +22 -16
- package/client/theme-doc/context.ts +1 -0
- package/client/theme-doc/firefox-polyfill.css +32 -0
- package/client/theme-doc/index.ts +4 -1
- package/client/theme-doc/tailwind.css +89 -5
- package/client/theme-doc/tailwind.out.css +333 -57
- package/client/theme-doc/useLanguage.ts +5 -3
- package/dist/compiler.d.ts +1 -1
- package/dist/compiler.js +13 -13
- package/dist/index.js +54 -18
- package/package.json +20 -7
package/dist/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -19,10 +23,26 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
19
23
|
return result;
|
|
20
24
|
};
|
|
21
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const bundler_utils_1 = require("@umijs/bundler-utils");
|
|
27
|
+
const utils_1 = require("@umijs/utils");
|
|
22
28
|
const fs_1 = __importStar(require("fs"));
|
|
23
29
|
const path_1 = require("path");
|
|
24
30
|
const markdown_1 = require("./markdown");
|
|
25
31
|
exports.default = (api) => {
|
|
32
|
+
// 把用户当前有设置在 docs/locales 下的语系放到变量 locales 中,方便后续使用
|
|
33
|
+
const locales = {};
|
|
34
|
+
const localesPath = (0, path_1.join)(api.cwd, 'docs/locales');
|
|
35
|
+
if ((0, fs_1.existsSync)(localesPath)) {
|
|
36
|
+
fs_1.default.readdirSync(localesPath).forEach((file) => {
|
|
37
|
+
if (file.endsWith('.json')) {
|
|
38
|
+
const filePath = (0, path_1.join)(localesPath, file);
|
|
39
|
+
const content = fs_1.default.readFileSync(filePath).toString();
|
|
40
|
+
const json = JSON.parse(content);
|
|
41
|
+
const localeName = file.replace('.json', '');
|
|
42
|
+
locales[localeName] = json;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
26
46
|
api.modifyDefaultConfig((memo) => {
|
|
27
47
|
memo.conventionRoutes = Object.assign(Object.assign({}, memo.conventionRoutes), { base: (0, path_1.join)(api.cwd, 'docs') });
|
|
28
48
|
memo.mdx = {
|
|
@@ -54,29 +74,45 @@ exports.default = (api) => {
|
|
|
54
74
|
}
|
|
55
75
|
}
|
|
56
76
|
});
|
|
77
|
+
// 检查路由是否存在其他语言,没有的话做 fallback 处理
|
|
78
|
+
api.modifyRoutes((r) => {
|
|
79
|
+
if (!locales)
|
|
80
|
+
return r;
|
|
81
|
+
for (const route in r) {
|
|
82
|
+
if (r[route].path.match(/^[a-z]{2}-[A-Z]{2}\/.*/))
|
|
83
|
+
continue;
|
|
84
|
+
const defaultLangFile = r[route].file.replace(/(.[a-z]{2}-[A-Z]{2})?.md$/, '');
|
|
85
|
+
Object.keys(locales).map((l) => {
|
|
86
|
+
if (r[defaultLangFile] && !r[defaultLangFile + '.' + l]) {
|
|
87
|
+
r[defaultLangFile + '.' + l] = Object.assign(Object.assign({}, r[defaultLangFile]), { path: `/${l}/${r[defaultLangFile].path}` });
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
return r;
|
|
92
|
+
});
|
|
57
93
|
api.onGenerateFiles(() => {
|
|
94
|
+
var _a;
|
|
95
|
+
// theme path
|
|
96
|
+
let theme = ((_a = api.config.docs) === null || _a === void 0 ? void 0 : _a.theme) || require.resolve('../client/theme-doc/index.ts');
|
|
97
|
+
if (theme === 'blog') {
|
|
98
|
+
theme = require.resolve('../client/theme-blog/index.ts');
|
|
99
|
+
}
|
|
100
|
+
theme = (0, utils_1.winPath)(theme);
|
|
58
101
|
const themeConfigPath = (0, path_1.join)(api.cwd, 'theme.config.ts');
|
|
59
102
|
const themeExists = (0, fs_1.existsSync)(themeConfigPath);
|
|
60
103
|
// 将 docs/locales 目录下的 json 文件注入到 themeConfig.locales 中
|
|
61
|
-
let injectLocale =
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
fs_1.
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const content = fs_1.default.readFileSync(filePath).toString();
|
|
68
|
-
const json = JSON.parse(content);
|
|
69
|
-
const localeName = file.replace('.json', '');
|
|
70
|
-
injectLocale += `themeConfig.locales['${localeName}'] = ${JSON.stringify(json)};
|
|
71
|
-
`;
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
// @TODO: 需要能够动态解析 theme 中导出的组件,现在是硬编码
|
|
104
|
+
let injectLocale = `themeConfig.locales = ${JSON.stringify(locales)};`;
|
|
105
|
+
// exports don't start with $ will be MDX Component
|
|
106
|
+
const [_, exports] = (0, bundler_utils_1.parseModuleSync)({
|
|
107
|
+
content: (0, fs_1.readFileSync)(theme, 'utf-8'),
|
|
108
|
+
path: theme,
|
|
109
|
+
});
|
|
76
110
|
api.writeTmpFile({
|
|
77
111
|
path: 'index.ts',
|
|
78
112
|
content: `
|
|
79
|
-
export {
|
|
113
|
+
export { ${exports
|
|
114
|
+
.filter((item) => !item.startsWith('$'))
|
|
115
|
+
.join(', ')} } from '${require.resolve('../client/theme-doc/index.ts')}';
|
|
80
116
|
`,
|
|
81
117
|
});
|
|
82
118
|
api.writeTmpFile({
|
|
@@ -84,7 +120,7 @@ export { Message, Hero } from '${require.resolve('../client/theme-doc')}';
|
|
|
84
120
|
content: `
|
|
85
121
|
import React from 'react';
|
|
86
122
|
import { useOutlet, useAppData, useLocation, Link } from 'umi';
|
|
87
|
-
import { Layout } from '${require.resolve('../client/theme-doc')}';
|
|
123
|
+
import { $Layout as Layout } from '${require.resolve('../client/theme-doc/index.ts')}';
|
|
88
124
|
${themeExists
|
|
89
125
|
? `import themeConfig from '${themeConfigPath}'`
|
|
90
126
|
: `const themeConfig = {}`}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/plugin-docs",
|
|
3
|
-
"version": "4.0.0-rc.
|
|
3
|
+
"version": "4.0.0-rc.4",
|
|
4
4
|
"description": "@umijs/plugin-docs",
|
|
5
5
|
"homepage": "https://github.com/umijs/umi-next/tree/master/packages/plugin-docs#readme",
|
|
6
6
|
"bugs": "https://github.com/umijs/umi-next/issues",
|
|
@@ -23,20 +23,33 @@
|
|
|
23
23
|
"dev": "pnpm build -- --watch"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"remark-slug": "6.1.0"
|
|
26
|
+
"keymaster": "1.6.2",
|
|
27
|
+
"react-helmet": "^6.1.0"
|
|
29
28
|
},
|
|
30
29
|
"devDependencies": {
|
|
30
|
+
"@mdx-js/mdx": "2.0.0",
|
|
31
31
|
"@types/keymaster": "^1.6.30",
|
|
32
|
+
"@types/react-helmet": "^6.1.5",
|
|
32
33
|
"classnames": "^2.3.1",
|
|
33
|
-
"
|
|
34
|
-
"
|
|
34
|
+
"rehype-slug": "5.0.1",
|
|
35
|
+
"tailwindcss": "^3.0.23",
|
|
36
|
+
"umi": "4.0.0-rc.4"
|
|
35
37
|
},
|
|
36
38
|
"publishConfig": {
|
|
37
39
|
"access": "public"
|
|
38
40
|
},
|
|
39
41
|
"authors": [
|
|
40
42
|
"chencheng <sorrycc@gmail.com> (https://github.com/sorrycc)"
|
|
41
|
-
]
|
|
43
|
+
],
|
|
44
|
+
"compiledConfig": {
|
|
45
|
+
"deps": [
|
|
46
|
+
"@mdx-js/mdx",
|
|
47
|
+
"rehype-slug"
|
|
48
|
+
],
|
|
49
|
+
"externals": {},
|
|
50
|
+
"excludeDtsDeps": [
|
|
51
|
+
"@mdx-js/mdx",
|
|
52
|
+
"rehype-slug"
|
|
53
|
+
]
|
|
54
|
+
}
|
|
42
55
|
}
|