pull/154/head
Kia King Ishii 5 years ago
parent d4958400bb
commit 1bcce48d5e

@ -0,0 +1,8 @@
import { Ref, computed } from 'vue'
import { usePageData } from './pageData'
export type FrontmatterRef = Ref<Record<string, any>>
export function useFrontmatter() {
return computed(() => usePageData().value.frontmatter)
}

@ -14,6 +14,7 @@ export { useRouter, useRoute, Router, Route } from './router'
export { useSiteData } from './composables/siteData' export { useSiteData } from './composables/siteData'
export { useSiteDataByRoute } from './composables/siteDataByRoute' export { useSiteDataByRoute } from './composables/siteDataByRoute'
export { usePageData } from './composables/pageData' export { usePageData } from './composables/pageData'
export { useFrontmatter } from './composables/frontmatter'
// components // components
export { Content } from './components/Content' export { Content } from './components/Content'

@ -13,33 +13,14 @@
</div> </div>
</template> </template>
<script lang="ts"> <script setup lang="ts">
import { defineComponent, computed } from 'vue' import { computed } from 'vue'
import { useRoute, useSiteDataByRoute } from 'vitepress' import { useSiteDataByRoute, useFrontmatter } from 'vitepress'
import { withBase } from '../utils'
ref: data = useFrontmatter()
export default defineComponent({
setup() { ref: hasFeatures = computed(() => data.features && data.features.length > 0)
const route = useRoute() ref: features = computed(() => data.features ? data.features : [])
const siteData = useSiteDataByRoute()
const data = computed(() => route.data.frontmatter)
const hasFeatures = computed(() => {
return data.value.features && data.value.features.length > 0
})
const features = computed(() => {
return data.value.features ? data.value.features : []
})
return {
data,
hasFeatures,
features
}
}
})
</script> </script>
<style scoped> <style scoped>

@ -1,28 +1,11 @@
<template> <template>
<footer v-if="footer" class="footer"> <footer v-if="$frontmatter.footer" class="footer">
<div class="container"> <div class="container">
<p class="text">{{ footer }}</p> <p class="text">{{ $frontmatter.footer }}</p>
</div> </div>
</footer> </footer>
</template> </template>
<script lang="ts">
import { defineComponent, computed } from 'vue'
import { useRoute } from 'vitepress'
export default defineComponent({
setup() {
const route = useRoute()
const footer = computed(() => route.data.frontmatter.footer)
return {
footer
}
}
})
</script>
<style scoped> <style scoped>
.footer { .footer {
margin: 0 auto; margin: 0 auto;

@ -1,77 +1,42 @@
<template> <template>
<header v-if="showHero" class="home-hero"> <header v-if="showHero" class="home-hero">
<figure v-if="hasHeroImage" class="figure"> <figure v-if="$frontmatter.heroImage" class="figure">
<img class="image" :src="heroImage" :alt="heroAlt"> <img
class="image"
:src="$withBase($frontmatter.heroImage)"
:alt="$frontmatter.heroAlt"
>
</figure> </figure>
<h1 v-if="hasHeroText" class="title">{{ heroText }}</h1> <h1 v-if="hasHeroText" class="title">{{ heroText }}</h1>
<p v-if="hasTagline" class="description">{{ tagline }}</p> <p v-if="hasTagline" class="description">{{ tagline }}</p>
<div v-if="hasAction" class="action"> <div v-if="hasAction" class="action">
<a class="action-link" :href="actionLink"> <a class="action-link" :href="$frontmatter.actionLink">
{{ actionText }} {{ $frontmatter.actionText }}
</a> </a>
</div> </div>
</header> </header>
</template> </template>
<script lang="ts"> <script setup lang="ts">
import { defineComponent, computed } from 'vue' import { computed } from 'vue'
import { useRoute, useSiteDataByRoute } from 'vitepress' import { useSiteDataByRoute, useFrontmatter } from 'vitepress'
import { withBase } from '../utils'
ref: site = useSiteDataByRoute()
export default defineComponent({ ref: data = useFrontmatter()
setup() {
const route = useRoute() ref: showHero = computed(() => {
const siteData = useSiteDataByRoute() return data.heroImage || hasHeroText || hasTagline || hasAction
const data = computed(() => route.data.frontmatter)
const showHero = computed(() => {
return hasHeroImage.value
|| hasHeroText.value
|| hasTagline.value
|| hasAction.value
})
const hasHeroImage = computed(() => !!data.value.heroImage)
const heroImage = computed(() => withBase(data.value.heroImage))
const heroAlt = computed(() => data.value.heroAlt || 'Hero image')
const hasHeroText = computed(() => data.value.heroText !== null)
const heroText = computed(() => {
return data.value.heroText || siteData.value.title
})
const hasTagline = computed(() => data.value.tagline !== null)
const tagline = computed(() => {
return data.value.tagline || siteData.value.description
})
const hasAction = computed(() => {
return data.value.actionLink && data.value.actionText
})
const actionLink = computed(() => data.value.actionLink)
const actionText = computed(() => data.value.actionText)
return {
showHero,
hasHeroImage,
heroImage,
heroAlt,
hasHeroText,
heroText,
hasTagline,
tagline,
hasAction,
actionLink,
actionText
}
}
}) })
ref: hasHeroText = computed(() => data.heroText !== null)
ref: heroText = computed(() => data.heroText || site.title)
ref: hasTagline = computed(() => data.tagline !== null)
ref: tagline = computed(() => data.tagline || site.description)
ref: hasAction = computed(() => data.actionLink && data.actionText)
</script> </script>
<style scoped> <style scoped>

Loading…
Cancel
Save