@umijs/plugin-docs 4.0.7 → 4.0.8
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/tailwind.out.css +4 -0
- 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 +6 -4
- 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>
|
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 = {});
|
package/dist/loader.js
CHANGED
|
@@ -1,22 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// loader.ts
|
|
20
|
+
var loader_exports = {};
|
|
21
|
+
__export(loader_exports, {
|
|
22
|
+
default: () => loader_default
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(loader_exports);
|
|
25
|
+
var import_compiler = require("./compiler");
|
|
26
|
+
async function loader_default(content) {
|
|
27
|
+
const filename = this.resourcePath;
|
|
28
|
+
const callback = this.async();
|
|
29
|
+
try {
|
|
30
|
+
const { result } = await (0, import_compiler.compile)({
|
|
31
|
+
content,
|
|
32
|
+
fileName: filename
|
|
33
|
+
});
|
|
34
|
+
return callback(null, result);
|
|
35
|
+
} catch (e) {
|
|
36
|
+
const err = e;
|
|
37
|
+
e.message = `${filename}: ${e.message}`;
|
|
38
|
+
throw err;
|
|
39
|
+
}
|
|
21
40
|
}
|
|
22
|
-
|
|
41
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
42
|
+
0 && (module.exports = {});
|
package/dist/markdown.js
CHANGED
|
@@ -1,23 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// markdown.ts
|
|
20
|
+
var markdown_exports = {};
|
|
21
|
+
__export(markdown_exports, {
|
|
22
|
+
parseTitle: () => parseTitle
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(markdown_exports);
|
|
4
25
|
function parseTitle(opts) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
title: match[2],
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
i += 1;
|
|
26
|
+
const lines = opts.content.replace(/{[\n\s\t]*\/\*[\s\S]*?\*\/[\n\s\t]*}/g, "").split("\n");
|
|
27
|
+
let i = 0;
|
|
28
|
+
const ret = [];
|
|
29
|
+
while (i < lines.length) {
|
|
30
|
+
const line = lines[i].trim();
|
|
31
|
+
const match = line.match(/^(#+)\s+(.*)/);
|
|
32
|
+
if (match) {
|
|
33
|
+
ret.push({
|
|
34
|
+
level: match[1].length,
|
|
35
|
+
title: match[2]
|
|
36
|
+
});
|
|
20
37
|
}
|
|
21
|
-
|
|
38
|
+
i += 1;
|
|
39
|
+
}
|
|
40
|
+
return ret;
|
|
22
41
|
}
|
|
23
|
-
|
|
42
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
43
|
+
0 && (module.exports = {
|
|
44
|
+
parseTitle
|
|
45
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/plugin-docs",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.8",
|
|
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",
|
|
@@ -17,15 +17,16 @@
|
|
|
17
17
|
"compiled"
|
|
18
18
|
],
|
|
19
19
|
"scripts": {
|
|
20
|
-
"build": "pnpm
|
|
20
|
+
"build": "pnpm father build",
|
|
21
21
|
"build:css": "tailwindcss -i ./client/theme-doc/tailwind.css -o ./client/theme-doc/tailwind.out.css",
|
|
22
22
|
"build:deps": "umi-scripts bundleDeps",
|
|
23
23
|
"build:extra": "pnpm build:css",
|
|
24
|
-
"dev": "pnpm
|
|
24
|
+
"dev": "pnpm father dev",
|
|
25
25
|
"dev:css": "pnpm build:css --watch",
|
|
26
26
|
"test": "umi-scripts jest-turbo"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
+
"github-slugger": "^1.4.0",
|
|
29
30
|
"keymaster": "1.6.2",
|
|
30
31
|
"react-helmet": "^6.1.0",
|
|
31
32
|
"rehype-pretty-code": "^0.3.1",
|
|
@@ -33,6 +34,7 @@
|
|
|
33
34
|
},
|
|
34
35
|
"devDependencies": {
|
|
35
36
|
"@mdx-js/mdx": "2.1.1",
|
|
37
|
+
"@types/github-slugger": "^1.3.0",
|
|
36
38
|
"@types/keymaster": "^1.6.30",
|
|
37
39
|
"@types/react-helmet": "^6.1.5",
|
|
38
40
|
"classnames": "^2.3.1",
|
|
@@ -40,7 +42,7 @@
|
|
|
40
42
|
"rehype-slug": "5.0.1",
|
|
41
43
|
"remark-gfm": "^3.0.1",
|
|
42
44
|
"tailwindcss": "^3.0.24",
|
|
43
|
-
"umi": "4.0.
|
|
45
|
+
"umi": "4.0.8"
|
|
44
46
|
},
|
|
45
47
|
"publishConfig": {
|
|
46
48
|
"access": "public"
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export default function getLinkFromTitle(title: string) {
|
|
2
|
-
return (
|
|
3
|
-
title
|
|
4
|
-
.toLowerCase()
|
|
5
|
-
.trim()
|
|
6
|
-
// not remove html tags
|
|
7
|
-
// .replace(/<[!\/a-z].*?>/gi, '')
|
|
8
|
-
// remove unwanted chars
|
|
9
|
-
.replace(
|
|
10
|
-
/[\u2000-\u206F\u2E00-\u2E7F\\'!!"#$%&()()*+,,.。/::;;<=>??@[\]^`{|}~]/g,
|
|
11
|
-
'',
|
|
12
|
-
)
|
|
13
|
-
.replace(/\s/g, '-')
|
|
14
|
-
);
|
|
15
|
-
}
|