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): add home-hero-image slot #1528

Merged
merged 5 commits into from
Dec 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/guide/theme-introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ Full list of slots available in the default theme layout:
- `aside-ads-after`
- When `layout: 'home'` is enabled via frontmatter:
- `home-hero-before`
- `home-hero-image`
- `home-hero-after`
- `home-features-before`
- `home-features-after`
Expand Down
8 changes: 7 additions & 1 deletion src/client/theme-default/Layout.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { provide, watch } from 'vue'
import { computed, provide, useSlots, watch } from 'vue'
import { useData, useRoute } from 'vitepress'
import { useSidebar, useCloseSidebarOnEscape } from './composables/sidebar.js'
import VPSkipLink from './components/VPSkipLink.vue'
Expand All @@ -25,6 +25,11 @@ provide('close-sidebar', closeSidebar)
provide('is-sidebar-open', isSidebarOpen)

const { frontmatter } = useData()

const slots = useSlots()
const heroImageSlotExists = computed(() => !!slots['home-hero-image'])

provide('hero-image-slot-exists', heroImageSlotExists)
</script>

<template>
Expand All @@ -49,6 +54,7 @@ const { frontmatter } = useData()

<VPContent>
<template #home-hero-before><slot name="home-hero-before" /></template>
<template #home-hero-image><slot name="home-hero-image" /></template>
<template #home-hero-after><slot name="home-hero-after" /></template>
<template #home-features-before><slot name="home-features-before" /></template>
<template #home-features-after><slot name="home-features-after" /></template>
Expand Down
1 change: 1 addition & 0 deletions src/client/theme-default/components/VPContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const NotFound = inject('NotFound')

<VPHome v-else-if="frontmatter.layout === 'home'">
<template #home-hero-before><slot name="home-hero-before" /></template>
<template #home-hero-image><slot name="home-hero-image" /></template>
<template #home-hero-after><slot name="home-hero-after" /></template>
<template #home-features-before><slot name="home-features-before" /></template>
<template #home-features-after><slot name="home-features-after" /></template>
Expand Down
11 changes: 8 additions & 3 deletions src/client/theme-default/components/VPHero.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script setup lang="ts">
import { Ref, inject } from 'vue'
import type { DefaultTheme } from 'vitepress/theme'
import VPButton from './VPButton.vue'
import VPImage from './VPImage.vue'
Expand All @@ -16,10 +17,12 @@ defineProps<{
image?: DefaultTheme.ThemeableImage
actions?: HeroAction[]
}>()

const heroImageSlotExists = inject('hero-image-slot-exists') as Ref<boolean>
</script>

<template>
<div class="VPHero" :class="{ 'has-image': image }">
<div class="VPHero" :class="{ 'has-image': image || heroImageSlotExists }">
<div class="container">
<div class="main">
<h1 v-if="name" class="name">
Expand All @@ -41,10 +44,12 @@ defineProps<{
</div>
</div>

<div v-if="image" class="image">
<div v-if="image || heroImageSlotExists" class="image">
<div class="image-container">
<div class="image-bg" />
<VPImage class="image-src" :image="image" />
<slot name="home-hero-image">
<VPImage v-if="image" class="image-src" :image="image" />
</slot>
</div>
</div>
</div>
Expand Down
4 changes: 3 additions & 1 deletion src/client/theme-default/components/VPHome.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import VPHomeFeatures from './VPHomeFeatures.vue'
<template>
<div class="VPHome">
<slot name="home-hero-before" />
<VPHomeHero />
<VPHomeHero>
<template #home-hero-image><slot name="home-hero-image" /></template>
</VPHomeHero>
<slot name="home-hero-after" />

<slot name="home-features-before" />
Expand Down
4 changes: 3 additions & 1 deletion src/client/theme-default/components/VPHomeHero.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ const { frontmatter: fm } = useData()
:tagline="fm.hero.tagline"
:image="fm.hero.image"
:actions="fm.hero.actions"
/>
>
<template #home-hero-image><slot name="home-hero-image" /></template>
</VPHero>
</template>