Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(theme): allow specifying common alt for logo #1451

Merged
merged 3 commits into from Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 22 additions & 3 deletions src/client/theme-default/components/VPImage.vue
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
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