diff --git a/src/client/theme-default/components/VPImage.vue b/src/client/theme-default/components/VPImage.vue index 9187f4c5aaf..e91ac3c9fe0 100644 --- a/src/client/theme-default/components/VPImage.vue +++ b/src/client/theme-default/components/VPImage.vue @@ -4,6 +4,7 @@ import { withBase } from 'vitepress' defineProps<{ image: DefaultTheme.ThemeableImage + alt?: string }>() @@ -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 || '')" /> diff --git a/types/default-theme.d.ts b/types/default-theme.d.ts index 36ba6f0d68f..387385ace67 100644 --- a/types/default-theme.d.ts +++ b/types/default-theme.d.ts @@ -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 -------------------------------------------------------------------