@vuepress/theme-default 2.0.0-rc.28 → 2.0.0-rc.30
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/lib/client/components/HomeHero.vue +2 -2
- package/lib/client/components/NavbarDropdown.vue +4 -5
- package/lib/client/components/NavbarItems.vue +4 -4
- package/lib/client/components/PageMeta.vue +4 -5
- package/lib/client/components/PageNav.vue +13 -10
- package/lib/client/components/SidebarItem.vue +2 -3
- package/lib/client/composables/useSidebarItems.js +2 -2
- package/lib/client/config.js +0 -8
- package/lib/client/layouts/Layout.vue +7 -0
- package/lib/client/styles/custom-container.scss +4 -8
- package/lib/client/styles/external-link-icon.scss +33 -0
- package/lib/client/styles/index.scss +1 -0
- package/lib/client/styles/vars.scss +4 -5
- package/lib/client/utils/getNavLink.d.ts +3 -3
- package/lib/client/utils/getNavLink.js +2 -2
- package/lib/node/defaultTheme.js +9 -21
- package/lib/node/utils/resolveContainerPluginOptions.d.ts +3 -3
- package/lib/node/utils/resolveContainerPluginOptions.js +2 -2
- package/lib/shared/nav.d.ts +3 -11
- package/lib/shared/options.d.ts +7 -5
- package/lib/shared/page.d.ts +5 -3
- package/package.json +18 -19
- package/lib/client/components/AutoLink.vue +0 -115
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import AutoLink from '@theme/AutoLink.vue'
|
|
3
2
|
import type { FunctionalComponent } from 'vue'
|
|
4
3
|
import { computed, h } from 'vue'
|
|
5
4
|
import {
|
|
5
|
+
AutoLink,
|
|
6
6
|
ClientOnly,
|
|
7
7
|
usePageFrontmatter,
|
|
8
8
|
useSiteLocaleData,
|
|
@@ -90,7 +90,7 @@ const HomeHeroImage: FunctionalComponent = () => {
|
|
|
90
90
|
:key="action.text"
|
|
91
91
|
class="action-button"
|
|
92
92
|
:class="[action.type]"
|
|
93
|
-
:
|
|
93
|
+
:config="action"
|
|
94
94
|
/>
|
|
95
95
|
</p>
|
|
96
96
|
</header>
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import AutoLink from '@theme/AutoLink.vue'
|
|
3
2
|
import DropdownTransition from '@theme/DropdownTransition.vue'
|
|
4
3
|
import { computed, ref, toRefs, watch } from 'vue'
|
|
5
4
|
import type { PropType } from 'vue'
|
|
6
|
-
import { useRoute } from 'vuepress/client'
|
|
5
|
+
import { AutoLink, useRoute } from 'vuepress/client'
|
|
7
6
|
import type { NavbarItem, ResolvedNavbarItem } from '../../shared/index.js'
|
|
8
7
|
|
|
9
8
|
const props = defineProps({
|
|
@@ -82,7 +81,7 @@ const isLastItemOfArray = (item: unknown, arr: unknown[]): boolean =>
|
|
|
82
81
|
<h4 class="navbar-dropdown-subtitle">
|
|
83
82
|
<AutoLink
|
|
84
83
|
v-if="child.link"
|
|
85
|
-
:
|
|
84
|
+
:config="child"
|
|
86
85
|
@focusout="
|
|
87
86
|
isLastItemOfArray(child, item.children) &&
|
|
88
87
|
child.children.length === 0 &&
|
|
@@ -100,7 +99,7 @@ const isLastItemOfArray = (item: unknown, arr: unknown[]): boolean =>
|
|
|
100
99
|
class="navbar-dropdown-subitem"
|
|
101
100
|
>
|
|
102
101
|
<AutoLink
|
|
103
|
-
:
|
|
102
|
+
:config="grandchild"
|
|
104
103
|
@focusout="
|
|
105
104
|
isLastItemOfArray(grandchild, child.children) &&
|
|
106
105
|
isLastItemOfArray(child, item.children) &&
|
|
@@ -113,7 +112,7 @@ const isLastItemOfArray = (item: unknown, arr: unknown[]): boolean =>
|
|
|
113
112
|
|
|
114
113
|
<template v-else>
|
|
115
114
|
<AutoLink
|
|
116
|
-
:
|
|
115
|
+
:config="child"
|
|
117
116
|
@focusout="
|
|
118
117
|
isLastItemOfArray(child, item.children) && (open = false)
|
|
119
118
|
"
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import AutoLink from '@theme/AutoLink.vue'
|
|
3
2
|
import NavbarDropdown from '@theme/NavbarDropdown.vue'
|
|
4
3
|
import { useRoutePaths } from '@vuepress/helper/client'
|
|
5
4
|
import { computed, ref } from 'vue'
|
|
6
5
|
import type { ComputedRef } from 'vue'
|
|
7
6
|
import {
|
|
7
|
+
AutoLink,
|
|
8
8
|
useRoute,
|
|
9
9
|
useRouteLocale,
|
|
10
10
|
useSiteData,
|
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
useThemeLocaleData,
|
|
23
23
|
useUpdateDeviceStatus,
|
|
24
24
|
} from '../composables/index.js'
|
|
25
|
-
import {
|
|
25
|
+
import { getAutoLink, resolveRepoType } from '../utils/index.js'
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* Get navbar config of select language dropdown
|
|
@@ -135,7 +135,7 @@ const resolveNavbarItem = (
|
|
|
135
135
|
item: NavbarItem | NavbarGroup | string,
|
|
136
136
|
): ResolvedNavbarItem => {
|
|
137
137
|
if (isString(item)) {
|
|
138
|
-
return
|
|
138
|
+
return getAutoLink(item)
|
|
139
139
|
}
|
|
140
140
|
if ((item as NavbarGroup).children) {
|
|
141
141
|
return {
|
|
@@ -192,7 +192,7 @@ const navbarLabel = computed(() => {
|
|
|
192
192
|
:item="item"
|
|
193
193
|
:class="isMobile ? 'mobile' : ''"
|
|
194
194
|
/>
|
|
195
|
-
<AutoLink v-else :
|
|
195
|
+
<AutoLink v-else :config="item" />
|
|
196
196
|
</div>
|
|
197
197
|
</nav>
|
|
198
198
|
</template>
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import AutoLink from '@theme/AutoLink.vue'
|
|
3
2
|
import { computed } from 'vue'
|
|
4
3
|
import type { ComputedRef } from 'vue'
|
|
5
|
-
import { usePageData, usePageFrontmatter } from 'vuepress/client'
|
|
4
|
+
import { AutoLink, usePageData, usePageFrontmatter } from 'vuepress/client'
|
|
5
|
+
import type { AutoLinkConfig } from 'vuepress/client'
|
|
6
6
|
import type {
|
|
7
7
|
DefaultThemeNormalPageFrontmatter,
|
|
8
8
|
DefaultThemePageData,
|
|
9
|
-
NavLink,
|
|
10
9
|
} from '../../shared/index.js'
|
|
11
10
|
import { useThemeLocaleData } from '../composables/index.js'
|
|
12
11
|
import { resolveEditLink } from '../utils/index.js'
|
|
13
12
|
|
|
14
|
-
const useEditNavLink = (): ComputedRef<null |
|
|
13
|
+
const useEditNavLink = (): ComputedRef<null | AutoLinkConfig> => {
|
|
15
14
|
const themeLocale = useThemeLocaleData()
|
|
16
15
|
const page = usePageData<DefaultThemePageData>()
|
|
17
16
|
const frontmatter = usePageFrontmatter<DefaultThemeNormalPageFrontmatter>()
|
|
@@ -96,7 +95,7 @@ const contributors = useContributors()
|
|
|
96
95
|
<template>
|
|
97
96
|
<footer class="vp-page-meta">
|
|
98
97
|
<div v-if="editNavLink" class="vp-meta-item edit-link">
|
|
99
|
-
<AutoLink class="label" :
|
|
98
|
+
<AutoLink class="label" :config="editNavLink">
|
|
100
99
|
<template #before>
|
|
101
100
|
<svg class="icon" viewBox="0 0 1024 1024">
|
|
102
101
|
<g fill="currentColor">
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import AutoLink from '@theme/AutoLink.vue'
|
|
3
|
-
import { resolveRoute } from '@vuepress/helper/client'
|
|
4
2
|
import { useEventListener } from '@vueuse/core'
|
|
5
3
|
import { computed } from 'vue'
|
|
6
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
AutoLink,
|
|
6
|
+
resolveRoute,
|
|
7
|
+
usePageFrontmatter,
|
|
8
|
+
useRoute,
|
|
9
|
+
} from 'vuepress/client'
|
|
10
|
+
import type { AutoLinkConfig } from 'vuepress/client'
|
|
7
11
|
import { isPlainObject, isString } from 'vuepress/shared'
|
|
8
12
|
import type {
|
|
9
13
|
DefaultThemeNormalPageFrontmatter,
|
|
10
|
-
NavLink,
|
|
11
14
|
ResolvedSidebarItem,
|
|
12
15
|
} from '../../shared/index.js'
|
|
13
16
|
import {
|
|
@@ -22,7 +25,7 @@ import {
|
|
|
22
25
|
const resolveFromFrontmatterConfig = (
|
|
23
26
|
conf: unknown,
|
|
24
27
|
current: string,
|
|
25
|
-
): null | false |
|
|
28
|
+
): null | false | AutoLinkConfig => {
|
|
26
29
|
if (conf === false) {
|
|
27
30
|
return null
|
|
28
31
|
}
|
|
@@ -40,7 +43,7 @@ const resolveFromFrontmatterConfig = (
|
|
|
40
43
|
}
|
|
41
44
|
}
|
|
42
45
|
|
|
43
|
-
if (isPlainObject<
|
|
46
|
+
if (isPlainObject<AutoLinkConfig>(conf)) {
|
|
44
47
|
return {
|
|
45
48
|
...conf,
|
|
46
49
|
link: resolveRoute(conf.link, current).path,
|
|
@@ -57,14 +60,14 @@ const resolveFromSidebarItems = (
|
|
|
57
60
|
sidebarItems: ResolvedSidebarItem[],
|
|
58
61
|
currentPath: string,
|
|
59
62
|
offset: number,
|
|
60
|
-
): null |
|
|
63
|
+
): null | AutoLinkConfig => {
|
|
61
64
|
const index = sidebarItems.findIndex((item) => item.link === currentPath)
|
|
62
65
|
if (index !== -1) {
|
|
63
66
|
const targetItem = sidebarItems[index + offset]
|
|
64
67
|
if (!targetItem?.link) {
|
|
65
68
|
return null
|
|
66
69
|
}
|
|
67
|
-
return targetItem as
|
|
70
|
+
return targetItem as AutoLinkConfig
|
|
68
71
|
}
|
|
69
72
|
|
|
70
73
|
for (const item of sidebarItems) {
|
|
@@ -140,7 +143,7 @@ useEventListener('keydown', (event): void => {
|
|
|
140
143
|
class="vp-page-nav"
|
|
141
144
|
:aria-label="navbarLabel"
|
|
142
145
|
>
|
|
143
|
-
<AutoLink v-if="prevNavLink" class="prev" :
|
|
146
|
+
<AutoLink v-if="prevNavLink" class="prev" :config="prevNavLink">
|
|
144
147
|
<div class="hint">
|
|
145
148
|
<span class="arrow left" />
|
|
146
149
|
{{ themeLocale.prev ?? 'Prev' }}
|
|
@@ -150,7 +153,7 @@ useEventListener('keydown', (event): void => {
|
|
|
150
153
|
</div>
|
|
151
154
|
</AutoLink>
|
|
152
155
|
|
|
153
|
-
<AutoLink v-if="nextNavLink" class="next" :
|
|
156
|
+
<AutoLink v-if="nextNavLink" class="next" :config="nextNavLink">
|
|
154
157
|
<div class="hint">
|
|
155
158
|
{{ themeLocale.next ?? 'Next' }}
|
|
156
159
|
<span class="arrow right" />
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import AutoLink from '@theme/AutoLink.vue'
|
|
3
2
|
import DropdownTransition from '@theme/DropdownTransition.vue'
|
|
4
3
|
import { useToggle } from '@vueuse/core'
|
|
5
4
|
import { computed, nextTick, onBeforeUnmount, toRefs } from 'vue'
|
|
6
5
|
import type { PropType } from 'vue'
|
|
7
|
-
import { useRoute, useRouter } from 'vuepress/client'
|
|
6
|
+
import { AutoLink, useRoute, useRouter } from 'vuepress/client'
|
|
8
7
|
import type { ResolvedSidebarItem } from '../../shared/index.js'
|
|
9
8
|
import { isActiveSidebarItem } from '../utils/index.js'
|
|
10
9
|
|
|
@@ -57,7 +56,7 @@ onBeforeUnmount(() => {
|
|
|
57
56
|
|
|
58
57
|
<template>
|
|
59
58
|
<li>
|
|
60
|
-
<AutoLink v-if="item.link" :class="itemClass" :
|
|
59
|
+
<AutoLink v-if="item.link" :class="itemClass" :config="item" />
|
|
61
60
|
<p
|
|
62
61
|
v-else
|
|
63
62
|
tabindex="0"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { computed, inject, provide } from 'vue';
|
|
2
2
|
import { usePageData, usePageFrontmatter, useRoute } from 'vuepress/client';
|
|
3
3
|
import { isPlainObject, isString, resolveLocalePath } from 'vuepress/shared';
|
|
4
|
-
import {
|
|
4
|
+
import { getAutoLink } from '../utils/index.js';
|
|
5
5
|
import { useThemeLocaleData } from './useThemeData.js';
|
|
6
6
|
export const sidebarItemsSymbol = Symbol('sidebarItems');
|
|
7
7
|
/**
|
|
@@ -78,7 +78,7 @@ export const resolveArraySidebarItems = (page, path, sidebarConfig, sidebarDepth
|
|
|
78
78
|
const handleChildItem = (item) => {
|
|
79
79
|
let childItem;
|
|
80
80
|
if (isString(item)) {
|
|
81
|
-
childItem =
|
|
81
|
+
childItem = getAutoLink(item);
|
|
82
82
|
}
|
|
83
83
|
else {
|
|
84
84
|
childItem = item;
|
package/lib/client/config.js
CHANGED
|
@@ -14,14 +14,6 @@ export default defineClientConfig({
|
|
|
14
14
|
app.component('CodeGroup', CodeGroup);
|
|
15
15
|
if (!hasGlobalComponent('CodeGroupItem'))
|
|
16
16
|
app.component('CodeGroupItem', CodeGroupItem);
|
|
17
|
-
// compat with @vuepress/plugin-external-link-icon
|
|
18
|
-
app.component('AutoLinkExternalIcon', () => {
|
|
19
|
-
const ExternalLinkIcon = app.component('ExternalLinkIcon');
|
|
20
|
-
if (ExternalLinkIcon) {
|
|
21
|
-
return h(ExternalLinkIcon);
|
|
22
|
-
}
|
|
23
|
-
return null;
|
|
24
|
-
});
|
|
25
17
|
// compat with @vuepress/plugin-docsearch and @vuepress/plugin-search
|
|
26
18
|
app.component('NavbarSearch', () => {
|
|
27
19
|
const SearchComponent = app.component('Docsearch') || app.component('SearchBox');
|
|
@@ -59,12 +59,19 @@ const onTouchEnd = (e): void => {
|
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
// external-link-icon
|
|
63
|
+
const enableExternalLinkIcon = computed(
|
|
64
|
+
() =>
|
|
65
|
+
frontmatter.value.externalLinkIcon ?? themeLocale.externalLinkIcon ?? true,
|
|
66
|
+
)
|
|
67
|
+
|
|
62
68
|
// classes
|
|
63
69
|
const containerClass = computed(() => [
|
|
64
70
|
{
|
|
65
71
|
'no-navbar': !shouldShowNavbar.value,
|
|
66
72
|
'no-sidebar': !sidebarItems.value.length,
|
|
67
73
|
'sidebar-open': isSidebarOpen.value,
|
|
74
|
+
'external-link-icon': enableExternalLinkIcon.value,
|
|
68
75
|
},
|
|
69
76
|
frontmatter.value.pageClass,
|
|
70
77
|
])
|
|
@@ -39,6 +39,8 @@
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
&.warning {
|
|
42
|
+
--external-link-icon-color: var(--c-warning-text-quote);
|
|
43
|
+
|
|
42
44
|
border-color: var(--c-warning);
|
|
43
45
|
background-color: var(--c-warning-bg);
|
|
44
46
|
color: var(--c-warning-text);
|
|
@@ -68,13 +70,11 @@
|
|
|
68
70
|
background-color: var(--c-warning-bg-lighter);
|
|
69
71
|
}
|
|
70
72
|
}
|
|
71
|
-
|
|
72
|
-
.external-link-icon {
|
|
73
|
-
--external-link-icon-color: var(--c-warning-text-quote);
|
|
74
|
-
}
|
|
75
73
|
}
|
|
76
74
|
|
|
77
75
|
&.danger {
|
|
76
|
+
--external-link-icon-color: var(--c-danger-text-quote);
|
|
77
|
+
|
|
78
78
|
border-color: var(--c-danger);
|
|
79
79
|
background-color: var(--c-danger-bg);
|
|
80
80
|
color: var(--c-danger-text);
|
|
@@ -104,10 +104,6 @@
|
|
|
104
104
|
background-color: var(--c-danger-bg-lighter);
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
|
-
|
|
108
|
-
.external-link-icon {
|
|
109
|
-
--external-link-icon-color: var(--c-danger-text-quote);
|
|
110
|
-
}
|
|
111
107
|
}
|
|
112
108
|
|
|
113
109
|
&.details {
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
@mixin external-link-icon {
|
|
2
|
+
&::after {
|
|
3
|
+
content: '';
|
|
4
|
+
display: inline-block;
|
|
5
|
+
margin-top: -1px;
|
|
6
|
+
margin-left: 4px;
|
|
7
|
+
width: 11px;
|
|
8
|
+
height: 11px;
|
|
9
|
+
background: var(--external-link-icon-color);
|
|
10
|
+
flex-shrink: 0;
|
|
11
|
+
-webkit-mask-image: var(--external-link-icon);
|
|
12
|
+
mask-image: var(--external-link-icon);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.vp-external-link-icon {
|
|
17
|
+
@include external-link-icon;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.external-link-icon {
|
|
21
|
+
.external-link {
|
|
22
|
+
@include external-link-icon;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.theme-default-content {
|
|
26
|
+
a[href*="://"],
|
|
27
|
+
a[target=_blank] {
|
|
28
|
+
&:not(.no-external-link-icon) {
|
|
29
|
+
@include external-link-icon;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -91,6 +91,10 @@
|
|
|
91
91
|
--sidebar-width-mobile: calc(var(--sidebar-width) * 0.82);
|
|
92
92
|
--content-width: 740px;
|
|
93
93
|
--homepage-width: 960px;
|
|
94
|
+
|
|
95
|
+
// external-link-icon
|
|
96
|
+
--external-link-icon: url("data:image/svg+xml, %3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' %3E%3Cpath d='M0 0h24v24H0V0z' fill='none' /%3E%3Cpath d='M9 5v2h6.59L4 18.59 5.41 20 17 8.41V15h2V5H9z' /%3E%3C/svg%3E");
|
|
97
|
+
--external-link-icon-color: var(--c-text-quote);
|
|
94
98
|
}
|
|
95
99
|
|
|
96
100
|
// plugin-back-to-top
|
|
@@ -138,11 +142,6 @@
|
|
|
138
142
|
--docsearch-footer-background: var(--c-bg);
|
|
139
143
|
}
|
|
140
144
|
|
|
141
|
-
// plugin-external-link-icon
|
|
142
|
-
.external-link-icon {
|
|
143
|
-
--external-link-icon-color: var(--c-text-quote);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
145
|
// plugin-medium-zoom
|
|
147
146
|
.medium-zoom-overlay {
|
|
148
147
|
--medium-zoom-bg-color: var(--c-bg);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AutoLinkConfig } from 'vuepress/client';
|
|
2
2
|
/**
|
|
3
|
-
* Resolve
|
|
3
|
+
* Resolve AutoLink props from string
|
|
4
4
|
*
|
|
5
5
|
* @example
|
|
6
6
|
* - Input: '/README.md'
|
|
7
7
|
* - Output: { text: 'Home', link: '/' }
|
|
8
8
|
*/
|
|
9
|
-
export declare const
|
|
9
|
+
export declare const getAutoLink: (config: string) => AutoLinkConfig;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { resolveRoute } from 'vuepress/client';
|
|
2
2
|
/**
|
|
3
|
-
* Resolve
|
|
3
|
+
* Resolve AutoLink props from string
|
|
4
4
|
*
|
|
5
5
|
* @example
|
|
6
6
|
* - Input: '/README.md'
|
|
7
7
|
* - Output: { text: 'Home', link: '/' }
|
|
8
8
|
*/
|
|
9
|
-
export const
|
|
9
|
+
export const getAutoLink = (config) => {
|
|
10
10
|
const { notFound, meta, path } = resolveRoute(config);
|
|
11
11
|
return notFound
|
|
12
12
|
? { text: path, link: path }
|
package/lib/node/defaultTheme.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { activeHeaderLinksPlugin } from '@vuepress/plugin-active-header-links';
|
|
2
2
|
import { backToTopPlugin } from '@vuepress/plugin-back-to-top';
|
|
3
|
-
import { containerPlugin } from '@vuepress/plugin-container';
|
|
4
3
|
import { copyCodePlugin } from '@vuepress/plugin-copy-code';
|
|
5
|
-
import { externalLinkIconPlugin } from '@vuepress/plugin-external-link-icon';
|
|
6
4
|
import { gitPlugin } from '@vuepress/plugin-git';
|
|
7
5
|
import { linksCheckPlugin } from '@vuepress/plugin-links-check';
|
|
6
|
+
import { markdownContainerPlugin } from '@vuepress/plugin-markdown-container';
|
|
8
7
|
import { mediumZoomPlugin } from '@vuepress/plugin-medium-zoom';
|
|
9
8
|
import { nprogressPlugin } from '@vuepress/plugin-nprogress';
|
|
10
9
|
import { palettePlugin } from '@vuepress/plugin-palette';
|
|
@@ -14,7 +13,7 @@ import { sitemapPlugin } from '@vuepress/plugin-sitemap';
|
|
|
14
13
|
import { themeDataPlugin } from '@vuepress/plugin-theme-data';
|
|
15
14
|
import { isPlainObject } from 'vuepress/shared';
|
|
16
15
|
import { fs, getDirname, path } from 'vuepress/utils';
|
|
17
|
-
import { assignDefaultLocaleOptions,
|
|
16
|
+
import { assignDefaultLocaleOptions, resolveMarkdownContainerPluginOptions, } from './utils/index.js';
|
|
18
17
|
const __dirname = getDirname(import.meta.url);
|
|
19
18
|
export const defaultTheme = ({ hostname, themePlugins = {}, ...localeOptions } = {}) => {
|
|
20
19
|
assignDefaultLocaleOptions(localeOptions);
|
|
@@ -60,48 +59,37 @@ export const defaultTheme = ({ hostname, themePlugins = {}, ...localeOptions } =
|
|
|
60
59
|
: {}),
|
|
61
60
|
})
|
|
62
61
|
: [],
|
|
63
|
-
// @vuepress/plugin-container
|
|
62
|
+
// @vuepress/plugin-markdown-container
|
|
64
63
|
themePlugins.container?.tip !== false
|
|
65
|
-
?
|
|
64
|
+
? markdownContainerPlugin(resolveMarkdownContainerPluginOptions(localeOptions, 'tip'))
|
|
66
65
|
: [],
|
|
67
66
|
themePlugins.container?.warning !== false
|
|
68
|
-
?
|
|
67
|
+
? markdownContainerPlugin(resolveMarkdownContainerPluginOptions(localeOptions, 'warning'))
|
|
69
68
|
: [],
|
|
70
69
|
themePlugins.container?.danger !== false
|
|
71
|
-
?
|
|
70
|
+
? markdownContainerPlugin(resolveMarkdownContainerPluginOptions(localeOptions, 'danger'))
|
|
72
71
|
: [],
|
|
73
72
|
themePlugins.container?.details !== false
|
|
74
|
-
?
|
|
73
|
+
? markdownContainerPlugin({
|
|
75
74
|
type: 'details',
|
|
76
75
|
before: (info) => `<details class="custom-container details">${info ? `<summary>${info}</summary>` : ''}\n`,
|
|
77
76
|
after: () => '</details>\n',
|
|
78
77
|
})
|
|
79
78
|
: [],
|
|
80
79
|
themePlugins.container?.codeGroup !== false
|
|
81
|
-
?
|
|
80
|
+
? markdownContainerPlugin({
|
|
82
81
|
type: 'code-group',
|
|
83
82
|
before: () => `<CodeGroup>\n`,
|
|
84
83
|
after: () => '</CodeGroup>\n',
|
|
85
84
|
})
|
|
86
85
|
: [],
|
|
87
86
|
themePlugins.container?.codeGroupItem !== false
|
|
88
|
-
?
|
|
87
|
+
? markdownContainerPlugin({
|
|
89
88
|
type: 'code-group-item',
|
|
90
89
|
before: (info) => `<CodeGroupItem title="${info}">\n`,
|
|
91
90
|
after: () => '</CodeGroupItem>\n',
|
|
92
91
|
})
|
|
93
92
|
: [],
|
|
94
|
-
// @vuepress/plugin-external-link-icon
|
|
95
|
-
themePlugins.externalLinkIcon !== false
|
|
96
|
-
? externalLinkIconPlugin({
|
|
97
|
-
locales: Object.entries(localeOptions.locales || {}).reduce((result, [key, value]) => {
|
|
98
|
-
result[key] = {
|
|
99
|
-
openInNewWindow: value.openInNewWindow ?? localeOptions.openInNewWindow,
|
|
100
|
-
};
|
|
101
|
-
return result;
|
|
102
|
-
}, {}),
|
|
103
|
-
})
|
|
104
|
-
: [],
|
|
105
93
|
// @vuepress/plugin-git
|
|
106
94
|
themePlugins.git !== false
|
|
107
95
|
? gitPlugin({
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { MarkdownContainerPluginOptions } from '@vuepress/plugin-markdown-container';
|
|
2
2
|
import type { DefaultThemeData } from '../../shared/index.js';
|
|
3
3
|
/**
|
|
4
|
-
* Resolve options for @vuepress/plugin-container
|
|
4
|
+
* Resolve options for @vuepress/plugin-markdown-container
|
|
5
5
|
*
|
|
6
6
|
* For custom containers default title
|
|
7
7
|
*/
|
|
8
|
-
export declare const
|
|
8
|
+
export declare const resolveMarkdownContainerPluginOptions: (localeOptions: DefaultThemeData, type: 'tip' | 'warning' | 'danger') => MarkdownContainerPluginOptions;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Resolve options for @vuepress/plugin-container
|
|
2
|
+
* Resolve options for @vuepress/plugin-markdown-container
|
|
3
3
|
*
|
|
4
4
|
* For custom containers default title
|
|
5
5
|
*/
|
|
6
|
-
export const
|
|
6
|
+
export const resolveMarkdownContainerPluginOptions = (localeOptions, type) => {
|
|
7
7
|
const locales = Object.entries(localeOptions.locales || {}).reduce((result, [key, value]) => {
|
|
8
8
|
result[key] = {
|
|
9
9
|
defaultInfo: value?.[type] ?? localeOptions[type],
|
package/lib/shared/nav.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { AutoLinkConfig } from 'vuepress/client';
|
|
1
2
|
/**
|
|
2
3
|
* Base nav item, displayed as text
|
|
3
4
|
*/
|
|
@@ -11,26 +12,17 @@ export interface NavItem {
|
|
|
11
12
|
export interface NavGroup<T> extends NavItem {
|
|
12
13
|
children: T[];
|
|
13
14
|
}
|
|
14
|
-
/**
|
|
15
|
-
* Props for `<AutoLink>`
|
|
16
|
-
*/
|
|
17
|
-
export interface NavLink extends NavItem {
|
|
18
|
-
link: string;
|
|
19
|
-
rel?: string;
|
|
20
|
-
target?: string;
|
|
21
|
-
activeMatch?: string;
|
|
22
|
-
}
|
|
23
15
|
/**
|
|
24
16
|
* Navbar types
|
|
25
17
|
*/
|
|
26
|
-
export type NavbarItem =
|
|
18
|
+
export type NavbarItem = AutoLinkConfig;
|
|
27
19
|
export type NavbarGroup = NavGroup<NavbarGroup | NavbarItem | string>;
|
|
28
20
|
export type NavbarConfig = (NavbarItem | NavbarGroup | string)[];
|
|
29
21
|
export type ResolvedNavbarItem = NavbarItem | NavGroup<ResolvedNavbarItem>;
|
|
30
22
|
/**
|
|
31
23
|
* Sidebar types
|
|
32
24
|
*/
|
|
33
|
-
export type SidebarItem = NavItem & Partial<
|
|
25
|
+
export type SidebarItem = NavItem & Partial<AutoLinkConfig>;
|
|
34
26
|
export type SidebarGroup = SidebarItem & NavGroup<SidebarItem | SidebarGroup | string> & {
|
|
35
27
|
collapsible?: boolean;
|
|
36
28
|
};
|
package/lib/shared/options.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export interface DefaultThemePluginsOptions {
|
|
|
16
16
|
*/
|
|
17
17
|
backToTop?: BackToTopPluginOptions | boolean;
|
|
18
18
|
/**
|
|
19
|
-
* Enable @vuepress/plugin-container or not
|
|
19
|
+
* Enable @vuepress/plugin-markdown-container or not
|
|
20
20
|
*/
|
|
21
21
|
container?: {
|
|
22
22
|
tip?: boolean;
|
|
@@ -30,10 +30,6 @@ export interface DefaultThemePluginsOptions {
|
|
|
30
30
|
* Enable @vuepress/plugin-copy-code or not
|
|
31
31
|
*/
|
|
32
32
|
copyCode?: CopyCodePluginOptions | boolean;
|
|
33
|
-
/**
|
|
34
|
-
* Enable @vuepress/plugin-external-link-icon or not
|
|
35
|
-
*/
|
|
36
|
-
externalLinkIcon?: boolean;
|
|
37
33
|
/**
|
|
38
34
|
* Enable @vuepress/plugin-git or not
|
|
39
35
|
*/
|
|
@@ -78,6 +74,12 @@ export interface DefaultThemeLocaleData extends LocaleData {
|
|
|
78
74
|
* @default true
|
|
79
75
|
*/
|
|
80
76
|
colorModeSwitch?: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Whether show external link icon
|
|
79
|
+
*
|
|
80
|
+
* @default true
|
|
81
|
+
*/
|
|
82
|
+
externalLinkIcon?: boolean;
|
|
81
83
|
/**
|
|
82
84
|
* Home path of current locale
|
|
83
85
|
*
|
package/lib/shared/page.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { GitPluginPageData } from '@vuepress/plugin-git';
|
|
2
|
-
import type {
|
|
2
|
+
import type { AutoLinkConfig } from 'vuepress/client';
|
|
3
|
+
import type { SidebarConfig } from './nav.js';
|
|
3
4
|
export interface DefaultThemePageData extends GitPluginPageData {
|
|
4
5
|
filePathRelative: string | null;
|
|
5
6
|
}
|
|
@@ -7,6 +8,7 @@ export interface DefaultThemePageFrontmatter {
|
|
|
7
8
|
home?: boolean;
|
|
8
9
|
navbar?: boolean;
|
|
9
10
|
pageClass?: string;
|
|
11
|
+
externalLinkIcon?: boolean;
|
|
10
12
|
}
|
|
11
13
|
export interface DefaultThemeHomePageFrontmatter extends DefaultThemePageFrontmatter {
|
|
12
14
|
home: true;
|
|
@@ -36,6 +38,6 @@ export interface DefaultThemeNormalPageFrontmatter extends DefaultThemePageFront
|
|
|
36
38
|
contributors?: boolean;
|
|
37
39
|
sidebar?: 'auto' | false | SidebarConfig;
|
|
38
40
|
sidebarDepth?: number;
|
|
39
|
-
prev?: string |
|
|
40
|
-
next?: string |
|
|
41
|
+
prev?: string | AutoLinkConfig;
|
|
42
|
+
next?: string | AutoLinkConfig;
|
|
41
43
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vuepress/theme-default",
|
|
3
|
-
"version": "2.0.0-rc.
|
|
3
|
+
"version": "2.0.0-rc.30",
|
|
4
4
|
"description": "Default theme of VuePress",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vuepress-theme",
|
|
@@ -42,28 +42,27 @@
|
|
|
42
42
|
"copy": "cpx \"src/**/*.{d.ts,vue,scss}\" lib"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@vuepress/helper": "~2.0.0-rc.
|
|
46
|
-
"@vuepress/plugin-active-header-links": "~2.0.0-rc.
|
|
47
|
-
"@vuepress/plugin-back-to-top": "~2.0.0-rc.
|
|
48
|
-
"@vuepress/plugin-
|
|
49
|
-
"@vuepress/plugin-
|
|
50
|
-
"@vuepress/plugin-
|
|
51
|
-
"@vuepress/plugin-
|
|
52
|
-
"@vuepress/plugin-
|
|
53
|
-
"@vuepress/plugin-
|
|
54
|
-
"@vuepress/plugin-
|
|
55
|
-
"@vuepress/plugin-
|
|
56
|
-
"@vuepress/plugin-
|
|
57
|
-
"@vuepress/plugin-
|
|
58
|
-
"@vuepress/plugin-
|
|
59
|
-
"@vuepress/plugin-theme-data": "~2.0.0-rc.28",
|
|
45
|
+
"@vuepress/helper": "~2.0.0-rc.30",
|
|
46
|
+
"@vuepress/plugin-active-header-links": "~2.0.0-rc.30",
|
|
47
|
+
"@vuepress/plugin-back-to-top": "~2.0.0-rc.30",
|
|
48
|
+
"@vuepress/plugin-copy-code": "~2.0.0-rc.30",
|
|
49
|
+
"@vuepress/plugin-git": "~2.0.0-rc.30",
|
|
50
|
+
"@vuepress/plugin-links-check": "~2.0.0-rc.30",
|
|
51
|
+
"@vuepress/plugin-markdown-container": "~2.0.0-rc.30",
|
|
52
|
+
"@vuepress/plugin-medium-zoom": "~2.0.0-rc.30",
|
|
53
|
+
"@vuepress/plugin-nprogress": "~2.0.0-rc.30",
|
|
54
|
+
"@vuepress/plugin-palette": "~2.0.0-rc.30",
|
|
55
|
+
"@vuepress/plugin-prismjs": "~2.0.0-rc.30",
|
|
56
|
+
"@vuepress/plugin-seo": "~2.0.0-rc.30",
|
|
57
|
+
"@vuepress/plugin-sitemap": "~2.0.0-rc.30",
|
|
58
|
+
"@vuepress/plugin-theme-data": "~2.0.0-rc.30",
|
|
60
59
|
"@vueuse/core": "^10.9.0",
|
|
61
|
-
"sass": "^1.77.
|
|
60
|
+
"sass": "^1.77.1",
|
|
62
61
|
"vue": "^3.4.27"
|
|
63
62
|
},
|
|
64
63
|
"peerDependencies": {
|
|
65
64
|
"sass-loader": "^14.0.0",
|
|
66
|
-
"vuepress": "2.0.0-rc.
|
|
65
|
+
"vuepress": "2.0.0-rc.11"
|
|
67
66
|
},
|
|
68
67
|
"peerDependenciesMeta": {
|
|
69
68
|
"sass-loader": {
|
|
@@ -73,5 +72,5 @@
|
|
|
73
72
|
"publishConfig": {
|
|
74
73
|
"access": "public"
|
|
75
74
|
},
|
|
76
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "e84a9e154e119525784f6934f06a795029798f8f"
|
|
77
76
|
}
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
import { computed, toRefs } from 'vue'
|
|
3
|
-
import type { PropType } from 'vue'
|
|
4
|
-
import { useRoute, useSiteData } from 'vuepress/client'
|
|
5
|
-
import { isLinkHttp, isLinkWithProtocol } from 'vuepress/shared'
|
|
6
|
-
import type { NavLink } from '../../shared/index.js'
|
|
7
|
-
|
|
8
|
-
defineOptions({
|
|
9
|
-
inheritAttrs: false,
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
const props = defineProps({
|
|
13
|
-
item: {
|
|
14
|
-
type: Object as PropType<NavLink>,
|
|
15
|
-
required: true,
|
|
16
|
-
},
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
defineSlots<{
|
|
20
|
-
before?: (props: Record<never, never>) => any
|
|
21
|
-
after?: (props: Record<never, never>) => any
|
|
22
|
-
}>()
|
|
23
|
-
|
|
24
|
-
const route = useRoute()
|
|
25
|
-
const site = useSiteData()
|
|
26
|
-
const { item } = toRefs(props)
|
|
27
|
-
|
|
28
|
-
// if the link has http protocol
|
|
29
|
-
const hasHttpProtocol = computed(() => isLinkHttp(item.value.link))
|
|
30
|
-
// if the link has non-http protocol
|
|
31
|
-
const hasNonHttpProtocol = computed(
|
|
32
|
-
() => !hasHttpProtocol.value && isLinkWithProtocol(item.value.link),
|
|
33
|
-
)
|
|
34
|
-
// resolve the `target` attr
|
|
35
|
-
const linkTarget = computed(() => {
|
|
36
|
-
if (hasNonHttpProtocol.value) return undefined
|
|
37
|
-
if (item.value.target) return item.value.target
|
|
38
|
-
if (hasHttpProtocol.value) return '_blank'
|
|
39
|
-
return undefined
|
|
40
|
-
})
|
|
41
|
-
// if the `target` attr is '_blank'
|
|
42
|
-
const isBlankTarget = computed(() => linkTarget.value === '_blank')
|
|
43
|
-
// is `<RouteLink>` or not
|
|
44
|
-
const isRouteLink = computed(
|
|
45
|
-
() =>
|
|
46
|
-
!hasHttpProtocol.value && !hasNonHttpProtocol.value && !isBlankTarget.value,
|
|
47
|
-
)
|
|
48
|
-
// resolve the `rel` attr
|
|
49
|
-
const linkRel = computed(() => {
|
|
50
|
-
if (hasNonHttpProtocol.value) return undefined
|
|
51
|
-
if (item.value.rel) return item.value.rel
|
|
52
|
-
if (isBlankTarget.value) return 'noopener noreferrer'
|
|
53
|
-
return undefined
|
|
54
|
-
})
|
|
55
|
-
// resolve the `aria-label` attr
|
|
56
|
-
const linkAriaLabel = computed(() => item.value.ariaLabel || item.value.text)
|
|
57
|
-
|
|
58
|
-
// should be active when current route is a subpath of this link
|
|
59
|
-
const shouldBeActiveInSubpath = computed(() => {
|
|
60
|
-
const localeKeys = Object.keys(site.value.locales)
|
|
61
|
-
if (localeKeys.length) {
|
|
62
|
-
return !localeKeys.some((key) => key === item.value.link)
|
|
63
|
-
}
|
|
64
|
-
return item.value.link !== '/'
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
// if this link is active
|
|
68
|
-
const isActive = computed(() => {
|
|
69
|
-
if (!isRouteLink.value) {
|
|
70
|
-
return false
|
|
71
|
-
}
|
|
72
|
-
if (item.value.activeMatch) {
|
|
73
|
-
return new RegExp(item.value.activeMatch).test(route.path)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (!shouldBeActiveInSubpath.value) {
|
|
77
|
-
return false
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// if this link is active in subpath
|
|
81
|
-
return route.path.startsWith(item.value.link)
|
|
82
|
-
})
|
|
83
|
-
</script>
|
|
84
|
-
|
|
85
|
-
<template>
|
|
86
|
-
<RouteLink
|
|
87
|
-
v-if="isRouteLink"
|
|
88
|
-
:active="isActive"
|
|
89
|
-
:to="item.link"
|
|
90
|
-
:aria-label="linkAriaLabel"
|
|
91
|
-
v-bind="$attrs"
|
|
92
|
-
>
|
|
93
|
-
<slot>
|
|
94
|
-
<slot name="before" />
|
|
95
|
-
{{ item.text }}
|
|
96
|
-
<slot name="after" />
|
|
97
|
-
</slot>
|
|
98
|
-
</RouteLink>
|
|
99
|
-
<a
|
|
100
|
-
v-else
|
|
101
|
-
class="external-link"
|
|
102
|
-
:href="item.link"
|
|
103
|
-
:rel="linkRel"
|
|
104
|
-
:target="linkTarget"
|
|
105
|
-
:aria-label="linkAriaLabel"
|
|
106
|
-
v-bind="$attrs"
|
|
107
|
-
>
|
|
108
|
-
<slot>
|
|
109
|
-
<slot name="before" />
|
|
110
|
-
{{ item.text }}
|
|
111
|
-
<AutoLinkExternalIcon v-if="isBlankTarget" />
|
|
112
|
-
<slot name="after" />
|
|
113
|
-
</slot>
|
|
114
|
-
</a>
|
|
115
|
-
</template>
|