|
1 | 1 | <template>
|
2 |
| - <main |
3 |
| - class="home" |
4 |
| - :aria-labelledby="$frontmatter.heroText !== null ? 'main-title' : null" |
5 |
| - > |
| 2 | + <main class="home" :aria-labelledby="heroText ? 'main-title' : null"> |
6 | 3 | <header class="hero">
|
7 |
| - <img |
8 |
| - v-if="$frontmatter.heroImage" |
9 |
| - :src="$withBase($frontmatter.heroImage)" |
10 |
| - :alt="$frontmatter.heroAlt || 'hero'" |
11 |
| - /> |
12 |
| - |
13 |
| - <h1 v-if="$frontmatter.heroText !== null" id="main-title"> |
14 |
| - {{ $frontmatter.heroText || $siteLocale.title || 'Hello' }} |
| 4 | + <img v-if="heroImage" :src="heroImage" :alt="heroAlt" /> |
| 5 | + |
| 6 | + <h1 v-if="heroText" id="main-title"> |
| 7 | + {{ heroText }} |
15 | 8 | </h1>
|
16 | 9 |
|
17 |
| - <p v-if="$frontmatter.tagline !== null" class="description"> |
18 |
| - {{ |
19 |
| - $frontmatter.tagline || |
20 |
| - $siteLocale.description || |
21 |
| - 'Welcome to your VuePress site' |
22 |
| - }} |
| 10 | + <p v-if="tagline" class="description"> |
| 11 | + {{ tagline }} |
23 | 12 | </p>
|
24 | 13 |
|
25 |
| - <p |
26 |
| - v-if="$frontmatter.actionText && $frontmatter.actionLink" |
27 |
| - class="action" |
28 |
| - > |
| 14 | + <p v-if="actions.length" class="actions"> |
29 | 15 | <NavLink
|
| 16 | + v-for="action in actions" |
| 17 | + :key="action.text" |
30 | 18 | class="action-button"
|
31 |
| - :item="{ |
32 |
| - text: $frontmatter.actionText, |
33 |
| - link: $frontmatter.actionLink, |
34 |
| - }" |
| 19 | + :class="[action.type]" |
| 20 | + :item="action" |
35 | 21 | />
|
36 | 22 | </p>
|
37 | 23 | </header>
|
38 | 24 |
|
39 |
| - <div |
40 |
| - v-if="$frontmatter.features && $frontmatter.features.length" |
41 |
| - class="features" |
42 |
| - > |
43 |
| - <div |
44 |
| - v-for="(feature, index) in $frontmatter.features" |
45 |
| - :key="index" |
46 |
| - class="feature" |
47 |
| - > |
| 25 | + <div v-if="features.length" class="features"> |
| 26 | + <div v-for="feature in features" :key="feature.title" class="feature"> |
48 | 27 | <h2>{{ feature.title }}</h2>
|
49 | 28 | <p>{{ feature.details }}</p>
|
50 | 29 | </div>
|
|
54 | 33 | <Content />
|
55 | 34 | </div>
|
56 | 35 |
|
57 |
| - <div v-if="$frontmatter.footer" class="footer"> |
58 |
| - {{ $frontmatter.footer }} |
| 36 | + <div v-if="footer" class="footer"> |
| 37 | + {{ footer }} |
59 | 38 | </div>
|
60 | 39 | </main>
|
61 | 40 | </template>
|
62 | 41 |
|
63 | 42 | <script lang="ts">
|
64 |
| -import { defineComponent } from 'vue' |
| 43 | +import { computed, defineComponent } from 'vue' |
| 44 | +import { |
| 45 | + usePageFrontmatter, |
| 46 | + useSiteLocaleData, |
| 47 | + withBase, |
| 48 | +} from '@vuepress/client' |
| 49 | +import { isArray } from '@vuepress/shared' |
| 50 | +import type { DefaultThemeHomePageFrontmatter } from '../types' |
65 | 51 | import NavLink from './NavLink.vue'
|
66 | 52 |
|
67 | 53 | export default defineComponent({
|
68 | 54 | name: 'Home',
|
| 55 | +
|
69 | 56 | components: {
|
70 | 57 | NavLink,
|
71 | 58 | },
|
| 59 | +
|
| 60 | + setup() { |
| 61 | + const frontmatter = usePageFrontmatter<DefaultThemeHomePageFrontmatter>() |
| 62 | + const siteLocale = useSiteLocaleData() |
| 63 | +
|
| 64 | + const heroImage = computed(() => { |
| 65 | + if (!frontmatter.value.heroImage) { |
| 66 | + return null |
| 67 | + } |
| 68 | +
|
| 69 | + return withBase(frontmatter.value.heroImage) |
| 70 | + }) |
| 71 | +
|
| 72 | + const heroText = computed(() => { |
| 73 | + if (frontmatter.value.heroText === null) { |
| 74 | + return null |
| 75 | + } |
| 76 | + return frontmatter.value.heroText || siteLocale.value.title || 'Hello' |
| 77 | + }) |
| 78 | +
|
| 79 | + const heroAlt = computed( |
| 80 | + () => frontmatter.value.heroAlt || heroText.value || 'hero' |
| 81 | + ) |
| 82 | +
|
| 83 | + const tagline = computed(() => { |
| 84 | + if (frontmatter.value.tagline === null) { |
| 85 | + return null |
| 86 | + } |
| 87 | + return ( |
| 88 | + frontmatter.value.tagline || |
| 89 | + siteLocale.value.description || |
| 90 | + 'Welcome to your VuePress site' |
| 91 | + ) |
| 92 | + }) |
| 93 | +
|
| 94 | + const actions = computed(() => { |
| 95 | + if (!isArray(frontmatter.value.actions)) { |
| 96 | + return [] |
| 97 | + } |
| 98 | +
|
| 99 | + return frontmatter.value.actions.map( |
| 100 | + ({ text, link, type = 'primary' }) => ({ |
| 101 | + text, |
| 102 | + link, |
| 103 | + type, |
| 104 | + }) |
| 105 | + ) |
| 106 | + }) |
| 107 | +
|
| 108 | + const features = computed(() => { |
| 109 | + if (isArray(frontmatter.value.features)) { |
| 110 | + return frontmatter.value.features |
| 111 | + } |
| 112 | + return [] |
| 113 | + }) |
| 114 | +
|
| 115 | + const footer = computed(() => frontmatter.value.footer) |
| 116 | +
|
| 117 | + return { |
| 118 | + heroImage, |
| 119 | + heroAlt, |
| 120 | + heroText, |
| 121 | + tagline, |
| 122 | + actions, |
| 123 | + features, |
| 124 | + footer, |
| 125 | + } |
| 126 | + }, |
72 | 127 | })
|
73 | 128 | </script>
|
0 commit comments