@vuepress/theme-default 2.0.0-beta.26 → 2.0.0-beta.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.
Files changed (41) hide show
  1. package/lib/client/clientAppEnhance.js +4 -5
  2. package/lib/client/components/DropdownLink.vue +51 -51
  3. package/lib/client/components/DropdownTransition.vue +11 -11
  4. package/lib/client/components/Home.vue +12 -107
  5. package/lib/client/components/HomeContent.vue +5 -0
  6. package/lib/client/components/HomeFeatures.vue +23 -0
  7. package/lib/client/components/HomeFooter.vue +17 -0
  8. package/lib/client/components/HomeHero.vue +97 -0
  9. package/lib/client/components/NavLink.vue +33 -33
  10. package/lib/client/components/Navbar.vue +23 -54
  11. package/lib/client/components/NavbarBrand.vue +55 -0
  12. package/lib/client/components/NavbarLinks.vue +16 -11
  13. package/lib/client/components/Page.vue +5 -5
  14. package/lib/client/components/PageMeta.vue +34 -31
  15. package/lib/client/components/PageNav.vue +14 -16
  16. package/lib/client/components/Sidebar.vue +8 -8
  17. package/lib/client/components/ToggleDarkModeButton.vue +11 -11
  18. package/lib/client/components/ToggleSidebarButton.vue +8 -8
  19. package/lib/client/components/global/Badge.vue +12 -12
  20. package/lib/client/components/global/CodeGroup.d.ts +1 -1
  21. package/lib/client/components/global/CodeGroupItem.vue +10 -10
  22. package/lib/client/components/global/{OutboundLink.vue → ExternalLinkIcon.vue} +7 -10
  23. package/lib/client/composables/useSidebarItems.d.ts +1 -1
  24. package/lib/client/index.d.ts +1 -1
  25. package/lib/client/layouts/404.vue +12 -12
  26. package/lib/client/layouts/Layout.vue +54 -54
  27. package/lib/client/styles/code.scss +1 -0
  28. package/lib/client/styles/home.scss +7 -4
  29. package/lib/client/styles/normalize.scss +1 -0
  30. package/lib/client/styles/page.scss +8 -0
  31. package/lib/client/styles/vars.scss +5 -0
  32. package/lib/client/utils/resolveEditLink.d.ts +1 -1
  33. package/lib/client/utils/resolveEditLink.js +12 -7
  34. package/lib/node/defaultTheme.js +28 -13
  35. package/lib/node/utils/assignDefaultLocaleOptions.d.ts +3 -1
  36. package/lib/node/utils/assignDefaultLocaleOptions.js +5 -5
  37. package/lib/node/utils/resolveContainerPluginOptions.d.ts +1 -1
  38. package/lib/node/utils/resolveGitPluginOptions.d.ts +1 -1
  39. package/lib/shared/options.d.ts +5 -1
  40. package/lib/shared/page.d.ts +3 -1
  41. package/package.json +21 -20
@@ -3,17 +3,16 @@ 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';
6
- import OutboundLink from './components/global/OutboundLink.vue';
6
+ import ExternalLinkIcon from './components/global/ExternalLinkIcon.vue';
7
7
  import { useScrollPromise } from './composables';
8
8
  import './styles/index.scss';
9
9
  export default defineClientAppEnhance(({ app, router }) => {
10
10
  app.component('Badge', Badge);
11
11
  app.component('CodeGroup', CodeGroup);
12
12
  app.component('CodeGroupItem', CodeGroupItem);
13
- // unregister the built-in `<OutboundLink>` to avoid warning
14
- delete app._context.components.OutboundLink;
15
- // override the built-in `<OutboundLink>`
16
- app.component('OutboundLink', OutboundLink);
13
+ // override the `<ExternalLinkIcon>` provided by @vuepress/plugin-external-link-icon
14
+ delete app._context.components.ExternalLinkIcon;
15
+ app.component('ExternalLinkIcon', ExternalLinkIcon);
17
16
  // compat with @vuepress/plugin-docsearch and @vuepress/plugin-search
18
17
  app.component('NavbarSearch', () => {
19
18
  const SearchComponent = app.component('Docsearch') || app.component('SearchBox');
@@ -1,3 +1,54 @@
1
+ <script setup lang="ts">
2
+ import { computed, ref, toRefs, watch } from 'vue'
3
+ import type { PropType } from 'vue'
4
+ import { useRoute } from 'vue-router'
5
+ import type { NavGroup, NavItem } from '../../shared'
6
+ import DropdownTransition from './DropdownTransition.vue'
7
+ import NavLink from './NavLink.vue'
8
+
9
+ const props = defineProps({
10
+ item: {
11
+ type: Object as PropType<NavGroup<NavItem>>,
12
+ required: true,
13
+ },
14
+ })
15
+
16
+ const { item } = toRefs(props)
17
+
18
+ const dropdownAriaLabel = computed(
19
+ () => item.value.ariaLabel || item.value.text
20
+ )
21
+
22
+ const open = ref(false)
23
+ const route = useRoute()
24
+ watch(
25
+ () => route.path,
26
+ () => {
27
+ open.value = false
28
+ }
29
+ )
30
+
31
+ /**
32
+ * Open the dropdown when user tab and click from keyboard.
33
+ *
34
+ * Use event.detail to detect tab and click from keyboard.
35
+ * The Tab + Click is UIEvent > KeyboardEvent, so the detail is 0.
36
+ *
37
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/detail
38
+ */
39
+ const handleDropdown = (e): void => {
40
+ const isTriggerByTab = e.detail === 0
41
+ if (isTriggerByTab) {
42
+ open.value = !open.value
43
+ } else {
44
+ open.value = false
45
+ }
46
+ }
47
+
48
+ const isLastItemOfArray = (item: unknown, arr: unknown[]): boolean =>
49
+ arr[arr.length - 1] === item
50
+ </script>
51
+
1
52
  <template>
2
53
  <div class="dropdown-wrapper" :class="{ open }">
3
54
  <button
@@ -73,54 +124,3 @@
73
124
  </DropdownTransition>
74
125
  </div>
75
126
  </template>
76
-
77
- <script setup lang="ts">
78
- import { computed, ref, toRefs, watch } from 'vue'
79
- import type { PropType } from 'vue'
80
- import { useRoute } from 'vue-router'
81
- import type { NavGroup, NavItem } from '../../shared'
82
- import DropdownTransition from './DropdownTransition.vue'
83
- import NavLink from './NavLink.vue'
84
-
85
- const props = defineProps({
86
- item: {
87
- type: Object as PropType<NavGroup<NavItem>>,
88
- required: true,
89
- },
90
- })
91
-
92
- const { item } = toRefs(props)
93
-
94
- const dropdownAriaLabel = computed(
95
- () => item.value.ariaLabel || item.value.text
96
- )
97
-
98
- const open = ref(false)
99
- const route = useRoute()
100
- watch(
101
- () => route.path,
102
- () => {
103
- open.value = false
104
- }
105
- )
106
-
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
- }
123
-
124
- const isLastItemOfArray = (item: unknown, arr: unknown[]): boolean =>
125
- arr[arr.length - 1] === item
126
- </script>
@@ -1,14 +1,3 @@
1
- <template>
2
- <Transition
3
- name="dropdown"
4
- @enter="setHeight"
5
- @after-enter="unsetHeight"
6
- @before-leave="setHeight"
7
- >
8
- <slot />
9
- </Transition>
10
- </template>
11
-
12
1
  <script setup lang="ts">
13
2
  const setHeight = (items): void => {
14
3
  // explicitly set height so that it can be transitioned
@@ -19,3 +8,14 @@ const unsetHeight = (items): void => {
19
8
  items.style.height = ''
20
9
  }
21
10
  </script>
11
+
12
+ <template>
13
+ <Transition
14
+ name="dropdown"
15
+ @enter="setHeight"
16
+ @after-enter="unsetHeight"
17
+ @before-leave="setHeight"
18
+ >
19
+ <slot />
20
+ </Transition>
21
+ </template>
@@ -1,110 +1,15 @@
1
- <template>
2
- <main class="home" :aria-labelledby="heroText ? 'main-title' : undefined">
3
- <header class="hero">
4
- <img v-if="heroImage" :src="heroImage" :alt="heroAlt" />
5
-
6
- <h1 v-if="heroText" id="main-title">
7
- {{ heroText }}
8
- </h1>
9
-
10
- <p v-if="tagline" class="description">
11
- {{ tagline }}
12
- </p>
13
-
14
- <p v-if="actions.length" class="actions">
15
- <NavLink
16
- v-for="action in actions"
17
- :key="action.text"
18
- class="action-button"
19
- :class="[action.type]"
20
- :item="action"
21
- />
22
- </p>
23
- </header>
24
-
25
- <div v-if="features.length" class="features">
26
- <div v-for="feature in features" :key="feature.title" class="feature">
27
- <h2>{{ feature.title }}</h2>
28
- <p>{{ feature.details }}</p>
29
- </div>
30
- </div>
31
-
32
- <div class="theme-default-content custom">
33
- <Content />
34
- </div>
1
+ <script setup lang="ts">
2
+ import HomeContent from './HomeContent.vue'
3
+ import HomeFeatures from './HomeFeatures.vue'
4
+ import HomeFooter from './HomeFooter.vue'
5
+ import HomeHero from './HomeHero.vue'
6
+ </script>
35
7
 
36
- <template v-if="footer">
37
- <!-- eslint-disable-next-line vue/no-v-html -->
38
- <div v-if="footerHtml" class="footer" v-html="footer" />
39
- <div v-else class="footer" v-text="footer" />
40
- </template>
8
+ <template>
9
+ <main class="home">
10
+ <HomeHero />
11
+ <HomeFeatures />
12
+ <HomeContent />
13
+ <HomeFooter />
41
14
  </main>
42
15
  </template>
43
-
44
- <script setup lang="ts">
45
- import {
46
- usePageFrontmatter,
47
- useSiteLocaleData,
48
- withBase,
49
- } from '@vuepress/client'
50
- import { isArray } from '@vuepress/shared'
51
- import { computed } from 'vue'
52
- import type { DefaultThemeHomePageFrontmatter } from '../../shared'
53
- import NavLink from './NavLink.vue'
54
-
55
- const frontmatter = usePageFrontmatter<DefaultThemeHomePageFrontmatter>()
56
- const siteLocale = useSiteLocaleData()
57
-
58
- // hero image and title
59
- const heroImage = computed(() => {
60
- if (!frontmatter.value.heroImage) {
61
- return null
62
- }
63
-
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
- })
85
-
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
- })
98
-
99
- // feature list
100
- const features = computed(() => {
101
- if (isArray(frontmatter.value.features)) {
102
- return frontmatter.value.features
103
- }
104
- return []
105
- })
106
-
107
- // footer
108
- const footer = computed(() => frontmatter.value.footer)
109
- const footerHtml = computed(() => frontmatter.value.footerHtml)
110
- </script>
@@ -0,0 +1,5 @@
1
+ <template>
2
+ <div class="theme-default-content custom">
3
+ <Content />
4
+ </div>
5
+ </template>
@@ -0,0 +1,23 @@
1
+ <script setup lang="ts">
2
+ import { usePageFrontmatter } from '@vuepress/client'
3
+ import { isArray } from '@vuepress/shared'
4
+ import { computed } from 'vue'
5
+ import type { DefaultThemeHomePageFrontmatter } from '../../shared'
6
+
7
+ const frontmatter = usePageFrontmatter<DefaultThemeHomePageFrontmatter>()
8
+ const features = computed(() => {
9
+ if (isArray(frontmatter.value.features)) {
10
+ return frontmatter.value.features
11
+ }
12
+ return []
13
+ })
14
+ </script>
15
+
16
+ <template>
17
+ <div v-if="features.length" class="features">
18
+ <div v-for="feature in features" :key="feature.title" class="feature">
19
+ <h2>{{ feature.title }}</h2>
20
+ <p>{{ feature.details }}</p>
21
+ </div>
22
+ </div>
23
+ </template>
@@ -0,0 +1,17 @@
1
+ <script setup lang="ts">
2
+ import { usePageFrontmatter } from '@vuepress/client'
3
+ import { computed } from 'vue'
4
+ import type { DefaultThemeHomePageFrontmatter } from '../../shared'
5
+
6
+ const frontmatter = usePageFrontmatter<DefaultThemeHomePageFrontmatter>()
7
+ const footer = computed(() => frontmatter.value.footer)
8
+ const footerHtml = computed(() => frontmatter.value.footerHtml)
9
+ </script>
10
+
11
+ <template>
12
+ <template v-if="footer">
13
+ <!-- eslint-disable-next-line vue/no-v-html -->
14
+ <div v-if="footerHtml" class="footer" v-html="footer" />
15
+ <div v-else class="footer" v-text="footer" />
16
+ </template>
17
+ </template>
@@ -0,0 +1,97 @@
1
+ <script setup lang="ts">
2
+ import {
3
+ ClientOnly,
4
+ usePageFrontmatter,
5
+ useSiteLocaleData,
6
+ withBase,
7
+ } from '@vuepress/client'
8
+ import { isArray } from '@vuepress/shared'
9
+ import type { FunctionalComponent } from 'vue'
10
+ import { computed, h } from 'vue'
11
+ import type { DefaultThemeHomePageFrontmatter } from '../../shared'
12
+ import { useDarkMode } from '../composables'
13
+ import NavLink from './NavLink.vue'
14
+
15
+ const frontmatter = usePageFrontmatter<DefaultThemeHomePageFrontmatter>()
16
+ const siteLocale = useSiteLocaleData()
17
+ const isDarkMode = useDarkMode()
18
+
19
+ const heroImage = computed(() => {
20
+ if (isDarkMode.value && frontmatter.value.heroImageDark !== undefined) {
21
+ return frontmatter.value.heroImageDark
22
+ }
23
+ return frontmatter.value.heroImage
24
+ })
25
+
26
+ const heroText = computed(() => {
27
+ if (frontmatter.value.heroText === null) {
28
+ return null
29
+ }
30
+ return frontmatter.value.heroText || siteLocale.value.title || 'Hello'
31
+ })
32
+
33
+ const heroAlt = computed(
34
+ () => frontmatter.value.heroAlt || heroText.value || 'hero'
35
+ )
36
+
37
+ const tagline = computed(() => {
38
+ if (frontmatter.value.tagline === null) {
39
+ return null
40
+ }
41
+ return (
42
+ frontmatter.value.tagline ||
43
+ siteLocale.value.description ||
44
+ 'Welcome to your VuePress site'
45
+ )
46
+ })
47
+
48
+ const actions = computed(() => {
49
+ if (!isArray(frontmatter.value.actions)) {
50
+ return []
51
+ }
52
+
53
+ return frontmatter.value.actions.map(({ text, link, type = 'primary' }) => ({
54
+ text,
55
+ link,
56
+ type,
57
+ }))
58
+ })
59
+
60
+ const HomeHeroImage: FunctionalComponent = () => {
61
+ if (!heroImage.value) return null
62
+ const img = h('img', {
63
+ src: withBase(heroImage.value),
64
+ alt: heroAlt.value,
65
+ })
66
+ if (frontmatter.value.heroImageDark === undefined) {
67
+ return img
68
+ }
69
+ // wrap hero image with <ClientOnly> to avoid ssr-mismatch
70
+ // when using a different hero image in dark mode
71
+ return h(ClientOnly, img)
72
+ }
73
+ </script>
74
+
75
+ <template>
76
+ <header class="hero">
77
+ <HomeHeroImage />
78
+
79
+ <h1 v-if="heroText" id="main-title">
80
+ {{ heroText }}
81
+ </h1>
82
+
83
+ <p v-if="tagline" class="description">
84
+ {{ tagline }}
85
+ </p>
86
+
87
+ <p v-if="actions.length" class="actions">
88
+ <NavLink
89
+ v-for="action in actions"
90
+ :key="action.text"
91
+ class="action-button"
92
+ :class="[action.type]"
93
+ :item="action"
94
+ />
95
+ </p>
96
+ </header>
97
+ </template>
@@ -1,32 +1,3 @@
1
- <template>
2
- <RouterLink
3
- v-if="isRouterLink"
4
- class="nav-link"
5
- :class="{ 'router-link-active': isActive }"
6
- :to="item.link"
7
- :aria-label="linkAriaLabel"
8
- v-bind="$attrs"
9
- >
10
- <slot name="before" />
11
- {{ item.text }}
12
- <slot name="after" />
13
- </RouterLink>
14
- <a
15
- v-else
16
- class="nav-link external"
17
- :href="item.link"
18
- :rel="linkRel"
19
- :target="linkTarget"
20
- :aria-label="linkAriaLabel"
21
- v-bind="$attrs"
22
- >
23
- <slot name="before" />
24
- {{ item.text }}
25
- <OutboundLink v-if="isBlankTarget" />
26
- <slot name="after" />
27
- </a>
28
- </template>
29
-
30
1
  <script lang="ts">
31
2
  /* eslint-disable import/first, import/no-duplicates, import/order */
32
3
  import { defineComponent } from 'vue'
@@ -58,12 +29,12 @@ const { item } = toRefs(props)
58
29
  // if the link has http protocol
59
30
  const hasHttpProtocol = computed(() => isLinkHttp(item.value.link))
60
31
  // if the link has non-http protocol
61
- const hasNonHttpProtocal = computed(
32
+ const hasNonHttpProtocol = computed(
62
33
  () => isLinkMailto(item.value.link) || isLinkTel(item.value.link)
63
34
  )
64
35
  // resolve the `target` attr
65
36
  const linkTarget = computed(() => {
66
- if (hasNonHttpProtocal.value) return undefined
37
+ if (hasNonHttpProtocol.value) return undefined
67
38
  if (item.value.target) return item.value.target
68
39
  if (hasHttpProtocol.value) return '_blank'
69
40
  return undefined
@@ -73,11 +44,11 @@ const isBlankTarget = computed(() => linkTarget.value === '_blank')
73
44
  // is `<RouterLink>` or not
74
45
  const isRouterLink = computed(
75
46
  () =>
76
- !hasHttpProtocol.value && !hasNonHttpProtocal.value && !isBlankTarget.value
47
+ !hasHttpProtocol.value && !hasNonHttpProtocol.value && !isBlankTarget.value
77
48
  )
78
49
  // resolve the `rel` attr
79
50
  const linkRel = computed(() => {
80
- if (hasNonHttpProtocal.value) return undefined
51
+ if (hasNonHttpProtocol.value) return undefined
81
52
  if (item.value.rel) return item.value.rel
82
53
  if (isBlankTarget.value) return 'noopener noreferrer'
83
54
  return undefined
@@ -112,3 +83,32 @@ const isActive = computed(() => {
112
83
  return isActiveInSubpath.value
113
84
  })
114
85
  </script>
86
+
87
+ <template>
88
+ <RouterLink
89
+ v-if="isRouterLink"
90
+ class="nav-link"
91
+ :class="{ 'router-link-active': isActive }"
92
+ :to="item.link"
93
+ :aria-label="linkAriaLabel"
94
+ v-bind="$attrs"
95
+ >
96
+ <slot name="before" />
97
+ {{ item.text }}
98
+ <slot name="after" />
99
+ </RouterLink>
100
+ <a
101
+ v-else
102
+ class="nav-link external"
103
+ :href="item.link"
104
+ :rel="linkRel"
105
+ :target="linkTarget"
106
+ :aria-label="linkAriaLabel"
107
+ v-bind="$attrs"
108
+ >
109
+ <slot name="before" />
110
+ {{ item.text }}
111
+ <ExternalLinkIcon v-if="isBlankTarget" />
112
+ <slot name="after" />
113
+ </a>
114
+ </template>
@@ -1,67 +1,18 @@
1
- <template>
2
- <header ref="navbar" class="navbar">
3
- <ToggleSidebarButton @toggle="$emit('toggle-sidebar')" />
4
-
5
- <span ref="siteBrand">
6
- <RouterLink :to="siteBrandLink">
7
- <img
8
- v-if="siteBrandLogo"
9
- class="logo"
10
- :src="withBase(siteBrandLogo)"
11
- :alt="siteBrandTitle"
12
- />
13
-
14
- <span
15
- v-if="siteBrandTitle"
16
- class="site-name"
17
- :class="{ 'can-hide': siteBrandLogo }"
18
- >
19
- {{ siteBrandTitle }}
20
- </span>
21
- </RouterLink>
22
- </span>
23
-
24
- <div class="navbar-links-wrapper" :style="linksWrapperStyle">
25
- <slot name="before" />
26
-
27
- <NavbarLinks class="can-hide" />
28
-
29
- <slot name="after" />
30
-
31
- <ToggleDarkModeButton v-if="enableDarkMode" />
32
-
33
- <NavbarSearch />
34
- </div>
35
- </header>
36
- </template>
37
-
38
1
  <script setup lang="ts">
39
- import { useRouteLocale, useSiteLocaleData, withBase } from '@vuepress/client'
40
2
  import { computed, onMounted, ref } from 'vue'
41
- import { useDarkMode, useThemeLocaleData } from '../composables'
3
+ import { useThemeLocaleData } from '../composables'
4
+ import NavbarBrand from './NavbarBrand.vue'
42
5
  import NavbarLinks from './NavbarLinks.vue'
43
6
  import ToggleDarkModeButton from './ToggleDarkModeButton.vue'
44
7
  import ToggleSidebarButton from './ToggleSidebarButton.vue'
45
8
 
46
9
  defineEmits(['toggle-sidebar'])
47
10
 
48
- const routeLocale = useRouteLocale()
49
- const siteLocale = useSiteLocaleData()
50
11
  const themeLocale = useThemeLocaleData()
51
- const isDarkMode = useDarkMode()
52
12
 
53
13
  const navbar = ref<HTMLElement | null>(null)
54
- const siteBrand = ref<HTMLElement | null>(null)
55
- const siteBrandLink = computed(
56
- () => themeLocale.value.home || routeLocale.value
57
- )
58
- const siteBrandLogo = computed(() => {
59
- if (isDarkMode.value && themeLocale.value.logoDark !== undefined) {
60
- return themeLocale.value.logoDark
61
- }
62
- return themeLocale.value.logo
63
- })
64
- const siteBrandTitle = computed(() => siteLocale.value.title)
14
+ const navbarBrand = ref<HTMLElement | null>(null)
15
+
65
16
  const linksWrapperMaxWidth = ref(0)
66
17
  const linksWrapperStyle = computed(() => {
67
18
  if (!linksWrapperMaxWidth.value) {
@@ -88,7 +39,7 @@ onMounted(() => {
88
39
  linksWrapperMaxWidth.value =
89
40
  navbar.value!.offsetWidth -
90
41
  navbarHorizontalPadding -
91
- (siteBrand.value?.offsetWidth || 0)
42
+ (navbarBrand.value?.offsetWidth || 0)
92
43
  }
93
44
  }
94
45
  handleLinksWrapWidth()
@@ -105,3 +56,21 @@ function getCssValue(el: HTMLElement | null, property: string): number {
105
56
  return Number.isNaN(num) ? 0 : num
106
57
  }
107
58
  </script>
59
+
60
+ <template>
61
+ <header ref="navbar" class="navbar">
62
+ <ToggleSidebarButton @toggle="$emit('toggle-sidebar')" />
63
+
64
+ <span ref="navbarBrand">
65
+ <NavbarBrand />
66
+ </span>
67
+
68
+ <div class="navbar-links-wrapper" :style="linksWrapperStyle">
69
+ <slot name="before" />
70
+ <NavbarLinks class="can-hide" />
71
+ <slot name="after" />
72
+ <ToggleDarkModeButton v-if="enableDarkMode" />
73
+ <NavbarSearch />
74
+ </div>
75
+ </header>
76
+ </template>
@@ -0,0 +1,55 @@
1
+ <script setup lang="ts">
2
+ import {
3
+ ClientOnly,
4
+ useRouteLocale,
5
+ useSiteLocaleData,
6
+ withBase,
7
+ } from '@vuepress/client'
8
+ import { computed, h } from 'vue'
9
+ import type { FunctionalComponent } from 'vue'
10
+ import { useDarkMode, useThemeLocaleData } from '../composables'
11
+
12
+ const routeLocale = useRouteLocale()
13
+ const siteLocale = useSiteLocaleData()
14
+ const themeLocale = useThemeLocaleData()
15
+ const isDarkMode = useDarkMode()
16
+
17
+ const navbarBrandLink = computed(
18
+ () => themeLocale.value.home || routeLocale.value
19
+ )
20
+ const navbarBrandTitle = computed(() => siteLocale.value.title)
21
+ const navbarBrandLogo = computed(() => {
22
+ if (isDarkMode.value && themeLocale.value.logoDark !== undefined) {
23
+ return themeLocale.value.logoDark
24
+ }
25
+ return themeLocale.value.logo
26
+ })
27
+ const NavbarBrandLogo: FunctionalComponent = () => {
28
+ if (!navbarBrandLogo.value) return null
29
+ const img = h('img', {
30
+ class: 'logo',
31
+ src: withBase(navbarBrandLogo.value),
32
+ alt: navbarBrandTitle.value,
33
+ })
34
+ if (themeLocale.value.logoDark === undefined) {
35
+ return img
36
+ }
37
+ // wrap brand logo with <ClientOnly> to avoid ssr-mismatch
38
+ // when using a different brand logo in dark mode
39
+ return h(ClientOnly, img)
40
+ }
41
+ </script>
42
+
43
+ <template>
44
+ <RouterLink :to="navbarBrandLink">
45
+ <NavbarBrandLogo />
46
+
47
+ <span
48
+ v-if="navbarBrandTitle"
49
+ class="site-name"
50
+ :class="{ 'can-hide': navbarBrandLogo }"
51
+ >
52
+ {{ navbarBrandTitle }}
53
+ </span>
54
+ </RouterLink>
55
+ </template>