@vuepress/theme-default 2.0.0-beta.23 → 2.0.0-beta.27
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/clientAppEnhance.js +1 -1
- package/lib/client/clientAppSetup.js +4 -9
- package/lib/client/components/DropdownLink.vue +83 -98
- package/lib/client/components/DropdownTransition.vue +8 -21
- package/lib/client/components/Home.vue +52 -75
- package/lib/client/components/NavLink.vue +71 -83
- package/lib/client/components/Navbar.vue +18 -9
- package/lib/client/components/NavbarLinks.vue +13 -29
- package/lib/client/components/Page.vue +1 -11
- package/lib/client/components/PageMeta.vue +10 -26
- package/lib/client/components/PageNav.vue +19 -34
- package/lib/client/components/Sidebar.vue +2 -17
- package/lib/client/components/ToggleDarkModeButton.vue +2 -9
- package/lib/client/components/ToggleSidebarButton.vue +17 -19
- package/lib/client/components/global/Badge.vue +16 -22
- package/lib/client/components/global/CodeGroup.js +8 -3
- package/lib/client/components/global/CodeGroupItem.vue +13 -11
- package/lib/client/components/global/OutboundLink.vue +4 -19
- package/lib/client/composables/index.d.ts +0 -2
- package/lib/client/composables/index.js +0 -2
- package/lib/client/composables/useDarkMode.d.ts +12 -2
- package/lib/client/composables/useDarkMode.js +57 -3
- package/lib/client/composables/useResolveRouteWithRedirect.js +1 -1
- package/lib/client/composables/useSidebarItems.d.ts +6 -2
- package/lib/client/composables/useSidebarItems.js +13 -4
- package/lib/client/index.d.ts +1 -1
- package/lib/client/layouts/404.vue +8 -21
- package/lib/client/layouts/Layout.vue +76 -106
- package/lib/client/styles/badge.scss +1 -3
- package/lib/client/styles/code.scss +1 -0
- package/lib/client/styles/custom-container.scss +2 -4
- package/lib/client/styles/home.scss +10 -7
- package/lib/client/styles/layout.scss +24 -3
- package/lib/client/styles/navbar.scss +18 -2
- package/lib/client/styles/normalize.scss +3 -3
- package/lib/client/styles/page.scss +1 -1
- package/lib/client/styles/sidebar.scss +1 -1
- package/lib/client/styles/vars.scss +4 -0
- package/lib/client/utils/resolveEditLink.js +1 -1
- package/lib/node/defaultTheme.js +10 -10
- package/lib/node/utils/assignDefaultLocaleOptions.js +1 -0
- package/lib/node/utils/resolveContainerPluginOptions.d.ts +1 -1
- package/lib/node/utils/resolveGitPluginOptions.d.ts +1 -1
- package/lib/shared/options.d.ts +11 -1
- package/lib/shared/page.d.ts +1 -0
- package/package.json +20 -19
- package/lib/client/composables/useHtmlDarkClass.d.ts +0 -2
- package/lib/client/composables/useHtmlDarkClass.js +0 -14
- package/lib/client/composables/usePrefersColorScheme.d.ts +0 -2
- package/lib/client/composables/usePrefersColorScheme.js +0 -18
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { h } from 'vue';
|
|
2
1
|
import { defineClientAppEnhance } from '@vuepress/client';
|
|
2
|
+
import { h } from 'vue';
|
|
3
3
|
import Badge from './components/global/Badge.vue';
|
|
4
4
|
import CodeGroup from './components/global/CodeGroup';
|
|
5
5
|
import CodeGroupItem from './components/global/CodeGroupItem.vue';
|
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { resolveSidebarItems, sidebarItemsSymbol, useThemeLocaleData, } from './composables';
|
|
1
|
+
import { defineClientAppSetup } from '@vuepress/client';
|
|
2
|
+
import { setupDarkMode, setupSidebarItems } from './composables';
|
|
4
3
|
export default defineClientAppSetup(() => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const themeLocale = useThemeLocaleData();
|
|
8
|
-
const frontmatter = usePageFrontmatter();
|
|
9
|
-
const sidebarItems = computed(() => resolveSidebarItems(frontmatter.value, themeLocale.value));
|
|
10
|
-
provide(sidebarItemsSymbol, sidebarItems);
|
|
4
|
+
setupDarkMode();
|
|
5
|
+
setupSidebarItems();
|
|
11
6
|
});
|
|
@@ -20,122 +20,107 @@
|
|
|
20
20
|
<span class="arrow" :class="open ? 'down' : 'right'" />
|
|
21
21
|
</button>
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
<h4 class="dropdown-subtitle">
|
|
33
|
-
<NavLink
|
|
34
|
-
v-if="child.link"
|
|
35
|
-
:item="child"
|
|
36
|
-
@focusout="
|
|
37
|
-
isLastItemOfArray(child, item.children) &&
|
|
38
|
-
child.children.length === 0 &&
|
|
39
|
-
(open = false)
|
|
40
|
-
"
|
|
41
|
-
/>
|
|
42
|
-
|
|
43
|
-
<span v-else>{{ child.text }}</span>
|
|
44
|
-
</h4>
|
|
45
|
-
|
|
46
|
-
<ul class="dropdown-subitem-wrapper">
|
|
47
|
-
<li
|
|
48
|
-
v-for="grandchild in child.children"
|
|
49
|
-
:key="grandchild.link"
|
|
50
|
-
class="dropdown-subitem"
|
|
51
|
-
>
|
|
23
|
+
<DropdownTransition>
|
|
24
|
+
<ul v-show="open" class="nav-dropdown">
|
|
25
|
+
<li
|
|
26
|
+
v-for="(child, index) in item.children"
|
|
27
|
+
:key="child.link || index"
|
|
28
|
+
class="dropdown-item"
|
|
29
|
+
>
|
|
30
|
+
<template v-if="child.children">
|
|
31
|
+
<h4 class="dropdown-subtitle">
|
|
52
32
|
<NavLink
|
|
53
|
-
|
|
33
|
+
v-if="child.link"
|
|
34
|
+
:item="child"
|
|
54
35
|
@focusout="
|
|
55
|
-
isLastItemOfArray(
|
|
56
|
-
|
|
36
|
+
isLastItemOfArray(child, item.children) &&
|
|
37
|
+
child.children.length === 0 &&
|
|
57
38
|
(open = false)
|
|
58
39
|
"
|
|
59
40
|
/>
|
|
60
|
-
</li>
|
|
61
|
-
</ul>
|
|
62
|
-
</template>
|
|
63
41
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
42
|
+
<span v-else>{{ child.text }}</span>
|
|
43
|
+
</h4>
|
|
44
|
+
|
|
45
|
+
<ul class="dropdown-subitem-wrapper">
|
|
46
|
+
<li
|
|
47
|
+
v-for="grandchild in child.children"
|
|
48
|
+
:key="grandchild.link"
|
|
49
|
+
class="dropdown-subitem"
|
|
50
|
+
>
|
|
51
|
+
<NavLink
|
|
52
|
+
:item="grandchild"
|
|
53
|
+
@focusout="
|
|
54
|
+
isLastItemOfArray(grandchild, child.children) &&
|
|
55
|
+
isLastItemOfArray(child, item.children) &&
|
|
56
|
+
(open = false)
|
|
57
|
+
"
|
|
58
|
+
/>
|
|
59
|
+
</li>
|
|
60
|
+
</ul>
|
|
61
|
+
</template>
|
|
62
|
+
|
|
63
|
+
<template v-else>
|
|
64
|
+
<NavLink
|
|
65
|
+
:item="child"
|
|
66
|
+
@focusout="
|
|
67
|
+
isLastItemOfArray(child, item.children) && (open = false)
|
|
68
|
+
"
|
|
69
|
+
/>
|
|
70
|
+
</template>
|
|
71
|
+
</li>
|
|
72
|
+
</ul>
|
|
73
|
+
</DropdownTransition>
|
|
74
74
|
</div>
|
|
75
75
|
</template>
|
|
76
76
|
|
|
77
|
-
<script lang="ts">
|
|
78
|
-
import { computed,
|
|
77
|
+
<script setup lang="ts">
|
|
78
|
+
import { computed, ref, toRefs, watch } from 'vue'
|
|
79
79
|
import type { PropType } from 'vue'
|
|
80
80
|
import { useRoute } from 'vue-router'
|
|
81
81
|
import type { NavGroup, NavItem } from '../../shared'
|
|
82
|
+
import DropdownTransition from './DropdownTransition.vue'
|
|
82
83
|
import NavLink from './NavLink.vue'
|
|
83
84
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
NavLink,
|
|
89
|
-
},
|
|
90
|
-
|
|
91
|
-
props: {
|
|
92
|
-
item: {
|
|
93
|
-
type: Object as PropType<NavGroup<NavItem>>,
|
|
94
|
-
required: true,
|
|
95
|
-
},
|
|
85
|
+
const props = defineProps({
|
|
86
|
+
item: {
|
|
87
|
+
type: Object as PropType<NavGroup<NavItem>>,
|
|
88
|
+
required: true,
|
|
96
89
|
},
|
|
90
|
+
})
|
|
97
91
|
|
|
98
|
-
|
|
99
|
-
const { item } = toRefs(props)
|
|
100
|
-
const dropdownAriaLabel = computed(
|
|
101
|
-
() => item.value.ariaLabel || item.value.text
|
|
102
|
-
)
|
|
92
|
+
const { item } = toRefs(props)
|
|
103
93
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
() => route.path,
|
|
108
|
-
() => {
|
|
109
|
-
open.value = false
|
|
110
|
-
}
|
|
111
|
-
)
|
|
94
|
+
const dropdownAriaLabel = computed(
|
|
95
|
+
() => item.value.ariaLabel || item.value.text
|
|
96
|
+
)
|
|
112
97
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
const handleDropdown = (e): void => {
|
|
122
|
-
const isTriggerByTab = e.detail === 0
|
|
123
|
-
if (isTriggerByTab) {
|
|
124
|
-
open.value = !open.value
|
|
125
|
-
} else {
|
|
126
|
-
open.value = false
|
|
127
|
-
}
|
|
128
|
-
}
|
|
98
|
+
const open = ref(false)
|
|
99
|
+
const route = useRoute()
|
|
100
|
+
watch(
|
|
101
|
+
() => route.path,
|
|
102
|
+
() => {
|
|
103
|
+
open.value = false
|
|
104
|
+
}
|
|
105
|
+
)
|
|
129
106
|
|
|
130
|
-
|
|
131
|
-
|
|
107
|
+
/**
|
|
108
|
+
* Open the dropdown when user tab and click from keyboard.
|
|
109
|
+
*
|
|
110
|
+
* Use event.detail to detect tab and click from keyboard.
|
|
111
|
+
* The Tab + Click is UIEvent > KeyboardEvent, so the detail is 0.
|
|
112
|
+
*
|
|
113
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/detail
|
|
114
|
+
*/
|
|
115
|
+
const handleDropdown = (e): void => {
|
|
116
|
+
const isTriggerByTab = e.detail === 0
|
|
117
|
+
if (isTriggerByTab) {
|
|
118
|
+
open.value = !open.value
|
|
119
|
+
} else {
|
|
120
|
+
open.value = false
|
|
121
|
+
}
|
|
122
|
+
}
|
|
132
123
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
dropdownAriaLabel,
|
|
136
|
-
handleDropdown,
|
|
137
|
-
isLastItemOfArray,
|
|
138
|
-
}
|
|
139
|
-
},
|
|
140
|
-
})
|
|
124
|
+
const isLastItemOfArray = (item: unknown, arr: unknown[]): boolean =>
|
|
125
|
+
arr[arr.length - 1] === item
|
|
141
126
|
</script>
|
|
@@ -9,26 +9,13 @@
|
|
|
9
9
|
</Transition>
|
|
10
10
|
</template>
|
|
11
11
|
|
|
12
|
-
<script lang="ts">
|
|
13
|
-
|
|
12
|
+
<script setup lang="ts">
|
|
13
|
+
const setHeight = (items): void => {
|
|
14
|
+
// explicitly set height so that it can be transitioned
|
|
15
|
+
items.style.height = items.scrollHeight + 'px'
|
|
16
|
+
}
|
|
14
17
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
setup() {
|
|
19
|
-
const setHeight = (items): void => {
|
|
20
|
-
// explicitly set height so that it can be transitioned
|
|
21
|
-
items.style.height = items.scrollHeight + 'px'
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const unsetHeight = (items): void => {
|
|
25
|
-
items.style.height = ''
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return {
|
|
29
|
-
setHeight,
|
|
30
|
-
unsetHeight,
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
})
|
|
18
|
+
const unsetHeight = (items): void => {
|
|
19
|
+
items.style.height = ''
|
|
20
|
+
}
|
|
34
21
|
</script>
|
|
@@ -41,93 +41,70 @@
|
|
|
41
41
|
</main>
|
|
42
42
|
</template>
|
|
43
43
|
|
|
44
|
-
<script lang="ts">
|
|
45
|
-
import { computed, defineComponent } from 'vue'
|
|
44
|
+
<script setup lang="ts">
|
|
46
45
|
import {
|
|
47
46
|
usePageFrontmatter,
|
|
48
47
|
useSiteLocaleData,
|
|
49
48
|
withBase,
|
|
50
49
|
} from '@vuepress/client'
|
|
51
50
|
import { isArray } from '@vuepress/shared'
|
|
51
|
+
import { computed } from 'vue'
|
|
52
52
|
import type { DefaultThemeHomePageFrontmatter } from '../../shared'
|
|
53
53
|
import NavLink from './NavLink.vue'
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
const frontmatter = usePageFrontmatter<DefaultThemeHomePageFrontmatter>()
|
|
56
|
+
const siteLocale = useSiteLocaleData()
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
// hero image and title
|
|
59
|
+
const heroImage = computed(() => {
|
|
60
|
+
if (!frontmatter.value.heroImage) {
|
|
61
|
+
return null
|
|
62
|
+
}
|
|
61
63
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
)
|
|
84
|
-
|
|
85
|
-
const tagline = computed(() => {
|
|
86
|
-
if (frontmatter.value.tagline === null) {
|
|
87
|
-
return null
|
|
88
|
-
}
|
|
89
|
-
return (
|
|
90
|
-
frontmatter.value.tagline ||
|
|
91
|
-
siteLocale.value.description ||
|
|
92
|
-
'Welcome to your VuePress site'
|
|
93
|
-
)
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
const actions = computed(() => {
|
|
97
|
-
if (!isArray(frontmatter.value.actions)) {
|
|
98
|
-
return []
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return frontmatter.value.actions.map(
|
|
102
|
-
({ text, link, type = 'primary' }) => ({
|
|
103
|
-
text,
|
|
104
|
-
link,
|
|
105
|
-
type,
|
|
106
|
-
})
|
|
107
|
-
)
|
|
108
|
-
})
|
|
109
|
-
|
|
110
|
-
const features = computed(() => {
|
|
111
|
-
if (isArray(frontmatter.value.features)) {
|
|
112
|
-
return frontmatter.value.features
|
|
113
|
-
}
|
|
114
|
-
return []
|
|
115
|
-
})
|
|
116
|
-
|
|
117
|
-
const footer = computed(() => frontmatter.value.footer)
|
|
64
|
+
return withBase(frontmatter.value.heroImage)
|
|
65
|
+
})
|
|
66
|
+
const heroText = computed(() => {
|
|
67
|
+
if (frontmatter.value.heroText === null) {
|
|
68
|
+
return null
|
|
69
|
+
}
|
|
70
|
+
return frontmatter.value.heroText || siteLocale.value.title || 'Hello'
|
|
71
|
+
})
|
|
72
|
+
const heroAlt = computed(
|
|
73
|
+
() => frontmatter.value.heroAlt || heroText.value || 'hero'
|
|
74
|
+
)
|
|
75
|
+
const tagline = computed(() => {
|
|
76
|
+
if (frontmatter.value.tagline === null) {
|
|
77
|
+
return null
|
|
78
|
+
}
|
|
79
|
+
return (
|
|
80
|
+
frontmatter.value.tagline ||
|
|
81
|
+
siteLocale.value.description ||
|
|
82
|
+
'Welcome to your VuePress site'
|
|
83
|
+
)
|
|
84
|
+
})
|
|
118
85
|
|
|
119
|
-
|
|
86
|
+
// action buttons
|
|
87
|
+
const actions = computed(() => {
|
|
88
|
+
if (!isArray(frontmatter.value.actions)) {
|
|
89
|
+
return []
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return frontmatter.value.actions.map(({ text, link, type = 'primary' }) => ({
|
|
93
|
+
text,
|
|
94
|
+
link,
|
|
95
|
+
type,
|
|
96
|
+
}))
|
|
97
|
+
})
|
|
120
98
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
features,
|
|
128
|
-
footer,
|
|
129
|
-
footerHtml,
|
|
130
|
-
}
|
|
131
|
-
},
|
|
99
|
+
// feature list
|
|
100
|
+
const features = computed(() => {
|
|
101
|
+
if (isArray(frontmatter.value.features)) {
|
|
102
|
+
return frontmatter.value.features
|
|
103
|
+
}
|
|
104
|
+
return []
|
|
132
105
|
})
|
|
106
|
+
|
|
107
|
+
// footer
|
|
108
|
+
const footer = computed(() => frontmatter.value.footer)
|
|
109
|
+
const footerHtml = computed(() => frontmatter.value.footerHtml)
|
|
133
110
|
</script>
|
|
@@ -28,99 +28,87 @@
|
|
|
28
28
|
</template>
|
|
29
29
|
|
|
30
30
|
<script lang="ts">
|
|
31
|
-
|
|
31
|
+
/* eslint-disable import/first, import/no-duplicates, import/order */
|
|
32
|
+
import { defineComponent } from 'vue'
|
|
33
|
+
|
|
34
|
+
export default defineComponent({
|
|
35
|
+
inheritAttrs: false,
|
|
36
|
+
})
|
|
37
|
+
</script>
|
|
38
|
+
|
|
39
|
+
<script setup lang="ts">
|
|
40
|
+
import { computed, toRefs } from 'vue'
|
|
32
41
|
import type { PropType } from 'vue'
|
|
33
42
|
import { useRoute } from 'vue-router'
|
|
34
43
|
import { useSiteData } from '@vuepress/client'
|
|
35
44
|
import { isLinkHttp, isLinkMailto, isLinkTel } from '@vuepress/shared'
|
|
36
45
|
import type { NavLink } from '../../shared'
|
|
37
46
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
props: {
|
|
44
|
-
item: {
|
|
45
|
-
type: Object as PropType<NavLink>,
|
|
46
|
-
required: true,
|
|
47
|
-
},
|
|
47
|
+
const props = defineProps({
|
|
48
|
+
item: {
|
|
49
|
+
type: Object as PropType<NavLink>,
|
|
50
|
+
required: true,
|
|
48
51
|
},
|
|
52
|
+
})
|
|
49
53
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const { item } = toRefs(props)
|
|
54
|
-
|
|
55
|
-
// if the link has http protocol
|
|
56
|
-
const hasHttpProtocol = computed(() => isLinkHttp(item.value.link))
|
|
57
|
-
// if the link has non-http protocol
|
|
58
|
-
const hasNonHttpProtocal = computed(
|
|
59
|
-
() => isLinkMailto(item.value.link) || isLinkTel(item.value.link)
|
|
60
|
-
)
|
|
61
|
-
// resolve the `target` attr
|
|
62
|
-
const linkTarget = computed(() => {
|
|
63
|
-
if (hasNonHttpProtocal.value) return undefined
|
|
64
|
-
if (item.value.target) return item.value.target
|
|
65
|
-
if (hasHttpProtocol.value) return '_blank'
|
|
66
|
-
return undefined
|
|
67
|
-
})
|
|
68
|
-
// if the `target` attr is '_blank'
|
|
69
|
-
const isBlankTarget = computed(() => linkTarget.value === '_blank')
|
|
70
|
-
// is `<RouterLink>` or not
|
|
71
|
-
const isRouterLink = computed(
|
|
72
|
-
() =>
|
|
73
|
-
!hasHttpProtocol.value &&
|
|
74
|
-
!hasNonHttpProtocal.value &&
|
|
75
|
-
!isBlankTarget.value
|
|
76
|
-
)
|
|
77
|
-
// resolve the `rel` attr
|
|
78
|
-
const linkRel = computed(() => {
|
|
79
|
-
if (hasNonHttpProtocal.value) return undefined
|
|
80
|
-
if (item.value.rel) return item.value.rel
|
|
81
|
-
if (isBlankTarget.value) return 'noopener noreferrer'
|
|
82
|
-
return undefined
|
|
83
|
-
})
|
|
84
|
-
// resolve the `aria-label` attr
|
|
85
|
-
const linkAriaLabel = computed(
|
|
86
|
-
() => item.value.ariaLabel || item.value.text
|
|
87
|
-
)
|
|
54
|
+
const route = useRoute()
|
|
55
|
+
const site = useSiteData()
|
|
56
|
+
const { item } = toRefs(props)
|
|
88
57
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
58
|
+
// if the link has http protocol
|
|
59
|
+
const hasHttpProtocol = computed(() => isLinkHttp(item.value.link))
|
|
60
|
+
// if the link has non-http protocol
|
|
61
|
+
const hasNonHttpProtocal = computed(
|
|
62
|
+
() => isLinkMailto(item.value.link) || isLinkTel(item.value.link)
|
|
63
|
+
)
|
|
64
|
+
// resolve the `target` attr
|
|
65
|
+
const linkTarget = computed(() => {
|
|
66
|
+
if (hasNonHttpProtocal.value) return undefined
|
|
67
|
+
if (item.value.target) return item.value.target
|
|
68
|
+
if (hasHttpProtocol.value) return '_blank'
|
|
69
|
+
return undefined
|
|
70
|
+
})
|
|
71
|
+
// if the `target` attr is '_blank'
|
|
72
|
+
const isBlankTarget = computed(() => linkTarget.value === '_blank')
|
|
73
|
+
// is `<RouterLink>` or not
|
|
74
|
+
const isRouterLink = computed(
|
|
75
|
+
() =>
|
|
76
|
+
!hasHttpProtocol.value && !hasNonHttpProtocal.value && !isBlankTarget.value
|
|
77
|
+
)
|
|
78
|
+
// resolve the `rel` attr
|
|
79
|
+
const linkRel = computed(() => {
|
|
80
|
+
if (hasNonHttpProtocal.value) return undefined
|
|
81
|
+
if (item.value.rel) return item.value.rel
|
|
82
|
+
if (isBlankTarget.value) return 'noopener noreferrer'
|
|
83
|
+
return undefined
|
|
84
|
+
})
|
|
85
|
+
// resolve the `aria-label` attr
|
|
86
|
+
const linkAriaLabel = computed(() => item.value.ariaLabel || item.value.text)
|
|
104
87
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
88
|
+
// should be active when current route is a subpath of this link
|
|
89
|
+
const shouldBeActiveInSubpath = computed(() => {
|
|
90
|
+
const localeKeys = Object.keys(site.value.locales)
|
|
91
|
+
if (localeKeys.length) {
|
|
92
|
+
return !localeKeys.some((key) => key === item.value.link)
|
|
93
|
+
}
|
|
94
|
+
return item.value.link !== '/'
|
|
95
|
+
})
|
|
96
|
+
// if this link is active in subpath
|
|
97
|
+
const isActiveInSubpath = computed(() => {
|
|
98
|
+
if (!shouldBeActiveInSubpath.value) {
|
|
99
|
+
return false
|
|
100
|
+
}
|
|
101
|
+
return route.path.startsWith(item.value.link)
|
|
102
|
+
})
|
|
115
103
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
104
|
+
// if this link is active
|
|
105
|
+
const isActive = computed(() => {
|
|
106
|
+
if (!isRouterLink.value) {
|
|
107
|
+
return false
|
|
108
|
+
}
|
|
109
|
+
if (item.value.activeMatch) {
|
|
110
|
+
return new RegExp(item.value.activeMatch).test(route.path)
|
|
111
|
+
}
|
|
112
|
+
return isActiveInSubpath.value
|
|
125
113
|
})
|
|
126
114
|
</script>
|
|
@@ -4,12 +4,15 @@
|
|
|
4
4
|
|
|
5
5
|
<span ref="siteBrand">
|
|
6
6
|
<RouterLink :to="siteBrandLink">
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
<!-- logo could be different in dark mode, so we make it client-only to avoid ssr-mismatch -->
|
|
8
|
+
<ClientOnly>
|
|
9
|
+
<img
|
|
10
|
+
v-if="siteBrandLogo"
|
|
11
|
+
class="logo"
|
|
12
|
+
:src="withBase(siteBrandLogo)"
|
|
13
|
+
:alt="siteBrandTitle"
|
|
14
|
+
/>
|
|
15
|
+
</ClientOnly>
|
|
13
16
|
|
|
14
17
|
<span
|
|
15
18
|
v-if="siteBrandTitle"
|
|
@@ -36,9 +39,9 @@
|
|
|
36
39
|
</template>
|
|
37
40
|
|
|
38
41
|
<script setup lang="ts">
|
|
39
|
-
import { computed, onMounted, ref } from 'vue'
|
|
40
42
|
import { useRouteLocale, useSiteLocaleData, withBase } from '@vuepress/client'
|
|
41
|
-
import {
|
|
43
|
+
import { computed, onMounted, ref } from 'vue'
|
|
44
|
+
import { useDarkMode, useThemeLocaleData } from '../composables'
|
|
42
45
|
import NavbarLinks from './NavbarLinks.vue'
|
|
43
46
|
import ToggleDarkModeButton from './ToggleDarkModeButton.vue'
|
|
44
47
|
import ToggleSidebarButton from './ToggleSidebarButton.vue'
|
|
@@ -48,13 +51,19 @@ defineEmits(['toggle-sidebar'])
|
|
|
48
51
|
const routeLocale = useRouteLocale()
|
|
49
52
|
const siteLocale = useSiteLocaleData()
|
|
50
53
|
const themeLocale = useThemeLocaleData()
|
|
54
|
+
const isDarkMode = useDarkMode()
|
|
51
55
|
|
|
52
56
|
const navbar = ref<HTMLElement | null>(null)
|
|
53
57
|
const siteBrand = ref<HTMLElement | null>(null)
|
|
54
58
|
const siteBrandLink = computed(
|
|
55
59
|
() => themeLocale.value.home || routeLocale.value
|
|
56
60
|
)
|
|
57
|
-
const siteBrandLogo = computed(() =>
|
|
61
|
+
const siteBrandLogo = computed(() => {
|
|
62
|
+
if (isDarkMode.value && themeLocale.value.logoDark !== undefined) {
|
|
63
|
+
return themeLocale.value.logoDark
|
|
64
|
+
}
|
|
65
|
+
return themeLocale.value.logo
|
|
66
|
+
})
|
|
58
67
|
const siteBrandTitle = computed(() => siteLocale.value.title)
|
|
59
68
|
const linksWrapperMaxWidth = ref(0)
|
|
60
69
|
const linksWrapperStyle = computed(() => {
|