Home.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <template>
  2. <header class="hero">
  3. <img
  4. v-if="data.heroImage"
  5. :src="heroImageSrc"
  6. :alt="data.heroAlt || 'hero'"
  7. >
  8. <h1
  9. v-if="data.heroText !== null"
  10. id="main-title"
  11. >
  12. {{ data.heroText || siteTitle || 'Hello' }}
  13. </h1>
  14. <p
  15. v-if="data.tagline !== null"
  16. class="description"
  17. >
  18. {{ data.tagline || siteDescription || 'Welcome to your VitePress site' }}
  19. </p>
  20. <p
  21. v-if="data.actionText && data.actionLink"
  22. class="action"
  23. >
  24. <NavBarLink :item="actionLink" />
  25. </p>
  26. <slot name="hero" />
  27. </header>
  28. <div
  29. v-if="data.features && data.features.length"
  30. class="features"
  31. >
  32. <div
  33. v-for="(feature, index) in data.features"
  34. :key="index"
  35. class="feature"
  36. >
  37. <h2>{{ feature.title }}</h2>
  38. <p>{{ feature.details }}</p>
  39. </div>
  40. <slot name="features" />
  41. </div>
  42. <div
  43. v-if="data.footer"
  44. class="footer"
  45. >
  46. {{ data.footer }}
  47. <slot name="footer" />
  48. </div>
  49. </template>
  50. <script lang="ts">
  51. import { defineComponent, computed } from 'vue'
  52. import NavBarLink from './NavBarLink.vue'
  53. import { withBase } from '../utils'
  54. import { useRoute, useSiteData } from 'vitepress'
  55. export default defineComponent({
  56. components: {
  57. NavBarLink
  58. },
  59. setup() {
  60. const route = useRoute()
  61. const siteData = useSiteData()
  62. const data = computed(() => route.data.frontmatter)
  63. const actionLink = computed(() => ({
  64. link: data.value.actionLink,
  65. text: data.value.actionText
  66. }))
  67. const heroImageSrc = computed(() => withBase(data.value.heroImage))
  68. const siteTitle = computed(() => siteData.value.title)
  69. const siteDescription = computed(() => siteData.value.description)
  70. return {
  71. data,
  72. actionLink,
  73. heroImageSrc,
  74. siteTitle,
  75. siteDescription
  76. }
  77. }
  78. })
  79. </script>
  80. <style scoped>
  81. .hero {
  82. text-align: center;
  83. }
  84. .hero img {
  85. max-width: 100%;
  86. max-height: 280px;
  87. display: block;
  88. margin: 3rem auto 1.5rem;
  89. }
  90. .hero h1 {
  91. font-size: 3rem;
  92. }
  93. .hero h1,
  94. .hero .description,
  95. .hero .action {
  96. margin: 1.8rem auto;
  97. }
  98. .hero .description {
  99. max-width: 35rem;
  100. font-size: 1.6rem;
  101. line-height: 1.3;
  102. /* TODO: calculating lighten 40% color with using style :vars from `--text-color` */
  103. color: #6a8bad;
  104. }
  105. ::v-deep(.nav-link) {
  106. display: inline-block;
  107. font-size: 1.2rem;
  108. color: #fff;
  109. background-color: var(--accent-color);
  110. margin-left: 0;
  111. padding: 0.8rem 1.6rem;
  112. border-radius: 4px;
  113. transition: background-color .1s ease;
  114. box-sizing: border-box;
  115. /* TODO: calculating darken 10% color with using style vars from `--accent-color` */
  116. border-bottom: 1px solid #389d70;
  117. }
  118. ::v-deep(.nav-link:hover) {
  119. /* TODO: calculating lighten 10% color with using style vars from `--accent-color` */
  120. background-color: #4abf8a;
  121. }
  122. .features {
  123. border-top: 1px solid var(--border-color);
  124. padding: 1.2rem 0;
  125. margin-top: 2.5rem;
  126. display: flex;
  127. flex-wrap: wrap;
  128. align-items: flex-start;
  129. align-content: stretch;
  130. justify-content: space-between;
  131. }
  132. .feature {
  133. flex-grow: 1;
  134. flex-basis: 30%;
  135. max-width: 30%;
  136. }
  137. .feature h2 {
  138. font-size: 1.4rem;
  139. font-weight: 500;
  140. border-bottom: none;
  141. padding-bottom: 0;
  142. /* TODO: calculating lighten 10% color with using style :vars from `--text-color` */
  143. color: #3a5169;
  144. }
  145. .feature p {
  146. /* TODO: calculating lighten 25% color with using style :vars from `--text-color` */
  147. color: #4e6e8e;
  148. }
  149. .footer {
  150. padding: 2.5rem;
  151. border-top: 1px solid var(--border-color);
  152. text-align: center;
  153. /* TODO: calculating lighten 25% color with using style :vars from `--text-color` */
  154. color: #4e6e8e;
  155. }
  156. @media screen and (max-width: 719px) {
  157. .features {
  158. flex-direction: column;
  159. }
  160. .feature {
  161. max-width: 100%;
  162. padding: 0 2.5rem;
  163. }
  164. }
  165. @media screen and (max-width: 429px) {
  166. .hero img {
  167. max-height: 210px;
  168. margin: 2rem auto 1.2rem;
  169. }
  170. .hero h1 {
  171. font-size: 2rem;
  172. }
  173. .hero h1,
  174. .hero .description,
  175. .hero .action {
  176. margin: 1.2rem auto;
  177. }
  178. .hero .description {
  179. font-size: 1.2rem;
  180. }
  181. .hero .action-button {
  182. font-size: 1rem;
  183. padding: 0.6rem 1.2rem;
  184. }
  185. .feature h2 {
  186. font-size: 1.25rem;
  187. }
  188. }
  189. </style>