@umijs/plugin-docs 4.0.5 → 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.
@@ -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()!;
@@ -112,7 +112,7 @@ export default () => {
112
112
  <components.Link
113
113
  to={(isFromPath ? currentLanguage?.locale : '') + r.href}
114
114
  key={i}
115
- onClick={() => (document.activeElement as HTMLElement)?.blur()}
115
+ onClick={() => scrollToAnchor(r.href)}
116
116
  className="group outline-none search-result"
117
117
  onFocus={() => setIsFocused(true)}
118
118
  onBlur={() => setIsFocused(false)}
@@ -168,7 +168,7 @@ function search(routes: any, keyword: string): SearchResultItem[] {
168
168
  .join(' > ') +
169
169
  ' > ' +
170
170
  title.title,
171
- href: '/' + path + '#' + getLinkFromTitle(title.title),
171
+ href: '/' + path + '#' + slugger.slug(title.title),
172
172
  });
173
173
  }
174
174
  });
@@ -206,3 +206,18 @@ function handleKeyUp(e: KeyboardEvent) {
206
206
  document.activeElement?.previousSibling as HTMLDivElement | undefined
207
207
  )?.focus();
208
208
  }
209
+
210
+ function scrollToAnchor(to: string) {
211
+ const hash = to.match(/(#[^&?]*)/)?.[1] || '';
212
+
213
+ (document.activeElement as HTMLElement)?.blur();
214
+
215
+ window.requestAnimationFrame(() => {
216
+ const elm = document.getElementById(hash.substring(1));
217
+ if (elm) {
218
+ elm.scrollIntoView();
219
+ } else {
220
+ window.scrollTo(0, 0);
221
+ }
222
+ });
223
+ }
@@ -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={'#' + getLinkFromTitle(item.title)}
52
+ href={'#' + slugger.slug(item.title)}
52
53
  >
53
54
  {getTocTitle(item.title)}
54
55
  </a>
@@ -0,0 +1,78 @@
1
+ import React, { FC, PropsWithChildren, ReactNode, useState } from 'react';
2
+
3
+ type Pane = {
4
+ title: ReactNode;
5
+ content: ReactNode;
6
+ };
7
+
8
+ type TabbedProps = {
9
+ panes?: Pane[];
10
+ };
11
+
12
+ export default function Tabbed(props: PropsWithChildren<TabbedProps>) {
13
+ const { children } = props;
14
+
15
+ const [activeTab, setActiveTab] = useState(0);
16
+
17
+ let tabs: ReactNode[] = [];
18
+ let content: ReactNode = null;
19
+
20
+ if (props.panes && props.panes.length > 0) {
21
+ tabs = props.panes.map((pane) => {
22
+ return pane.title;
23
+ });
24
+
25
+ content = props.panes[activeTab].content;
26
+ } else {
27
+ // Guess pane from children, make mdx more idiomatic
28
+ const childrenArray = React.Children.toArray(children) || [];
29
+
30
+ tabs = childrenArray.filter((_, index) => index % 2 === 0);
31
+ const contents = childrenArray.filter((_, index) => index % 2 === 1);
32
+
33
+ content = contents[activeTab];
34
+ }
35
+
36
+ return (
37
+ <div className="tabbed-code">
38
+ <Wrapper>
39
+ <Tabs tabs={tabs} setActiveTab={setActiveTab} activeTab={activeTab} />
40
+ </Wrapper>
41
+ {content || null}
42
+ </div>
43
+ );
44
+ }
45
+ const Wrapper: FC<PropsWithChildren> = ({ children }) => {
46
+ return <div className={`w-full pt-5 pt-0 `}>{children}</div>;
47
+ };
48
+
49
+ const Tabs: FC<
50
+ PropsWithChildren<{
51
+ tabs: ReactNode[];
52
+ setActiveTab: Function;
53
+ activeTab: number;
54
+ }>
55
+ > = ({ tabs, activeTab, setActiveTab }) => {
56
+ return (
57
+ <ul className="cursor-pointer m-0 mt-4 px-0 list-none inline-flex flex-wrap rounded-t-lg text-sm font-small text-center text-gray-500 dark:text-gray-400">
58
+ {tabs.map((tab, index) => {
59
+ return (
60
+ <li key={index} className="mr-0 mt-0">
61
+ <button
62
+ onClick={() => setActiveTab(index)}
63
+ className={`tabbed-tab-button
64
+ hover:text-gray-700 hover:border-gray-300 dark:hover:text-gray-300
65
+ ${
66
+ activeTab === index
67
+ ? 'bg-zinc-900 text-white hover:text-neutral-300 dark:text-white'
68
+ : 'text-neutral-500 hover:text-gray-700 hover:border-gray-300 dark:hover:text-gray-300 '
69
+ }`}
70
+ >
71
+ {tab}
72
+ </button>
73
+ </li>
74
+ );
75
+ })}
76
+ </ul>
77
+ );
78
+ };
@@ -5,4 +5,5 @@ export { default as FeatureItem } from './components/FeatureItem';
5
5
  export { default as Features } from './components/Features';
6
6
  export { default as Hero } from './components/Hero';
7
7
  export { default as Message } from './components/Message';
8
+ export { default as Tabbed } from './components/Tabbed';
8
9
  export { default as $Layout } from './Layout';
@@ -3,28 +3,28 @@
3
3
  @tailwind utilities;
4
4
 
5
5
  article h1 {
6
- @apply text-4xl font-bold tracking-tight mt-2 my-4 dark:text-white;
6
+ @apply text-4xl font-bold tracking-tight mt-2 my-4 dark:text-white title-link;
7
7
  }
8
8
 
9
9
  article h2 {
10
- @apply text-3xl font-semibold tracking-tight mt-10 dark:text-white;
10
+ @apply text-3xl font-semibold tracking-tight mt-10 dark:text-white title-link;
11
11
  @apply pb-1 border-b;
12
12
  }
13
13
 
14
14
  article h3 {
15
- @apply text-2xl font-semibold tracking-tight mt-8 dark:text-white;
15
+ @apply text-2xl font-semibold tracking-tight mt-8 dark:text-white title-link;
16
16
  }
17
17
 
18
18
  article h4 {
19
- @apply text-xl font-semibold tracking-tight mt-8 dark:text-white;
19
+ @apply text-xl font-semibold tracking-tight mt-8 dark:text-white title-link;
20
20
  }
21
21
 
22
22
  article h5 {
23
- @apply text-lg font-semibold tracking-tight mt-8 dark:text-white;
23
+ @apply text-lg font-semibold tracking-tight mt-8 dark:text-white title-link;
24
24
  }
25
25
 
26
26
  article h6 {
27
- @apply text-base font-semibold tracking-tight mt-8 dark:text-white;
27
+ @apply text-base font-semibold tracking-tight mt-8 dark:text-white title-link;
28
28
  }
29
29
 
30
30
  article p {
@@ -77,6 +77,23 @@ article div[data-rehype-pretty-code-fragment] {
77
77
  @apply my-4;
78
78
  }
79
79
 
80
+ article .tabbed-code div[data-rehype-pretty-code-fragment] {
81
+ @apply my-0;
82
+ }
83
+
84
+ article .tabbed-code pre {
85
+ @apply rounded-none rounded-b-md rounded-tr-md;
86
+ }
87
+
88
+ article .tabbed-code .tabbed-tab-button {
89
+ @apply inline-flex items-center rounded-t-lg px-4;
90
+ }
91
+
92
+ article .tabbed-code .tabbed-tab-button * {
93
+ @apply mt-0;
94
+ color: inherit;
95
+ }
96
+
80
97
  /* 代码块的标题部分 */
81
98
  article
82
99
  div[data-rehype-pretty-code-fragment]
@@ -223,6 +240,33 @@ h6 {
223
240
  }
224
241
 
225
242
  @layer components {
243
+ .title-link a {
244
+ float: left;
245
+ margin-top: 0.1em;
246
+ margin-left: -24px;
247
+ width: 20px;
248
+ padding-right: 4px;
249
+ line-height: 1;
250
+ box-sizing: border-box;
251
+ background: none;
252
+ opacity: 0;
253
+ }
254
+
255
+ .title-link:hover a {
256
+ opacity: 1;
257
+ }
258
+
259
+ .title-link span {
260
+ display: none;
261
+ }
262
+
263
+ .title-link a::after {
264
+ content: '#';
265
+ display: inline-block;
266
+ vertical-align: middle;
267
+ font-size: 20px;
268
+ }
269
+
226
270
  .features-dark {
227
271
  @apply bg-gray-900;
228
272
  background-image: radial-gradient(#2a2a2a 20%, transparent 20%);
@@ -787,6 +787,10 @@ video {
787
787
  margin: 2rem;
788
788
  }
789
789
 
790
+ .m-0 {
791
+ margin: 0px;
792
+ }
793
+
790
794
  .my-6 {
791
795
  margin-top: 1.5rem;
792
796
  margin-bottom: 1.5rem;
@@ -873,14 +877,30 @@ video {
873
877
  margin-bottom: 0.75rem;
874
878
  }
875
879
 
880
+ .mr-0 {
881
+ margin-right: 0px;
882
+ }
883
+
876
884
  .block {
877
885
  display: block;
878
886
  }
879
887
 
888
+ .inline-block {
889
+ display: inline-block;
890
+ }
891
+
880
892
  .flex {
881
893
  display: flex;
882
894
  }
883
895
 
896
+ .inline-flex {
897
+ display: inline-flex;
898
+ }
899
+
900
+ .contents {
901
+ display: contents;
902
+ }
903
+
884
904
  .hidden {
885
905
  display: none;
886
906
  }
@@ -1088,6 +1108,10 @@ video {
1088
1108
  cursor: default;
1089
1109
  }
1090
1110
 
1111
+ .list-none {
1112
+ list-style-type: none;
1113
+ }
1114
+
1091
1115
  .flex-row {
1092
1116
  flex-direction: row;
1093
1117
  }
@@ -1156,6 +1180,11 @@ video {
1156
1180
  border-radius: 0.75rem;
1157
1181
  }
1158
1182
 
1183
+ .rounded-t-lg {
1184
+ border-top-left-radius: 0.5rem;
1185
+ border-top-right-radius: 0.5rem;
1186
+ }
1187
+
1159
1188
  .border {
1160
1189
  border-width: 1px;
1161
1190
  }
@@ -1236,6 +1265,11 @@ video {
1236
1265
  background-color: rgb(37 99 235 / var(--tw-bg-opacity));
1237
1266
  }
1238
1267
 
1268
+ .bg-zinc-900 {
1269
+ --tw-bg-opacity: 1;
1270
+ background-color: rgb(24 24 27 / var(--tw-bg-opacity));
1271
+ }
1272
+
1239
1273
  .object-cover {
1240
1274
  -o-object-fit: cover;
1241
1275
  object-fit: cover;
@@ -1309,6 +1343,11 @@ video {
1309
1343
  padding-bottom: 1.25rem;
1310
1344
  }
1311
1345
 
1346
+ .px-0 {
1347
+ padding-left: 0px;
1348
+ padding-right: 0px;
1349
+ }
1350
+
1312
1351
  .pt-4 {
1313
1352
  padding-top: 1rem;
1314
1353
  }
@@ -1341,6 +1380,14 @@ video {
1341
1380
  padding-bottom: 3rem;
1342
1381
  }
1343
1382
 
1383
+ .pt-5 {
1384
+ padding-top: 1.25rem;
1385
+ }
1386
+
1387
+ .pt-0 {
1388
+ padding-top: 0px;
1389
+ }
1390
+
1344
1391
  .text-center {
1345
1392
  text-align: center;
1346
1393
  }
@@ -1438,6 +1485,11 @@ video {
1438
1485
  color: rgb(147 197 253 / var(--tw-text-opacity));
1439
1486
  }
1440
1487
 
1488
+ .text-neutral-500 {
1489
+ --tw-text-opacity: 1;
1490
+ color: rgb(115 115 115 / var(--tw-text-opacity));
1491
+ }
1492
+
1441
1493
  .opacity-0 {
1442
1494
  opacity: 0;
1443
1495
  }
@@ -1543,6 +1595,33 @@ video {
1543
1595
  transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
1544
1596
  }
1545
1597
 
1598
+ article h1 a {
1599
+ float: left;
1600
+ margin-top: 0.1em;
1601
+ margin-left: -24px;
1602
+ width: 20px;
1603
+ padding-right: 4px;
1604
+ line-height: 1;
1605
+ box-sizing: border-box;
1606
+ background: none;
1607
+ opacity: 0;
1608
+ }
1609
+
1610
+ article h1:hover a {
1611
+ opacity: 1;
1612
+ }
1613
+
1614
+ article h1 span {
1615
+ display: none;
1616
+ }
1617
+
1618
+ article h1 a::after {
1619
+ content: '#';
1620
+ display: inline-block;
1621
+ vertical-align: middle;
1622
+ font-size: 20px;
1623
+ }
1624
+
1546
1625
  article h1 {
1547
1626
  margin-bottom: 1rem;
1548
1627
  margin-top: 0.5rem;
@@ -1557,6 +1636,33 @@ article h1 {
1557
1636
  color: rgb(255 255 255 / var(--tw-text-opacity));
1558
1637
  }
1559
1638
 
1639
+ article h2 a {
1640
+ float: left;
1641
+ margin-top: 0.1em;
1642
+ margin-left: -24px;
1643
+ width: 20px;
1644
+ padding-right: 4px;
1645
+ line-height: 1;
1646
+ box-sizing: border-box;
1647
+ background: none;
1648
+ opacity: 0;
1649
+ }
1650
+
1651
+ article h2:hover a {
1652
+ opacity: 1;
1653
+ }
1654
+
1655
+ article h2 span {
1656
+ display: none;
1657
+ }
1658
+
1659
+ article h2 a::after {
1660
+ content: '#';
1661
+ display: inline-block;
1662
+ vertical-align: middle;
1663
+ font-size: 20px;
1664
+ }
1665
+
1560
1666
  article h2 {
1561
1667
  margin-top: 2.5rem;
1562
1668
  font-size: 1.875rem;
@@ -1575,6 +1681,33 @@ article h2 {
1575
1681
  padding-bottom: 0.25rem;
1576
1682
  }
1577
1683
 
1684
+ article h3 a {
1685
+ float: left;
1686
+ margin-top: 0.1em;
1687
+ margin-left: -24px;
1688
+ width: 20px;
1689
+ padding-right: 4px;
1690
+ line-height: 1;
1691
+ box-sizing: border-box;
1692
+ background: none;
1693
+ opacity: 0;
1694
+ }
1695
+
1696
+ article h3:hover a {
1697
+ opacity: 1;
1698
+ }
1699
+
1700
+ article h3 span {
1701
+ display: none;
1702
+ }
1703
+
1704
+ article h3 a::after {
1705
+ content: '#';
1706
+ display: inline-block;
1707
+ vertical-align: middle;
1708
+ font-size: 20px;
1709
+ }
1710
+
1578
1711
  article h3 {
1579
1712
  margin-top: 2rem;
1580
1713
  font-size: 1.5rem;
@@ -1588,6 +1721,33 @@ article h3 {
1588
1721
  color: rgb(255 255 255 / var(--tw-text-opacity));
1589
1722
  }
1590
1723
 
1724
+ article h4 a {
1725
+ float: left;
1726
+ margin-top: 0.1em;
1727
+ margin-left: -24px;
1728
+ width: 20px;
1729
+ padding-right: 4px;
1730
+ line-height: 1;
1731
+ box-sizing: border-box;
1732
+ background: none;
1733
+ opacity: 0;
1734
+ }
1735
+
1736
+ article h4:hover a {
1737
+ opacity: 1;
1738
+ }
1739
+
1740
+ article h4 span {
1741
+ display: none;
1742
+ }
1743
+
1744
+ article h4 a::after {
1745
+ content: '#';
1746
+ display: inline-block;
1747
+ vertical-align: middle;
1748
+ font-size: 20px;
1749
+ }
1750
+
1591
1751
  article h4 {
1592
1752
  margin-top: 2rem;
1593
1753
  font-size: 1.25rem;
@@ -1601,6 +1761,33 @@ article h4 {
1601
1761
  color: rgb(255 255 255 / var(--tw-text-opacity));
1602
1762
  }
1603
1763
 
1764
+ article h5 a {
1765
+ float: left;
1766
+ margin-top: 0.1em;
1767
+ margin-left: -24px;
1768
+ width: 20px;
1769
+ padding-right: 4px;
1770
+ line-height: 1;
1771
+ box-sizing: border-box;
1772
+ background: none;
1773
+ opacity: 0;
1774
+ }
1775
+
1776
+ article h5:hover a {
1777
+ opacity: 1;
1778
+ }
1779
+
1780
+ article h5 span {
1781
+ display: none;
1782
+ }
1783
+
1784
+ article h5 a::after {
1785
+ content: '#';
1786
+ display: inline-block;
1787
+ vertical-align: middle;
1788
+ font-size: 20px;
1789
+ }
1790
+
1604
1791
  article h5 {
1605
1792
  margin-top: 2rem;
1606
1793
  font-size: 1.125rem;
@@ -1614,6 +1801,33 @@ article h5 {
1614
1801
  color: rgb(255 255 255 / var(--tw-text-opacity));
1615
1802
  }
1616
1803
 
1804
+ article h6 a {
1805
+ float: left;
1806
+ margin-top: 0.1em;
1807
+ margin-left: -24px;
1808
+ width: 20px;
1809
+ padding-right: 4px;
1810
+ line-height: 1;
1811
+ box-sizing: border-box;
1812
+ background: none;
1813
+ opacity: 0;
1814
+ }
1815
+
1816
+ article h6:hover a {
1817
+ opacity: 1;
1818
+ }
1819
+
1820
+ article h6 span {
1821
+ display: none;
1822
+ }
1823
+
1824
+ article h6 a::after {
1825
+ content: '#';
1826
+ display: inline-block;
1827
+ vertical-align: middle;
1828
+ font-size: 20px;
1829
+ }
1830
+
1617
1831
  article h6 {
1618
1832
  margin-top: 2rem;
1619
1833
  font-size: 1rem;
@@ -1793,6 +2007,32 @@ article div[data-rehype-pretty-code-fragment] {
1793
2007
  margin-bottom: 1rem;
1794
2008
  }
1795
2009
 
2010
+ article .tabbed-code div[data-rehype-pretty-code-fragment] {
2011
+ margin-top: 0px;
2012
+ margin-bottom: 0px;
2013
+ }
2014
+
2015
+ article .tabbed-code pre {
2016
+ border-radius: 0px;
2017
+ border-bottom-right-radius: 0.375rem;
2018
+ border-bottom-left-radius: 0.375rem;
2019
+ border-top-right-radius: 0.375rem;
2020
+ }
2021
+
2022
+ article .tabbed-code .tabbed-tab-button {
2023
+ display: inline-flex;
2024
+ align-items: center;
2025
+ border-top-left-radius: 0.5rem;
2026
+ border-top-right-radius: 0.5rem;
2027
+ padding-left: 1rem;
2028
+ padding-right: 1rem;
2029
+ }
2030
+
2031
+ article .tabbed-code .tabbed-tab-button * {
2032
+ margin-top: 0px;
2033
+ color: inherit;
2034
+ }
2035
+
1796
2036
  /* 代码块的标题部分 */
1797
2037
 
1798
2038
  article
@@ -2203,6 +2443,11 @@ h6 {
2203
2443
  border-color: rgb(243 244 246 / var(--tw-border-opacity));
2204
2444
  }
2205
2445
 
2446
+ .hover\:border-gray-300:hover {
2447
+ --tw-border-opacity: 1;
2448
+ border-color: rgb(209 213 219 / var(--tw-border-opacity));
2449
+ }
2450
+
2206
2451
  .hover\:bg-gray-50:hover {
2207
2452
  --tw-bg-opacity: 1;
2208
2453
  background-color: rgb(249 250 251 / var(--tw-bg-opacity));
@@ -2218,6 +2463,16 @@ h6 {
2218
2463
  color: rgb(59 130 246 / var(--tw-text-opacity));
2219
2464
  }
2220
2465
 
2466
+ .hover\:text-gray-700:hover {
2467
+ --tw-text-opacity: 1;
2468
+ color: rgb(55 65 81 / var(--tw-text-opacity));
2469
+ }
2470
+
2471
+ .hover\:text-neutral-300:hover {
2472
+ --tw-text-opacity: 1;
2473
+ color: rgb(212 212 212 / var(--tw-text-opacity));
2474
+ }
2475
+
2221
2476
  .hover\:shadow-2xl:hover {
2222
2477
  --tw-shadow: 0 25px 50px -12px rgb(0 0 0 / 0.25);
2223
2478
  --tw-shadow-colored: 0 25px 50px -12px var(--tw-shadow-color);
@@ -2375,6 +2630,11 @@ h6 {
2375
2630
  color: rgb(59 130 246 / var(--tw-text-opacity));
2376
2631
  }
2377
2632
 
2633
+ .dark .dark\:hover\:text-gray-300:hover {
2634
+ --tw-text-opacity: 1;
2635
+ color: rgb(209 213 219 / var(--tw-text-opacity));
2636
+ }
2637
+
2378
2638
  @media (min-width: 768px) {
2379
2639
  .md\:h-6 {
2380
2640
  height: 1.5rem;
@@ -0,0 +1,22 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2016 Titus Wormer <tituswormer@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1 @@
1
+ (function(){"use strict";var e={980:function(e){var t=Object.prototype.hasOwnProperty;var n=Object.prototype.toString;var r=Object.defineProperty;var o=Object.getOwnPropertyDescriptor;var i=function isArray(e){if(typeof Array.isArray==="function"){return Array.isArray(e)}return n.call(e)==="[object Array]"};var u=function isPlainObject(e){if(!e||n.call(e)!=="[object Object]"){return false}var r=t.call(e,"constructor");var o=e.constructor&&e.constructor.prototype&&t.call(e.constructor.prototype,"isPrototypeOf");if(e.constructor&&!r&&!o){return false}var i;for(i in e){}return typeof i==="undefined"||t.call(e,i)};var a=function setProperty(e,t){if(r&&t.name==="__proto__"){r(e,t.name,{enumerable:true,configurable:true,value:t.newValue,writable:true})}else{e[t.name]=t.newValue}};var c=function getProperty(e,n){if(n==="__proto__"){if(!t.call(e,n)){return void 0}else if(o){return o(e,n).value}}return e[n]};e.exports=function extend(){var e,t,n,r,o,f;var l=arguments[0];var s=1;var p=arguments.length;var y=false;if(typeof l==="boolean"){y=l;l=arguments[1]||{};s=2}if(l==null||typeof l!=="object"&&typeof l!=="function"){l={}}for(;s<p;++s){e=arguments[s];if(e!=null){for(t in e){n=c(l,t);r=c(e,t);if(l!==r){if(y&&r&&(u(r)||(o=i(r)))){if(o){o=false;f=n&&i(n)?n:[]}else{f=n&&u(n)?n:{}}a(l,{name:t,newValue:extend(y,f,r)})}else if(typeof r!=="undefined"){a(l,{name:t,newValue:r})}}}}}return l}}};var t={};function __nccwpck_require__(n){var r=t[n];if(r!==undefined){return r.exports}var o=t[n]={exports:{}};var i=true;try{e[n](o,o.exports,__nccwpck_require__);i=false}finally{if(i)delete t[n]}return o.exports}!function(){__nccwpck_require__.d=function(e,t){for(var n in t){if(__nccwpck_require__.o(t,n)&&!__nccwpck_require__.o(e,n)){Object.defineProperty(e,n,{enumerable:true,get:t[n]})}}}}();!function(){__nccwpck_require__.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}}();!function(){__nccwpck_require__.r=function(e){if(typeof Symbol!=="undefined"&&Symbol.toStringTag){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}Object.defineProperty(e,"__esModule",{value:true})}}();if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var n={};!function(){__nccwpck_require__.r(n);__nccwpck_require__.d(n,{default:function(){return rehypeAutolinkHeadings}});var e=__nccwpck_require__(980);var t={}.hasOwnProperty;function hasProperty(e,n){var r=n&&e&&typeof e==="object"&&e.type==="element"&&e.properties&&t.call(e.properties,n)&&e.properties[n];return r!==null&&r!==undefined&&r!==false}function headingRank(e){var t=e&&e.type==="element"&&e.tagName.toLowerCase()||"";var n=t.length===2&&t.charCodeAt(0)===104?t.charCodeAt(1):0;return n>48&&n<55?n-48:null}const isElement=function(e,t,n,r,o){const i=convertElement(t);if(n!==undefined&&n!==null&&(typeof n!=="number"||n<0||n===Number.POSITIVE_INFINITY)){throw new Error("Expected positive finite index for child node")}if(r!==undefined&&r!==null&&(!r.type||!r.children)){throw new Error("Expected parent node")}if(!e||!e.type||typeof e.type!=="string"){return false}if((r===undefined||r===null)!==(n===undefined||n===null)){throw new Error("Expected both parent and index")}return i.call(o,e,n,r)};const convertElement=function(e){if(e===undefined||e===null){return hast_util_is_element_element}if(typeof e==="string"){return tagNameFactory(e)}if(typeof e==="object"){return anyFactory(e)}if(typeof e==="function"){return castFactory(e)}throw new Error("Expected function, string, or array as test")};function anyFactory(e){const t=[];let n=-1;while(++n<e.length){t[n]=convertElement(e[n])}return castFactory(any);function any(...e){let n=-1;while(++n<t.length){if(t[n].call(this,...e)){return true}}return false}}function tagNameFactory(e){return tagName;function tagName(t){return hast_util_is_element_element(t)&&t.tagName===e}}function castFactory(e){return assertion;function assertion(t,...n){return hast_util_is_element_element(t)&&Boolean(e.call(this,t,...n))}}function hast_util_is_element_element(e){return Boolean(e&&typeof e==="object"&&e.type==="element"&&typeof e.tagName==="string")}const r=function is(e,t,n,r,o){const i=convert(t);if(n!==undefined&&n!==null&&(typeof n!=="number"||n<0||n===Number.POSITIVE_INFINITY)){throw new Error("Expected positive finite index")}if(r!==undefined&&r!==null&&(!is(r)||!r.children)){throw new Error("Expected parent node")}if((r===undefined||r===null)!==(n===undefined||n===null)){throw new Error("Expected both parent and index")}return e&&e.type&&typeof e.type==="string"?Boolean(i.call(o,e,n,r)):false};const convert=function(e){if(e===undefined||e===null){return ok}if(typeof e==="string"){return typeFactory(e)}if(typeof e==="object"){return Array.isArray(e)?unist_util_is_anyFactory(e):propsFactory(e)}if(typeof e==="function"){return unist_util_is_castFactory(e)}throw new Error("Expected function, string, or object as test")};function unist_util_is_anyFactory(e){const t=[];let n=-1;while(++n<e.length){t[n]=convert(e[n])}return unist_util_is_castFactory(any);function any(...e){let n=-1;while(++n<t.length){if(t[n].call(this,...e))return true}return false}}function propsFactory(e){return unist_util_is_castFactory(all);function all(t){let n;for(n in e){if(t[n]!==e[n])return false}return true}}function typeFactory(e){return unist_util_is_castFactory(type);function type(t){return t&&t.type===e}}function unist_util_is_castFactory(e){return assertion;function assertion(...t){return Boolean(e.call(this,...t))}}function ok(){return true}function color(e){return""+e+""}const o=true;const i="skip";const u=false;const visitParents=function(e,t,n,r){if(typeof t==="function"&&typeof n!=="function"){r=n;n=t;t=null}const o=convert(t);const a=r?-1:1;factory(e,null,[])();function factory(e,c,f){const l=typeof e==="object"&&e!==null?e:{};let s;if(typeof l.type==="string"){s=typeof l.tagName==="string"?l.tagName:typeof l.name==="string"?l.name:undefined;Object.defineProperty(visit,"name",{value:"node ("+color(l.type+(s?"<"+s+">":""))+")"})}return visit;function visit(){let l=[];let s;let p;let y;if(!t||o(e,c,f[f.length-1]||null)){l=toResult(n(e,f));if(l[0]===u){return l}}if(e.children&&l[0]!==i){p=(r?e.children.length:-1)+a;y=f.concat(e);while(p>-1&&p<e.children.length){s=factory(e.children[p],p,y)();if(s[0]===u){return s}p=typeof s[1]==="number"?s[1]:p+a}}return l}}};function toResult(e){if(Array.isArray(e)){return e}if(typeof e==="number"){return[o,e]}return[e]}const visit=function(e,t,n,r){if(typeof t==="function"&&typeof n!=="function"){r=n;n=t;t=null}visitParents(e,t,overload,r);function overload(e,t){const r=t[t.length-1];return n(e,r?r.children.indexOf(e):null,r)}};const a={type:"element",tagName:"span",properties:{className:["icon","icon-link"]},children:[]};function rehypeAutolinkHeadings(t={}){let n=t.properties;const r=t.behaviour||t.behavior||"prepend";const o=t.content||a;const u=t.group;const c=convertElement(t.test);let f;if(r==="wrap"){f=wrap}else if(r==="before"||r==="after"){f=around}else{if(!n){n={ariaHidden:"true",tabIndex:-1}}f=inject}return e=>{visit(e,"element",((e,t,n)=>{if(headingRank(e)&&hasProperty(e,"id")&&c(e,t,n)){return f(e,t,n)}}))};function inject(t){t.children[r==="prepend"?"unshift":"push"](create(t,e(true,{},n),toChildren(o,t)));return[i]}function around(t,a,c){if(typeof a!=="number"||!c)return;const f=create(t,e(true,{},n),toChildren(o,t));let l=r==="before"?[f,t]:[t,f];if(u){const e=toNode(u,t);if(e&&!Array.isArray(e)&&e.type==="element"){e.children=l;l=[e]}}c.children.splice(a,1,...l);return[i,a+l.length]}function wrap(t){t.children=[create(t,e(true,{},n),t.children)];return[i]}function toChildren(e,t){const n=toNode(e,t);return Array.isArray(n)?n:[n]}function toNode(t,n){if(typeof t==="function")return t(n);return e(true,Array.isArray(t)?[]:{},t)}function create(e,t,n){return{type:"element",tagName:"a",properties:Object.assign({},t,{href:"#"+(e.properties||{}).id}),children:n}}}}();module.exports=n})();
@@ -0,0 +1 @@
1
+ {"name":"rehype-autolink-headings","author":"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)","license":"MIT","types":"index.d.ts"}
package/dist/compiler.js CHANGED
@@ -1,54 +1,70 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
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
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.compile = void 0;
7
- const rehype_pretty_code_1 = __importDefault(require("rehype-pretty-code"));
8
- const plugin_utils_1 = require("umi/plugin-utils");
9
- // @ts-ignore
10
- const mdx_1 = require("../compiled/@mdx-js/mdx");
11
- // @ts-ignore
12
- const rehype_slug_1 = __importDefault(require("../compiled/rehype-slug"));
13
- // @ts-ignore
14
- const remark_gfm_1 = __importDefault(require("../compiled/remark-gfm"));
15
- // https://rehype-pretty-code.netlify.app
16
- const rehypePrettyCodeOptions = {
17
- theme: 'dark-plus',
18
- onVisitLine(node) {
19
- // Prevent lines from collapsing in `display: grid` mode, and
20
- // allow empty lines to be copy/pasted
21
- if (node.children.length === 0) {
22
- node.children = [{ type: 'text', value: ' ' }];
23
- }
24
- },
25
- // 允许高亮代码行
26
- // 对于高亮的代码行,设置为 highlighted 样式表类
27
- onVisitHighlightedLine(node) {
28
- node.properties.className.push('highlighted');
29
- },
30
- // 允许高亮代码文字
31
- // 对于高亮的代码文字,设置为 word 样式表类
32
- onVisitHighlightedWord(node) {
33
- node.properties.className = ['word'];
34
- },
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
+ }
35
47
  };
36
48
  async function compile(opts) {
37
- const compiler = (0, mdx_1.createProcessor)({
38
- jsx: true,
39
- remarkPlugins: [remark_gfm_1.default],
40
- rehypePlugins: [rehype_slug_1.default, [rehype_pretty_code_1.default, rehypePrettyCodeOptions]],
41
- });
42
- try {
43
- let result = String(await compiler.process(opts.content));
44
- result = result.replace('function MDXContent(props = {}) {', `
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 = {}) {", `
45
61
  import { useEffect } from 'react';
46
62
 
47
63
  function MDXContent(props = {}) {
48
64
 
49
65
  useEffect(() => {
50
66
  if (window.location.hash.length !== 0) {
51
- // 为了右侧内容区能正常跳转
67
+ // \u4E3A\u4E86\u53F3\u4FA7\u5185\u5BB9\u533A\u80FD\u6B63\u5E38\u8DF3\u8F6C
52
68
  const hash = decodeURIComponent(window.location.hash);
53
69
  setTimeout(() => {
54
70
  document.getElementById(hash.slice(1))?.scrollIntoView();
@@ -63,17 +79,16 @@ function MDXContent(props = {}) {
63
79
  }, []);
64
80
 
65
81
  `);
66
- return { result };
67
- }
68
- catch (e) {
69
- plugin_utils_1.logger.error(e.reason);
70
- plugin_utils_1.logger.error(`Above error occurred in ${opts.fileName} at line ${e.line}`);
71
- plugin_utils_1.logger.error(opts.content
72
- .split('\n')
73
- .filter((_, i) => i == e.line - 1)
74
- .join('\n'));
75
- plugin_utils_1.logger.error(' '.repeat(e.column - 1) + '^');
76
- return { result: '' };
77
- }
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
+ }
78
90
  }
79
- exports.compile = compile;
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
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = 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]; } };
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
- Object.defineProperty(o, k2, desc);
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
- Object.defineProperty(exports, "__esModule", { value: true });
26
- const bundler_utils_1 = require("@umijs/bundler-utils");
27
- const utils_1 = require("@umijs/utils");
28
- const fs_1 = __importStar(require("fs"));
29
- const path_1 = require("path");
30
- const markdown_1 = require("./markdown");
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
- }
46
- api.modifyDefaultConfig((memo) => {
47
- memo.conventionRoutes = {
48
- ...memo.conventionRoutes,
49
- base: (0, path_1.join)(api.cwd, 'docs'),
50
- };
51
- memo.mdx = {
52
- loader: require.resolve('./loader'),
53
- loaderOptions: {},
54
- };
55
- return memo;
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
- api.addLayouts(() => {
58
- return [
59
- {
60
- id: 'docs-layout',
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
- api.onPatchRoute(({ route }) => {
66
- if (route.__content) {
67
- route.titles = (0, markdown_1.parseTitle)({
68
- content: route.__content,
69
- });
70
- }
71
- // 放在 docs/xxx.zh-CN.md 的文档,会被映射到 /zh-CN/docs/xxx 目录
72
- if (route.file.match(/.[a-z]{2}-[A-Z]{2}.md$/)) {
73
- route.path = route.path.replace(/(.*).([a-z]{2}-[A-Z]{2})$/, '$2/$1');
74
- // 放在 docs/xxx/README.zh-CN.md 格式结尾的文档,会被映射到 /zh-CN/docs 目录
75
- if (route.path.endsWith('README')) {
76
- route.path = route.path.replace(/README$/, '');
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
- // 检查路由是否存在其他语言,没有的话做 fallback 处理
81
- api.modifyRoutes((r) => {
82
- if (!locales)
83
- return r;
84
- for (const route in r) {
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.onGenerateFiles(() => {
100
- var _a;
101
- // theme path
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, utils_1.winPath)(require.resolve('../client/theme-doc/index.ts'))}';
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
- return (0, path_1.join)(opts.api.paths.absTmpPath, opts.api.plugin.key && !opts.noPluginDir
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
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const compiler_1 = require("./compiler");
4
- async function default_1(content) {
5
- // @ts-ignore
6
- const filename = this.resourcePath;
7
- // @ts-ignore
8
- const callback = this.async();
9
- try {
10
- const { result } = await (0, compiler_1.compile)({
11
- content,
12
- fileName: filename,
13
- });
14
- return callback(null, result);
15
- }
16
- catch (e) {
17
- const err = e;
18
- e.message = `${filename}: ${e.message}`;
19
- throw err;
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
- exports.default = default_1;
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
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseTitle = void 0;
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
- const lines = opts.content
6
- .replace(/{[\n\s\t]*\/\*[\s\S]*?\*\/[\n\s\t]*}/g, '')
7
- .split('\n');
8
- let i = 0;
9
- const ret = [];
10
- while (i < lines.length) {
11
- const line = lines[i].trim();
12
- const match = line.match(/^(#+)\s+(.*)/);
13
- if (match) {
14
- ret.push({
15
- level: match[1].length,
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
- return ret;
38
+ i += 1;
39
+ }
40
+ return ret;
22
41
  }
23
- exports.parseTitle = parseTitle;
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.5",
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 tsc",
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 build --watch",
25
- "dev:css": "pnpm build:css -- --watch",
24
+ "dev": "pnpm father dev",
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,13 +34,15 @@
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",
41
+ "rehype-autolink-headings": "^6.1.1",
39
42
  "rehype-slug": "5.0.1",
40
43
  "remark-gfm": "^3.0.1",
41
44
  "tailwindcss": "^3.0.24",
42
- "umi": "4.0.5"
45
+ "umi": "4.0.8"
43
46
  },
44
47
  "publishConfig": {
45
48
  "access": "public"
@@ -51,13 +54,15 @@
51
54
  "deps": [
52
55
  "@mdx-js/mdx",
53
56
  "rehype-slug",
54
- "remark-gfm"
57
+ "remark-gfm",
58
+ "rehype-autolink-headings"
55
59
  ],
56
60
  "externals": {},
57
61
  "excludeDtsDeps": [
58
62
  "@mdx-js/mdx",
59
63
  "rehype-slug",
60
- "remark-gfm"
64
+ "remark-gfm",
65
+ "rehype-autolink-headings"
61
66
  ]
62
67
  }
63
68
  }
@@ -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
- }