Commit 42813ce 1 parent 35772ca commit 42813ce Copy full SHA for 42813ce
File tree 5 files changed +57
-13
lines changed
5 files changed +57
-13
lines changed Original file line number Diff line number Diff line change 1
1
<script setup lang="ts">
2
+ import type { DefaultTheme } from ' vitepress/theme'
2
3
import VPButton from ' ./VPButton.vue'
4
+ import VPImage from ' ./VPImage.vue'
3
5
4
6
export interface HeroAction {
5
7
theme? : ' brand' | ' alt'
6
8
text: string
7
9
link: string
8
10
}
9
11
10
- export interface Image {
11
- src: string
12
- alt? : string
13
- }
14
-
15
12
defineProps <{
16
13
name? : string
17
14
text: string
18
15
tagline? : string
19
- image? : Image
16
+ image? : DefaultTheme . ThemeableImage
20
17
actions? : HeroAction []
21
18
}>()
22
19
</script >
@@ -25,7 +22,9 @@ defineProps<{
25
22
<div class =" VPHero" :class =" { 'has-image': image }" >
26
23
<div class =" container" >
27
24
<div class =" main" >
28
- <h1 v-if =" name" class =" name" ><span class =" clip" >{{ name }}</span ></h1 >
25
+ <h1 v-if =" name" class =" name" >
26
+ <span class =" clip" >{{ name }}</span >
27
+ </h1 >
29
28
<p v-if =" text" class =" text" >{{ text }}</p >
30
29
<p v-if =" tagline" class =" tagline" >{{ tagline }}</p >
31
30
@@ -45,7 +44,7 @@ defineProps<{
45
44
<div v-if =" image" class =" image" >
46
45
<div class =" image-container" >
47
46
<div class =" image-bg" />
48
- <img class =" image-src" :src = " image.src " :alt =" image.alt " >
47
+ <VPImage class =" image-src" :image =" image" / >
49
48
</div >
50
49
</div >
51
50
</div >
@@ -293,7 +292,7 @@ defineProps<{
293
292
}
294
293
}
295
294
296
- .image-src {
295
+ :deep( .image-src ) {
297
296
position : absolute ;
298
297
top : 50% ;
299
298
left : 50% ;
Original file line number Diff line number Diff line change
1
+ <script setup lang="ts">
2
+ import { withBase } from ' vitepress'
3
+ import type { DefaultTheme } from ' vitepress/theme'
4
+
5
+ defineProps <{
6
+ image: DefaultTheme .ThemeableImage
7
+ }>()
8
+ </script >
9
+
10
+ <script lang="ts">
11
+ export default {
12
+ inheritAttrs: false
13
+ }
14
+ </script >
15
+
16
+ <template >
17
+ <template v-if =" image " >
18
+ <img
19
+ v-if =" typeof image === 'string' || 'src' in image"
20
+ class =" VPImage"
21
+ v-bind =" typeof image === 'string' ? $attrs : { ...image, ...$attrs }"
22
+ :src =" withBase(typeof image === 'string' ? image : image.src)"
23
+ />
24
+ <template v-else >
25
+ <VPImage class =" dark" :image =" image.dark" v-bind =" $attrs" />
26
+ <VPImage class =" light" :image =" image.light" v-bind =" $attrs" />
27
+ </template >
28
+ </template >
29
+ </template >
30
+
31
+ <style scoped>
32
+ html :not (.dark ) .VPImage.dark {
33
+ display : none ;
34
+ }
35
+ .dark .VPImage.light {
36
+ display : none ;
37
+ }
38
+ </style >
Original file line number Diff line number Diff line change 1
1
<script setup lang="ts">
2
2
import { useData } from ' vitepress'
3
3
import { useSidebar } from ' ../composables/sidebar'
4
+ import VPImage from ' ./VPImage.vue'
4
5
5
6
const { site, theme } = useData ()
6
7
const { hasSidebar } = useSidebar ()
@@ -9,7 +10,7 @@ const { hasSidebar } = useSidebar()
9
10
<template >
10
11
<div class =" VPNavBarTitle" :class =" { 'has-sidebar': hasSidebar }" >
11
12
<a class =" title" :href =" site.base" >
12
- <img v-if = " theme.logo " class =" logo" :src =" theme.logo" >
13
+ <VPImage class =" logo" :image =" theme.logo" / >
13
14
<template v-if =" theme .siteTitle " >{{ theme.siteTitle }}</template >
14
15
<template v-else-if =" theme .siteTitle === undefined " >{{ site.title }}</template >
15
16
</a >
@@ -52,7 +53,7 @@ const { hasSidebar } = useSidebar()
52
53
}
53
54
}
54
55
55
- .logo {
56
+ :deep( .logo ) {
56
57
margin-right : 8px ;
57
58
height : 24px ;
58
59
}
Original file line number Diff line number Diff line change 12
12
"types" : [ "vite/client" ] ,
13
13
"paths" : {
14
14
"/@theme/*" : [ "theme-default/*" ] ,
15
- "vitepress" : [ "index.ts" ]
15
+ "vitepress" : [ "index.ts" ] ,
16
+ "vitepress/theme" : [ "../../types/default-theme.d" ]
16
17
}
17
18
} ,
18
19
"include" : [ "." ]
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ export namespace DefaultTheme {
5
5
*
6
6
* @example '/logo.svg'
7
7
*/
8
- logo ?: string
8
+ logo ?: ThemeableImage
9
9
10
10
/**
11
11
* Custom site title in navbar. If the value is undefined,
@@ -96,6 +96,11 @@ export namespace DefaultTheme {
96
96
items : ( NavItemChildren | NavItemWithLink ) [ ]
97
97
}
98
98
99
+ // image -----------------------------------------------------------------------
100
+
101
+ export type ThemeableImage = Image | { light : Image ; dark : Image }
102
+ export type Image = string | { src : string ; alt ?: string }
103
+
99
104
// sidebar -------------------------------------------------------------------
100
105
101
106
export type Sidebar = SidebarGroup [ ] | SidebarMulti
You can’t perform that action at this time.
0 commit comments