@umijs/plugin-docs 4.0.0-rc.3 → 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.
@@ -25,7 +25,7 @@ export default () => {
25
25
  return (
26
26
  <div>
27
27
  <div
28
- className="w-24 rounded-lg overflow-hidden cursor-pointer border
28
+ className="w-24 rounded-lg overflow-hidden cursor-pointer border text-center
29
29
  border-white hover:border-gray-100 dark:border-gray-800"
30
30
  onClick={handleClick}
31
31
  >
@@ -31,6 +31,10 @@ export default (props: any) => {
31
31
 
32
32
  const { title, description } = props.themeConfig;
33
33
 
34
+ const isHomePage =
35
+ window.location.pathname === '/' ||
36
+ window.location.pathname.replace(/[a-z]{2}-[A-Z]{2}\/?/, '') === '/';
37
+
34
38
  return (
35
39
  <ThemeContext.Provider
36
40
  value={{
@@ -54,7 +58,7 @@ export default (props: any) => {
54
58
  <div className="g-glossy-firefox-cover" />
55
59
  <div className="g-glossy-firefox" id="firefox-head-bg" />
56
60
 
57
- {window.location.pathname === '/' ? (
61
+ {isHomePage ? (
58
62
  <div id="article-body">
59
63
  <Helmet>
60
64
  <title>
@@ -71,7 +75,7 @@ export default (props: any) => {
71
75
  className="w-full flex flex-row justify-center overflow-x-hidden"
72
76
  >
73
77
  <div className="container flex flex-row justify-center">
74
- <div className="w-full lg:w-1/2 px-4 lg:px-0 m-8 z-20 lg:py-12">
78
+ <div className="w-full lg:w-1/2 px-4 lg:px-2 m-8 z-20 lg:py-12">
75
79
  <article className="flex-1">{props.children}</article>
76
80
  </div>
77
81
  </div>
@@ -1,12 +1,16 @@
1
1
  import React from 'react';
2
2
  import { useThemeContext } from './context';
3
+ import useLanguage from './useLanguage';
3
4
 
4
5
  export default () => {
5
6
  const { themeConfig, components } = useThemeContext()!;
7
+ const { isFromPath, currentLanguage } = useLanguage();
8
+
6
9
  // @ts-ignore
7
10
  const { logo } = themeConfig;
11
+
8
12
  return (
9
- <components.Link to="/">
13
+ <components.Link to={isFromPath ? '/' + currentLanguage?.locale : '/'}>
10
14
  <div className="flex flex-row items-center">
11
15
  <img src={logo} className="w-8 h-8" alt="logo" />
12
16
  <div className="text-xl font-extrabold ml-2 dark:text-white">
@@ -36,9 +36,9 @@ export default () => {
36
36
  return (
37
37
  <div
38
38
  className={cx(
39
- 'md:w-12 md:h-6 w-12 h-4 flex items-center bg-gray-300 rounded-full ',
39
+ 'md:w-12 md:h-6 w-12 h-4 flex items-center rounded-full ',
40
40
  'py-1 px-1.5 cursor-pointer',
41
- toggle ? 'bg-blue-300' : 'bg-gray-700',
41
+ toggle ? 'bg-gray-100' : 'bg-gray-700',
42
42
  )}
43
43
  onClick={() => setToggle(!toggle)}
44
44
  >
@@ -40,7 +40,7 @@ export default () => {
40
40
  <p className="text-lg font-extrabold dark:text-white">
41
41
  {route.titles[0].title}
42
42
  </p>
43
- <ul className="max-h-[calc(100vh-360px)] overflow-y-scroll py-2">
43
+ <ul className="max-h-[calc(100vh-360px)] overflow-y-auto py-2">
44
44
  {titles.map((item: any) => {
45
45
  return (
46
46
  <li
@@ -13,22 +13,21 @@ interface MessageProps {
13
13
  }
14
14
 
15
15
  function Message(props: PropsWithChildren<MessageProps>) {
16
- let bgColor = 'bg-blue-50';
17
- let textColor = 'text-blue-900';
16
+ const messageType = props.type || 'info';
18
17
 
19
- switch (props.type) {
18
+ let messageClass: string;
19
+ switch (messageType) {
20
20
  case MessageType.Success:
21
- bgColor = 'bg-green-50';
22
- textColor = 'text-green-900';
21
+ messageClass = 'mdx-message-success';
23
22
  break;
24
23
  case MessageType.Warning:
25
- bgColor = 'bg-orange-50';
26
- textColor = 'text-orange-900';
24
+ messageClass = 'mdx-message-warning';
27
25
  break;
28
26
  case MessageType.Error:
29
- bgColor = 'bg-red-50';
30
- textColor = 'text-red-900';
27
+ messageClass = 'mdx-message-error';
31
28
  break;
29
+ default:
30
+ messageClass = 'mdx-message-info';
32
31
  }
33
32
 
34
33
  const messageText =
@@ -39,7 +38,7 @@ function Message(props: PropsWithChildren<MessageProps>) {
39
38
  return (
40
39
  <>
41
40
  <div
42
- className={`w-full py-3 px-4 ${bgColor} ${textColor} rounded-lg my-4 mdx-message`}
41
+ className={`w-full py-3 px-4 rounded-lg my-4 mdx-message ${messageClass}`}
43
42
  >
44
43
  <p>
45
44
  {props.emoji && (
@@ -3,7 +3,8 @@
3
3
  https://www.cnblogs.com/coco1s/p/14953143.html
4
4
  */
5
5
 
6
- .g-glossy-firefox, .g-glossy-firefox-cover {
6
+ .g-glossy-firefox,
7
+ .g-glossy-firefox-cover {
7
8
  display: none;
8
9
  }
9
10
 
@@ -84,12 +84,18 @@ article a code {
84
84
 
85
85
  article a {
86
86
  @apply text-blue-600 mx-1 hover:text-blue-300 transition dark:text-blue-400;
87
- background-image: linear-gradient(transparent 60%, rgba(130, 199, 255, 0.28) 55%);
87
+ background-image: linear-gradient(
88
+ transparent 60%,
89
+ rgba(130, 199, 255, 0.28) 55%
90
+ );
88
91
  }
89
92
 
90
93
  .link-with-underline {
91
94
  @apply text-blue-600 mx-1 hover:text-blue-300 transition dark:text-blue-400;
92
- background-image: linear-gradient(transparent 60%, rgba(130, 199, 255, 0.28) 55%);
95
+ background-image: linear-gradient(
96
+ transparent 60%,
97
+ rgba(130, 199, 255, 0.28) 55%
98
+ );
93
99
  }
94
100
 
95
101
  /*article pre {*/
@@ -111,7 +117,7 @@ article hr {
111
117
  }
112
118
 
113
119
  html {
114
- scroll-behavior: smooth
120
+ scroll-behavior: smooth;
115
121
  }
116
122
 
117
123
  :root {
@@ -119,12 +125,16 @@ html {
119
125
  }
120
126
 
121
127
  /** Anchor with offset for headings */
122
- h1, h2, h3, h4, h5, h6 {
128
+ h1,
129
+ h2,
130
+ h3,
131
+ h4,
132
+ h5,
133
+ h6 {
123
134
  scroll-margin-top: calc(var(--anchor-offset) + 88px);
124
135
  }
125
136
 
126
137
  @layer components {
127
-
128
138
  .features-dark {
129
139
  @apply bg-gray-900;
130
140
  background-image: radial-gradient(#2a2a2a 20%, transparent 20%);
@@ -147,7 +157,43 @@ h1, h2, h3, h4, h5, h6 {
147
157
  display: none;
148
158
  }
149
159
 
160
+ .mdx-message {
161
+ @apply border-l-8;
162
+ }
163
+
150
164
  .mdx-message > p {
151
165
  @apply mt-0;
152
166
  }
167
+
168
+ .mdx-message-info {
169
+ @apply bg-blue-50 border-blue-300 dark:bg-blue-100 dark:border-blue-500;
170
+ }
171
+
172
+ .mdx-message-info > p {
173
+ @apply text-blue-900 dark:text-blue-900;
174
+ }
175
+
176
+ .mdx-message-success {
177
+ @apply bg-green-50 border-green-300 dark:bg-green-100 dark:border-green-500;
178
+ }
179
+
180
+ .mdx-message-success > p {
181
+ @apply text-green-900 dark:text-green-900;
182
+ }
183
+
184
+ .mdx-message-warning {
185
+ @apply bg-orange-50 border-orange-300 dark:bg-orange-100 dark:border-orange-500;
186
+ }
187
+
188
+ .mdx-message-warning > p {
189
+ @apply text-orange-900 dark:text-orange-900;
190
+ }
191
+
192
+ .mdx-message-error {
193
+ @apply bg-red-50 border-red-300 dark:bg-red-100 dark:border-red-500;
194
+ }
195
+
196
+ .mdx-message-error > p {
197
+ @apply text-red-900 dark:text-red-900;
198
+ }
153
199
  }
@@ -515,10 +515,110 @@ Ensure the default browser behavior of the `hidden` attribute.
515
515
  display: none;
516
516
  }
517
517
 
518
+ .mdx-message {
519
+ border-left-width: 8px;
520
+ }
521
+
518
522
  .mdx-message > p {
519
523
  margin-top: 0px;
520
524
  }
521
525
 
526
+ .mdx-message-info {
527
+ --tw-border-opacity: 1;
528
+ border-color: rgb(147 197 253 / var(--tw-border-opacity));
529
+ --tw-bg-opacity: 1;
530
+ background-color: rgb(239 246 255 / var(--tw-bg-opacity));
531
+ }
532
+
533
+ .dark .mdx-message-info {
534
+ --tw-border-opacity: 1;
535
+ border-color: rgb(59 130 246 / var(--tw-border-opacity));
536
+ --tw-bg-opacity: 1;
537
+ background-color: rgb(219 234 254 / var(--tw-bg-opacity));
538
+ }
539
+
540
+ .mdx-message-info > p {
541
+ --tw-text-opacity: 1;
542
+ color: rgb(30 58 138 / var(--tw-text-opacity));
543
+ }
544
+
545
+ .dark .mdx-message-info > p {
546
+ --tw-text-opacity: 1;
547
+ color: rgb(30 58 138 / var(--tw-text-opacity));
548
+ }
549
+
550
+ .mdx-message-success {
551
+ --tw-border-opacity: 1;
552
+ border-color: rgb(134 239 172 / var(--tw-border-opacity));
553
+ --tw-bg-opacity: 1;
554
+ background-color: rgb(240 253 244 / var(--tw-bg-opacity));
555
+ }
556
+
557
+ .dark .mdx-message-success {
558
+ --tw-border-opacity: 1;
559
+ border-color: rgb(34 197 94 / var(--tw-border-opacity));
560
+ --tw-bg-opacity: 1;
561
+ background-color: rgb(220 252 231 / var(--tw-bg-opacity));
562
+ }
563
+
564
+ .mdx-message-success > p {
565
+ --tw-text-opacity: 1;
566
+ color: rgb(20 83 45 / var(--tw-text-opacity));
567
+ }
568
+
569
+ .dark .mdx-message-success > p {
570
+ --tw-text-opacity: 1;
571
+ color: rgb(20 83 45 / var(--tw-text-opacity));
572
+ }
573
+
574
+ .mdx-message-warning {
575
+ --tw-border-opacity: 1;
576
+ border-color: rgb(253 186 116 / var(--tw-border-opacity));
577
+ --tw-bg-opacity: 1;
578
+ background-color: rgb(255 247 237 / var(--tw-bg-opacity));
579
+ }
580
+
581
+ .dark .mdx-message-warning {
582
+ --tw-border-opacity: 1;
583
+ border-color: rgb(249 115 22 / var(--tw-border-opacity));
584
+ --tw-bg-opacity: 1;
585
+ background-color: rgb(255 237 213 / var(--tw-bg-opacity));
586
+ }
587
+
588
+ .mdx-message-warning > p {
589
+ --tw-text-opacity: 1;
590
+ color: rgb(124 45 18 / var(--tw-text-opacity));
591
+ }
592
+
593
+ .dark .mdx-message-warning > p {
594
+ --tw-text-opacity: 1;
595
+ color: rgb(124 45 18 / var(--tw-text-opacity));
596
+ }
597
+
598
+ .mdx-message-error {
599
+ --tw-border-opacity: 1;
600
+ border-color: rgb(252 165 165 / var(--tw-border-opacity));
601
+ --tw-bg-opacity: 1;
602
+ background-color: rgb(254 242 242 / var(--tw-bg-opacity));
603
+ }
604
+
605
+ .dark .mdx-message-error {
606
+ --tw-border-opacity: 1;
607
+ border-color: rgb(239 68 68 / var(--tw-border-opacity));
608
+ --tw-bg-opacity: 1;
609
+ background-color: rgb(254 226 226 / var(--tw-bg-opacity));
610
+ }
611
+
612
+ .mdx-message-error > p {
613
+ --tw-text-opacity: 1;
614
+ color: rgb(127 29 29 / var(--tw-text-opacity));
615
+ }
616
+
617
+ .dark .mdx-message-error > p {
618
+ --tw-text-opacity: 1;
619
+ color: rgb(127 29 29 / var(--tw-text-opacity));
620
+ }
621
+
522
622
  .fixed {
523
623
  position: fixed;
524
624
  }
@@ -905,6 +1005,10 @@ Ensure the default browser behavior of the `hidden` attribute.
905
1005
  overflow: hidden;
906
1006
  }
907
1007
 
1008
+ .overflow-y-auto {
1009
+ overflow-y: auto;
1010
+ }
1011
+
908
1012
  .overflow-x-hidden {
909
1013
  overflow-x: hidden;
910
1014
  }
@@ -985,16 +1089,6 @@ Ensure the default browser behavior of the `hidden` attribute.
985
1089
  background-color: rgb(239 246 255 / var(--tw-bg-opacity));
986
1090
  }
987
1091
 
988
- .bg-gray-300 {
989
- --tw-bg-opacity: 1;
990
- background-color: rgb(209 213 219 / var(--tw-bg-opacity));
991
- }
992
-
993
- .bg-blue-300 {
994
- --tw-bg-opacity: 1;
995
- background-color: rgb(147 197 253 / var(--tw-bg-opacity));
996
- }
997
-
998
1092
  .bg-gray-700 {
999
1093
  --tw-bg-opacity: 1;
1000
1094
  background-color: rgb(55 65 81 / var(--tw-bg-opacity));
@@ -1015,21 +1109,6 @@ Ensure the default browser behavior of the `hidden` attribute.
1015
1109
  background-color: rgb(37 99 235 / var(--tw-bg-opacity));
1016
1110
  }
1017
1111
 
1018
- .bg-green-50 {
1019
- --tw-bg-opacity: 1;
1020
- background-color: rgb(240 253 244 / var(--tw-bg-opacity));
1021
- }
1022
-
1023
- .bg-orange-50 {
1024
- --tw-bg-opacity: 1;
1025
- background-color: rgb(255 247 237 / var(--tw-bg-opacity));
1026
- }
1027
-
1028
- .bg-red-50 {
1029
- --tw-bg-opacity: 1;
1030
- background-color: rgb(254 242 242 / var(--tw-bg-opacity));
1031
- }
1032
-
1033
1112
  .object-cover {
1034
1113
  -o-object-fit: cover;
1035
1114
  object-fit: cover;
@@ -1205,26 +1284,6 @@ Ensure the default browser behavior of the `hidden` attribute.
1205
1284
  color: rgb(147 197 253 / var(--tw-text-opacity));
1206
1285
  }
1207
1286
 
1208
- .text-blue-900 {
1209
- --tw-text-opacity: 1;
1210
- color: rgb(30 58 138 / var(--tw-text-opacity));
1211
- }
1212
-
1213
- .text-green-900 {
1214
- --tw-text-opacity: 1;
1215
- color: rgb(20 83 45 / var(--tw-text-opacity));
1216
- }
1217
-
1218
- .text-orange-900 {
1219
- --tw-text-opacity: 1;
1220
- color: rgb(124 45 18 / var(--tw-text-opacity));
1221
- }
1222
-
1223
- .text-red-900 {
1224
- --tw-text-opacity: 1;
1225
- color: rgb(127 29 29 / var(--tw-text-opacity));
1226
- }
1227
-
1228
1287
  .opacity-0 {
1229
1288
  opacity: 0;
1230
1289
  }
@@ -1626,7 +1685,10 @@ article a:hover {
1626
1685
  }
1627
1686
 
1628
1687
  article a {
1629
- background-image: linear-gradient(transparent 60%, rgba(130, 199, 255, 0.28) 55%);
1688
+ background-image: linear-gradient(
1689
+ transparent 60%,
1690
+ rgba(130, 199, 255, 0.28) 55%
1691
+ );
1630
1692
  }
1631
1693
 
1632
1694
  .link-with-underline {
@@ -1652,7 +1714,10 @@ article a {
1652
1714
  }
1653
1715
 
1654
1716
  .link-with-underline {
1655
- background-image: linear-gradient(transparent 60%, rgba(130, 199, 255, 0.28) 55%);
1717
+ background-image: linear-gradient(
1718
+ transparent 60%,
1719
+ rgba(130, 199, 255, 0.28) 55%
1720
+ );
1656
1721
  }
1657
1722
 
1658
1723
  /*article pre {*/
@@ -1684,7 +1749,7 @@ article hr {
1684
1749
  }
1685
1750
 
1686
1751
  html {
1687
- scroll-behavior: smooth
1752
+ scroll-behavior: smooth;
1688
1753
  }
1689
1754
 
1690
1755
  :root {
@@ -1693,7 +1758,12 @@ html {
1693
1758
 
1694
1759
  /** Anchor with offset for headings */
1695
1760
 
1696
- h1, h2, h3, h4, h5, h6 {
1761
+ h1,
1762
+ h2,
1763
+ h3,
1764
+ h4,
1765
+ h5,
1766
+ h6 {
1697
1767
  scroll-margin-top: calc(var(--anchor-offset) + 88px);
1698
1768
  }
1699
1769
 
@@ -1987,9 +2057,9 @@ h1, h2, h3, h4, h5, h6 {
1987
2057
  width: 75%;
1988
2058
  }
1989
2059
 
1990
- .lg\:px-0 {
1991
- padding-left: 0px;
1992
- padding-right: 0px;
2060
+ .lg\:px-2 {
2061
+ padding-left: 0.5rem;
2062
+ padding-right: 0.5rem;
1993
2063
  }
1994
2064
 
1995
2065
  .lg\:py-12 {
@@ -1,3 +1,5 @@
1
+ // @ts-ignore
2
+ import { history } from 'umi';
1
3
  import { useThemeContext } from './context';
2
4
 
3
5
  interface useLanguageResult {
@@ -36,19 +38,19 @@ function useLanguage(): useLanguageResult {
36
38
  let p = location.pathname.split('/');
37
39
  p.shift();
38
40
  p.shift();
39
- window.location.pathname = p.join('/');
41
+ history.push('/' + p.join('/'));
40
42
  return;
41
43
  }
42
44
 
43
45
  // 当前在默认语言,切换到其他语言
44
46
  if (!isFromPath) {
45
- window.location.pathname = locale + location.pathname;
47
+ history.push('/' + locale + location.pathname);
46
48
  return;
47
49
  }
48
50
 
49
51
  let p = location.pathname.split('/');
50
52
  p[1] = locale;
51
- window.location.pathname = p.join('/');
53
+ history.push('/' + p.join('/'));
52
54
  }
53
55
 
54
56
  function render(key: string) {
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.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
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];
@@ -25,6 +29,20 @@ const fs_1 = __importStar(require("fs"));
25
29
  const path_1 = require("path");
26
30
  const markdown_1 = require("./markdown");
27
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
+ }
28
46
  api.modifyDefaultConfig((memo) => {
29
47
  memo.conventionRoutes = Object.assign(Object.assign({}, memo.conventionRoutes), { base: (0, path_1.join)(api.cwd, 'docs') });
30
48
  memo.mdx = {
@@ -56,6 +74,22 @@ exports.default = (api) => {
56
74
  }
57
75
  }
58
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
+ });
59
93
  api.onGenerateFiles(() => {
60
94
  var _a;
61
95
  // theme path
@@ -67,20 +101,7 @@ exports.default = (api) => {
67
101
  const themeConfigPath = (0, path_1.join)(api.cwd, 'theme.config.ts');
68
102
  const themeExists = (0, fs_1.existsSync)(themeConfigPath);
69
103
  // 将 docs/locales 目录下的 json 文件注入到 themeConfig.locales 中
70
- let injectLocale = 'themeConfig.locales = {};';
71
- const localesPath = (0, path_1.join)(api.cwd, 'docs/locales');
72
- if ((0, fs_1.existsSync)(localesPath)) {
73
- fs_1.default.readdirSync(localesPath).forEach((file) => {
74
- if (file.endsWith('.json')) {
75
- const filePath = (0, path_1.join)(localesPath, file);
76
- const content = fs_1.default.readFileSync(filePath).toString();
77
- const json = JSON.parse(content);
78
- const localeName = file.replace('.json', '');
79
- injectLocale += `themeConfig.locales['${localeName}'] = ${JSON.stringify(json)};
80
- `;
81
- }
82
- });
83
- }
104
+ let injectLocale = `themeConfig.locales = ${JSON.stringify(locales)};`;
84
105
  // exports don't start with $ will be MDX Component
85
106
  const [_, exports] = (0, bundler_utils_1.parseModuleSync)({
86
107
  content: (0, fs_1.readFileSync)(theme, 'utf-8'),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/plugin-docs",
3
- "version": "4.0.0-rc.3",
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",
@@ -33,7 +33,7 @@
33
33
  "classnames": "^2.3.1",
34
34
  "rehype-slug": "5.0.1",
35
35
  "tailwindcss": "^3.0.23",
36
- "umi": "4.0.0-rc.3"
36
+ "umi": "4.0.0-rc.4"
37
37
  },
38
38
  "publishConfig": {
39
39
  "access": "public"