Skip to content

Commit

Permalink
feat(theme): allow specifying common alt for logo (#1451)
Browse files Browse the repository at this point in the history
Co-authored-by: Divyansh Singh <[email protected]>
  • Loading branch information
7nohe and brc-dd authored Oct 13, 2022
1 parent 41a519c commit 55688a8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
25 changes: 22 additions & 3 deletions src/client/theme-default/components/VPImage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { withBase } from 'vitepress'
defineProps<{
image: DefaultTheme.ThemeableImage
alt?: string
}>()
</script>

Expand All @@ -20,11 +21,29 @@ export default {
class="VPImage"
v-bind="typeof image === 'string' ? $attrs : { ...image, ...$attrs }"
:src="withBase(typeof image === 'string' ? image : image.src)"
:alt="typeof image === 'string' ? '' : (image.alt || '')"
:alt="alt ?? (typeof image === 'string' ? '' : image.alt || '')"
/>
<template v-else>
<VPImage class="dark" :image="image.dark" v-bind="$attrs" />
<VPImage class="light" :image="image.light" v-bind="$attrs" />
<VPImage
class="dark"
:image="image.dark"
:alt="
typeof image.dark === 'string'
? image.alt
: image.dark.alt || image.alt
"
v-bind="$attrs"
/>
<VPImage
class="light"
:image="image.light"
:alt="
typeof image.light === 'string'
? image.alt
: image.light.alt || image.alt
"
v-bind="$attrs"
/>
</template>
</template>
</template>
Expand Down
4 changes: 3 additions & 1 deletion types/default-theme.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ export namespace DefaultTheme {

// image -----------------------------------------------------------------------

export type ThemeableImage = Image | { light: Image; dark: Image }
export type ThemeableImage =
| Image
| { light: Image; dark: Image; alt?: string }
export type Image = string | { src: string; alt?: string }

// sidebar -------------------------------------------------------------------
Expand Down

0 comments on commit 55688a8

Please sign in to comment.