@umijs/plugin-docs 4.0.0-canary.20220425.2 → 4.0.0-canary.20220428.1
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 +37 -20
- package/client/theme-doc/Sidebar.tsx +1 -0
- package/client/theme-doc/Toc.tsx +11 -14
- package/client/theme-doc/components/Features.tsx +1 -1
- package/client/theme-doc/tailwind.css +3 -1
- package/client/theme-doc/tailwind.out.css +58 -6
- package/client/theme-doc/utils/getLinkFromTitle.ts +15 -0
- package/client/theme-doc/utils/getTocTitle.ts +9 -0
- package/dist/compiler.js +4 -0
- package/package.json +2 -2
|
@@ -3,9 +3,11 @@ import key from 'keymaster';
|
|
|
3
3
|
import React, { Fragment, useEffect, useState } from 'react';
|
|
4
4
|
import { useThemeContext } from './context';
|
|
5
5
|
import useLanguage from './useLanguage';
|
|
6
|
+
import getLinkFromTitle from './utils/getLinkFromTitle';
|
|
6
7
|
|
|
7
8
|
export default () => {
|
|
8
|
-
const {
|
|
9
|
+
const { components } = useThemeContext()!;
|
|
10
|
+
const { isFromPath, currentLanguage, render } = useLanguage();
|
|
9
11
|
const [isFocused, setIsFocused] = useState(false);
|
|
10
12
|
const [keyword, setKeyword] = useState('');
|
|
11
13
|
|
|
@@ -34,6 +36,7 @@ export default () => {
|
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
useEffect(() => {
|
|
39
|
+
if (!themeConfig.searchHotKey) return;
|
|
37
40
|
key.filter = () => true;
|
|
38
41
|
|
|
39
42
|
// 在页面中按下 ⌘+k 可以打开搜索框
|
|
@@ -73,17 +76,20 @@ export default () => {
|
|
|
73
76
|
onFocus={() => setIsFocused(true)}
|
|
74
77
|
onBlur={() => setIsFocused(false)}
|
|
75
78
|
value={keyword}
|
|
79
|
+
autoComplete="off"
|
|
76
80
|
onChange={(e) => setKeyword(e.target.value)}
|
|
77
81
|
id="search-input"
|
|
78
82
|
className="w-full bg-transparent outline-none text-sm px-4 py-2"
|
|
79
83
|
placeholder={render('Search anything ...')}
|
|
80
84
|
/>
|
|
81
|
-
|
|
82
|
-
|
|
85
|
+
{themeConfig.searchHotKey && (
|
|
86
|
+
<div
|
|
87
|
+
className="bg-gray-200 rounded px-2 h-6 flex flex-row text-gray-400
|
|
83
88
|
items-center justify-center border border-gray-300 text-xs"
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
89
|
+
>
|
|
90
|
+
{isMac ? macSearchKey : windowsSearchKey}
|
|
91
|
+
</div>
|
|
92
|
+
)}
|
|
87
93
|
<div
|
|
88
94
|
id="search-results-wrapper"
|
|
89
95
|
className={cx(
|
|
@@ -93,8 +99,8 @@ export default () => {
|
|
|
93
99
|
)}
|
|
94
100
|
>
|
|
95
101
|
{result.map((r, i) => (
|
|
96
|
-
<
|
|
97
|
-
|
|
102
|
+
<components.Link
|
|
103
|
+
to={(isFromPath ? currentLanguage?.locale : '') + r.href}
|
|
98
104
|
key={i}
|
|
99
105
|
className="group outline-none search-result"
|
|
100
106
|
onFocus={() => setIsFocused(true)}
|
|
@@ -106,7 +112,7 @@ export default () => {
|
|
|
106
112
|
>
|
|
107
113
|
{r.path}
|
|
108
114
|
</p>
|
|
109
|
-
</
|
|
115
|
+
</components.Link>
|
|
110
116
|
))}
|
|
111
117
|
</div>
|
|
112
118
|
</div>
|
|
@@ -124,9 +130,15 @@ function search(routes: any, keyword: string): SearchResultItem[] {
|
|
|
124
130
|
|
|
125
131
|
const result: SearchResultItem[] = [];
|
|
126
132
|
|
|
133
|
+
function addResult(newResult: { path: string; href: string }) {
|
|
134
|
+
const { path, href } = newResult;
|
|
135
|
+
if (result.find((r) => r.path === path)) return;
|
|
136
|
+
result.push({ path, href });
|
|
137
|
+
}
|
|
138
|
+
|
|
127
139
|
Object.keys(routes).map((path) => {
|
|
128
140
|
if (path.toLowerCase().includes(keyword.toLowerCase())) {
|
|
129
|
-
|
|
141
|
+
addResult({
|
|
130
142
|
path: path.split('/').slice(1).join(' > '),
|
|
131
143
|
href: '/' + path,
|
|
132
144
|
});
|
|
@@ -134,16 +146,21 @@ function search(routes: any, keyword: string): SearchResultItem[] {
|
|
|
134
146
|
|
|
135
147
|
const route = routes[path];
|
|
136
148
|
if (!route.titles) return;
|
|
137
|
-
route.titles
|
|
138
|
-
.
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
149
|
+
route.titles.map((title: any) => {
|
|
150
|
+
if (title.title.toLowerCase().includes(keyword.toLowerCase())) {
|
|
151
|
+
addResult({
|
|
152
|
+
path:
|
|
153
|
+
path
|
|
154
|
+
.split('/')
|
|
155
|
+
.map((s) => s.replace(/\.[a-z]{2}-[A-Z]{2}\/?/g, ''))
|
|
156
|
+
.slice(1)
|
|
157
|
+
.join(' > ') +
|
|
158
|
+
' > ' +
|
|
159
|
+
title.title,
|
|
160
|
+
href: '/' + path + '#' + getLinkFromTitle(title.title),
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
});
|
|
147
164
|
});
|
|
148
165
|
|
|
149
166
|
if (result.length > 8) return result.slice(0, 8);
|
package/client/theme-doc/Toc.tsx
CHANGED
|
@@ -2,13 +2,8 @@ import React from 'react';
|
|
|
2
2
|
import { Helmet } from 'react-helmet';
|
|
3
3
|
import { useThemeContext } from './context';
|
|
4
4
|
import useLanguage from './useLanguage';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return title
|
|
8
|
-
.toLowerCase()
|
|
9
|
-
.replace(/\s/g, '-')
|
|
10
|
-
.replace(/[()()\\{},]/g, '');
|
|
11
|
-
}
|
|
5
|
+
import getLinkFromTitle from './utils/getLinkFromTitle';
|
|
6
|
+
import getTocTitle from './utils/getTocTitle';
|
|
12
7
|
|
|
13
8
|
export default () => {
|
|
14
9
|
const { location, appData, themeConfig } = useThemeContext()!;
|
|
@@ -30,7 +25,7 @@ export default () => {
|
|
|
30
25
|
return (
|
|
31
26
|
<div
|
|
32
27
|
className="w-full lg:m-12 mb-12 border
|
|
33
|
-
border-gray-
|
|
28
|
+
border-gray-200 dark:border-neutral-700 py-4 rounded-lg z-20"
|
|
34
29
|
>
|
|
35
30
|
{/* @ts-ignore */}
|
|
36
31
|
<Helmet>
|
|
@@ -38,22 +33,24 @@ export default () => {
|
|
|
38
33
|
{route.titles[0].title} | {themeConfig.title}
|
|
39
34
|
</title>
|
|
40
35
|
</Helmet>
|
|
41
|
-
<p className="text-lg font-extrabold dark:text-
|
|
42
|
-
{route.titles[0].title}
|
|
36
|
+
<p className="text-lg font-extrabold text-gray-800 dark:text-neutral-50 pb-2 border-b border-gray-200 dark:border-neutral-700">
|
|
37
|
+
<span className="px-4">{route.titles[0].title}</span>
|
|
43
38
|
</p>
|
|
44
|
-
<ul className="max-h-[calc(100vh-360px)] overflow-y-auto
|
|
39
|
+
<ul className="max-h-[calc(100vh-360px)] overflow-y-auto px-4">
|
|
45
40
|
{titles.map((item: any) => {
|
|
46
41
|
return (
|
|
47
42
|
<li
|
|
48
43
|
style={{ paddingLeft: `${item.level - 2}rem` }}
|
|
49
|
-
className="mt-3 text-gray-600 cursor-pointer dark:text-
|
|
44
|
+
className="mt-3 text-gray-600 cursor-pointer dark:text-neutral-400
|
|
50
45
|
hover:text-blue-500 transition duration-300 dark:hover:text-blue-500"
|
|
51
46
|
>
|
|
52
47
|
<a
|
|
53
|
-
className={
|
|
48
|
+
className={`${
|
|
49
|
+
item.level > 2 ? 'text-sm' : 'text-base'
|
|
50
|
+
} break-all 2xl:break-words`}
|
|
54
51
|
href={'#' + getLinkFromTitle(item.title)}
|
|
55
52
|
>
|
|
56
|
-
{item.title
|
|
53
|
+
{getTocTitle(item.title)}
|
|
57
54
|
</a>
|
|
58
55
|
</li>
|
|
59
56
|
);
|
|
@@ -8,7 +8,7 @@ function Features(
|
|
|
8
8
|
props: PropsWithChildren<{ title?: string; subtitle?: string }>,
|
|
9
9
|
) {
|
|
10
10
|
return (
|
|
11
|
-
<div className="w-
|
|
11
|
+
<div className="w-full py-36 features dark:features-dark min-h-screen">
|
|
12
12
|
{(props.title || props.subtitle) && (
|
|
13
13
|
<div className="mb-24 px-4">
|
|
14
14
|
{props.title && (
|
|
@@ -78,7 +78,9 @@ article div[data-rehype-pretty-code-fragment] {
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
/* 代码块的标题部分 */
|
|
81
|
-
article
|
|
81
|
+
article
|
|
82
|
+
div[data-rehype-pretty-code-fragment]
|
|
83
|
+
> div[data-rehype-pretty-code-title] {
|
|
82
84
|
@apply pb-1 text-sm text-zinc-400 dark:text-neutral-400 text-center;
|
|
83
85
|
}
|
|
84
86
|
|
|
@@ -1046,6 +1046,10 @@ Ensure the default browser behavior of the `hidden` attribute.
|
|
|
1046
1046
|
overflow-y: scroll;
|
|
1047
1047
|
}
|
|
1048
1048
|
|
|
1049
|
+
.break-all {
|
|
1050
|
+
word-break: break-all;
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1049
1053
|
.rounded-lg {
|
|
1050
1054
|
border-radius: 0.5rem;
|
|
1051
1055
|
}
|
|
@@ -1070,6 +1074,10 @@ Ensure the default browser behavior of the `hidden` attribute.
|
|
|
1070
1074
|
border-bottom-width: 2px;
|
|
1071
1075
|
}
|
|
1072
1076
|
|
|
1077
|
+
.border-b {
|
|
1078
|
+
border-bottom-width: 1px;
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1073
1081
|
.border-white {
|
|
1074
1082
|
--tw-border-opacity: 1;
|
|
1075
1083
|
border-color: rgb(255 255 255 / var(--tw-border-opacity));
|
|
@@ -1080,9 +1088,9 @@ Ensure the default browser behavior of the `hidden` attribute.
|
|
|
1080
1088
|
border-color: rgb(209 213 219 / var(--tw-border-opacity));
|
|
1081
1089
|
}
|
|
1082
1090
|
|
|
1083
|
-
.border-gray-
|
|
1091
|
+
.border-gray-200 {
|
|
1084
1092
|
--tw-border-opacity: 1;
|
|
1085
|
-
border-color: rgb(
|
|
1093
|
+
border-color: rgb(229 231 235 / var(--tw-border-opacity));
|
|
1086
1094
|
}
|
|
1087
1095
|
|
|
1088
1096
|
.border-b-gray-100 {
|
|
@@ -1186,6 +1194,11 @@ Ensure the default browser behavior of the `hidden` attribute.
|
|
|
1186
1194
|
padding-right: 0.25rem;
|
|
1187
1195
|
}
|
|
1188
1196
|
|
|
1197
|
+
.py-4 {
|
|
1198
|
+
padding-top: 1rem;
|
|
1199
|
+
padding-bottom: 1rem;
|
|
1200
|
+
}
|
|
1201
|
+
|
|
1189
1202
|
.py-12 {
|
|
1190
1203
|
padding-top: 3rem;
|
|
1191
1204
|
padding-bottom: 3rem;
|
|
@@ -1230,6 +1243,10 @@ Ensure the default browser behavior of the `hidden` attribute.
|
|
|
1230
1243
|
padding-bottom: 9rem;
|
|
1231
1244
|
}
|
|
1232
1245
|
|
|
1246
|
+
.pb-2 {
|
|
1247
|
+
padding-bottom: 0.5rem;
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1233
1250
|
.pb-12 {
|
|
1234
1251
|
padding-bottom: 3rem;
|
|
1235
1252
|
}
|
|
@@ -1258,6 +1275,11 @@ Ensure the default browser behavior of the `hidden` attribute.
|
|
|
1258
1275
|
line-height: 1.75rem;
|
|
1259
1276
|
}
|
|
1260
1277
|
|
|
1278
|
+
.text-base {
|
|
1279
|
+
font-size: 1rem;
|
|
1280
|
+
line-height: 1.5rem;
|
|
1281
|
+
}
|
|
1282
|
+
|
|
1261
1283
|
.text-3xl {
|
|
1262
1284
|
font-size: 1.875rem;
|
|
1263
1285
|
line-height: 2.25rem;
|
|
@@ -1296,6 +1318,11 @@ Ensure the default browser behavior of the `hidden` attribute.
|
|
|
1296
1318
|
color: rgb(55 65 81 / var(--tw-text-opacity));
|
|
1297
1319
|
}
|
|
1298
1320
|
|
|
1321
|
+
.text-gray-800 {
|
|
1322
|
+
--tw-text-opacity: 1;
|
|
1323
|
+
color: rgb(31 41 55 / var(--tw-text-opacity));
|
|
1324
|
+
}
|
|
1325
|
+
|
|
1299
1326
|
.text-gray-600 {
|
|
1300
1327
|
--tw-text-opacity: 1;
|
|
1301
1328
|
color: rgb(75 85 99 / var(--tw-text-opacity));
|
|
@@ -1678,7 +1705,9 @@ article div[data-rehype-pretty-code-fragment] {
|
|
|
1678
1705
|
|
|
1679
1706
|
/* 代码块的标题部分 */
|
|
1680
1707
|
|
|
1681
|
-
article
|
|
1708
|
+
article
|
|
1709
|
+
div[data-rehype-pretty-code-fragment]
|
|
1710
|
+
> div[data-rehype-pretty-code-title] {
|
|
1682
1711
|
padding-bottom: 0.25rem;
|
|
1683
1712
|
text-align: center;
|
|
1684
1713
|
font-size: 0.875rem;
|
|
@@ -1687,7 +1716,9 @@ article div[data-rehype-pretty-code-fragment] > div[data-rehype-pretty-code-titl
|
|
|
1687
1716
|
color: rgb(161 161 170 / var(--tw-text-opacity));
|
|
1688
1717
|
}
|
|
1689
1718
|
|
|
1690
|
-
.dark article
|
|
1719
|
+
.dark article
|
|
1720
|
+
div[data-rehype-pretty-code-fragment]
|
|
1721
|
+
> div[data-rehype-pretty-code-title] {
|
|
1691
1722
|
--tw-text-opacity: 1;
|
|
1692
1723
|
color: rgb(163 163 163 / var(--tw-text-opacity));
|
|
1693
1724
|
}
|
|
@@ -2132,6 +2163,11 @@ h6 {
|
|
|
2132
2163
|
border-color: rgb(55 65 81 / var(--tw-border-opacity));
|
|
2133
2164
|
}
|
|
2134
2165
|
|
|
2166
|
+
.dark .dark\:border-neutral-700 {
|
|
2167
|
+
--tw-border-opacity: 1;
|
|
2168
|
+
border-color: rgb(64 64 64 / var(--tw-border-opacity));
|
|
2169
|
+
}
|
|
2170
|
+
|
|
2135
2171
|
.dark .dark\:border-gray-500 {
|
|
2136
2172
|
--tw-border-opacity: 1;
|
|
2137
2173
|
border-color: rgb(107 114 128 / var(--tw-border-opacity));
|
|
@@ -2182,9 +2218,14 @@ h6 {
|
|
|
2182
2218
|
color: rgb(191 219 254 / var(--tw-text-opacity));
|
|
2183
2219
|
}
|
|
2184
2220
|
|
|
2185
|
-
.dark .dark\:text-
|
|
2221
|
+
.dark .dark\:text-neutral-50 {
|
|
2186
2222
|
--tw-text-opacity: 1;
|
|
2187
|
-
color: rgb(
|
|
2223
|
+
color: rgb(250 250 250 / var(--tw-text-opacity));
|
|
2224
|
+
}
|
|
2225
|
+
|
|
2226
|
+
.dark .dark\:text-neutral-400 {
|
|
2227
|
+
--tw-text-opacity: 1;
|
|
2228
|
+
color: rgb(163 163 163 / var(--tw-text-opacity));
|
|
2188
2229
|
}
|
|
2189
2230
|
|
|
2190
2231
|
.dark .dark\:text-gray-200 {
|
|
@@ -2192,6 +2233,11 @@ h6 {
|
|
|
2192
2233
|
color: rgb(229 231 235 / var(--tw-text-opacity));
|
|
2193
2234
|
}
|
|
2194
2235
|
|
|
2236
|
+
.dark .dark\:text-gray-400 {
|
|
2237
|
+
--tw-text-opacity: 1;
|
|
2238
|
+
color: rgb(156 163 175 / var(--tw-text-opacity));
|
|
2239
|
+
}
|
|
2240
|
+
|
|
2195
2241
|
.dark .dark\:text-gray-300 {
|
|
2196
2242
|
--tw-text-opacity: 1;
|
|
2197
2243
|
color: rgb(209 213 219 / var(--tw-text-opacity));
|
|
@@ -2355,3 +2401,9 @@ h6 {
|
|
|
2355
2401
|
padding-right: 16rem;
|
|
2356
2402
|
}
|
|
2357
2403
|
}
|
|
2404
|
+
|
|
2405
|
+
@media (min-width: 1536px) {
|
|
2406
|
+
.\32xl\:break-words {
|
|
2407
|
+
overflow-wrap: break-word;
|
|
2408
|
+
}
|
|
2409
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
}
|
package/dist/compiler.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/plugin-docs",
|
|
3
|
-
"version": "4.0.0-canary.
|
|
3
|
+
"version": "4.0.0-canary.20220428.1",
|
|
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",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"rehype-slug": "5.0.1",
|
|
40
40
|
"remark-gfm": "^3.0.1",
|
|
41
41
|
"tailwindcss": "^3.0.23",
|
|
42
|
-
"umi": "4.0.0-canary.
|
|
42
|
+
"umi": "4.0.0-canary.20220428.1"
|
|
43
43
|
},
|
|
44
44
|
"publishConfig": {
|
|
45
45
|
"access": "public"
|