From 55688a87e3baa38d0e0a37a6eba0039484416875 Mon Sep 17 00:00:00 2001 From: Urata Daiki <7nohe@users.noreply.github.com> Date: Thu, 13 Oct 2022 21:16:18 +0900 Subject: [PATCH] feat(theme): allow specifying common alt for logo (#1451) Co-authored-by: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> --- .../theme-default/components/VPImage.vue | 25 ++++++++++++++++--- types/default-theme.d.ts | 4 ++- 2 files changed, 25 insertions(+), 4 deletions(-) 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 -------------------------------------------------------------------