NEXT craftinamerica.org. Base setup for headless wordpress https://www.craftinamerica.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.vue 8.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. // Homepage grid
  2. <template lang="pug">
  3. .page--index.f-col.between
  4. header.w-max(v-if="allPages.welcome")
  5. .page-content(v-html="allPages.welcome.content")
  6. article.w-max
  7. //- sticky section
  8. section(v-if="allSticky && Object.keys(allSticky).length").stickies
  9. ul.flipped(:class="[`sticky-${Object.keys(allSticky).length}`]")
  10. //- if sticky
  11. li.shadow(v-for="sticky in allSticky")
  12. card(:content="sticky" :type="`${sticky.type}`")
  13. //- firstRow: ['episodes', 'exhibitions', 'events', 'shorts', 'posts'], exceprt on episodes only.
  14. section
  15. ul
  16. li.shadow(v-for="type in firstRow")
  17. card(:content="firstPostOfType(type)" :type="type")
  18. //- secondRow: 'artists', // This is only ONE post, excerpt on artist
  19. section.max
  20. ul.w-max
  21. li.shadow(v-for="post in randomPosts.filter(p => p.type == secondRow)")
  22. card(v-if="post" :content="post" :type="`${post.type}`" :wide="true")
  23. //- (thirdRow) firstRow.flipped: ['guides', 'objects', 'techniques', 'talks', 'center'], exceprt on guides only
  24. section
  25. ul.flipped
  26. li.shadow(v-for="type in thirdRow")
  27. .random--wrapper(v-for="post in randomPosts.filter(p => p.type == type)")
  28. card(:content="post" :type="type")
  29. </template>
  30. <script>
  31. import { postTypeGetters, scrollTop } from './mixin-post-types'
  32. import card from '@/components/card.vue'
  33. import { convertTitleCase, postTypes, sortTypes } from '@/utils/helpers'
  34. export default {
  35. mixins: [postTypeGetters, scrollTop],
  36. components: { card },
  37. data() {
  38. return {
  39. firstRow: ['episode', 'exhibition', 'event', 'artist', 'post'],
  40. secondRow: 'artist', // This is only ONE post
  41. thirdRow: ['episode', 'exhibition', 'event', 'artist', 'post'],
  42. }
  43. },
  44. async created() {
  45. // console.log(wp)
  46. const omit = ['event', 'exhibition']
  47. for (let type of postTypes) {
  48. const action = `getAll${convertTitleCase(type)}s`
  49. // Limit the amount of posts because we
  50. // only need the most recent
  51. const params = { limit: 1 }
  52. // We try and fetch EVERYTHING except
  53. // for EVENTS and EXHIBITIONS
  54. if (!omit.includes(type)) {
  55. this.$store.dispatch(action, { sortType: null, params })
  56. } else {
  57. // Only grab the current or upcoming on load
  58. const eventsOrExhibitions = await this.$store.dispatch(
  59. action,
  60. {
  61. sortType: sortTypes.currentAndUpcoming,
  62. params
  63. }
  64. )
  65. // If no current or upcoming, get past events
  66. // to fill in the blanks
  67. if (eventsOrExhibitions.length < 1) {
  68. this.$store.dispatch(action, { sortType: sortTypes.past, params })
  69. }
  70. }
  71. }
  72. await this.$store.dispatch('getRandomPosts', ['episode', 'exhibition', 'event', 'artist', 'artist', 'post'])
  73. this.checkAndSetHero('welcome')
  74. },
  75. methods: {
  76. async checkAndSetHero(type) {
  77. if (!this['allPagesLoaded']) {
  78. await this.$store.dispatch('getAllPages', { sortType: null, params: null })
  79. }
  80. // We always set a hero no matter what
  81. // Because the hero component will deal
  82. // with how to render based on hero.url
  83. const page = this.allPages.filter(
  84. page => page.slug == type + 's',
  85. )[0]
  86. let hero = { url: null, heroType: null }
  87. // Clear the hero and bail
  88. if(!page) return this.$store.commit('SET_HERO', hero)
  89. hero.url = page.featured
  90. hero.heroType = 'image'
  91. if (
  92. page.hero &&
  93. JSON.parse(page.hero) &&
  94. JSON.parse(page.hero).url
  95. ) {
  96. json = JSON.parse(page.hero)
  97. json.heroType = 'video'
  98. }
  99. // No featured or youTube
  100. if (!hero.url) {
  101. hero.heroType = null
  102. }
  103. // Set the hero text to the post title or excerpt
  104. hero.text = page && page.excerpt ? page.excerpt : page.title
  105. this.$store.commit('SET_HERO', hero)
  106. },
  107. firstPostOfType(type) {
  108. return Object.values(this[`all${convertTitleCase(type)}s`])[0]
  109. },
  110. },
  111. }
  112. </script>
  113. <style lang="postcss">
  114. // prettier-ignore
  115. @import '../sss/variables.sss'
  116. @import '../sss/theme.sss'
  117. .page--index
  118. > header
  119. padding: $ms-0
  120. > article
  121. display: flex
  122. justify-content: space-around
  123. flex-direction: column
  124. align-items: stretch
  125. section
  126. ul
  127. list-style: none
  128. li
  129. margin: 0 0 $ms-0 0
  130. &.max
  131. margin: 0
  132. > ul
  133. grid-template-columns:
  134. auto
  135. grid-template-rows:
  136. auto
  137. /* min-width 768px */
  138. @media (min-width: $medium)
  139. .page--index > article > section
  140. &.stickies
  141. margin: 0 0 2% 0
  142. &.max
  143. margin: 35px 0 20px
  144. ul
  145. display: grid
  146. grid-template-columns:
  147. 49.5% 24.25% 24.25%
  148. grid-template-rows:
  149. 48% 48%
  150. gap: 3% 1%
  151. li
  152. margin: 0
  153. min-height: 10em
  154. /* background-color: purple */
  155. background-color: white
  156. /* n1 episode */
  157. &:nth-of-type(1)
  158. grid-column-start: 1
  159. grid-row-start: 1
  160. grid-row-end: 3
  161. /* n2 exhibition, n3 events */
  162. &:nth-of-type(2), &:nth-of-type(3)
  163. grid-column-start: 2
  164. grid-row-start: 1
  165. &:nth-of-type(3)
  166. grid-column-start: 3
  167. /* n4 artists, n5 posts */
  168. &:nth-of-type(4), &:nth-of-type(5)
  169. grid-column-start: 2
  170. grid-row-start: 2
  171. &:nth-of-type(5)
  172. grid-column-start: 3
  173. &.stickies
  174. ul
  175. &.flipped
  176. grid-template-columns:
  177. 24.25% 24.25% 49.5%
  178. li
  179. &:nth-of-type(1)
  180. grid-row-end: 2
  181. &:nth-of-type(3)
  182. grid-column-start: 1
  183. grid-row-start: 2
  184. &:nth-of-type(5)
  185. grid-row-start: 1
  186. grid-row-end: 3
  187. &.sticky-1
  188. display: flex
  189. > li .card--info
  190. display: flex
  191. > a:first-of-type
  192. width: 100%
  193. &.sticky-2
  194. display: flex
  195. &.sticky-3
  196. display: flex
  197. &.sticky-4
  198. display: flex
  199. &.sticky-5
  200. grid-template-columns:
  201. 24.25% 24.25% 49.5%
  202. grid-template-rows:
  203. 48% 48%
  204. gap: 3% 1%
  205. > li
  206. &:nth-of-type(1)
  207. grid-row-end: 2
  208. &:nth-of-type(2)
  209. grid-column-start: 2
  210. grid-row-start: 1
  211. grid-row-end: 2
  212. &:nth-of-type(3)
  213. grid-column-start: 1
  214. grid-row-start: 2
  215. margin: 0 0 8% 0
  216. &:nth-of-type(4)
  217. grid-column-start: 2
  218. grid-row-start: 2
  219. margin: 0 0 8% 0
  220. &:nth-of-type(5)
  221. grid-column-start: 3
  222. margin: 0 0 4% 0
  223. </style>