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 9.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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(:class="[`sticky-${Object.keys(allSticky).length}`, 'flipped']")
  10. //- if sticky
  11. li.post.shadow(v-for="sticky in allSticky")
  12. card(:content="sticky" :type="`${sticky.type}`")
  13. //- firstRow: ['episode', 'exhibition', 'event', 'short', 'post'], exceprt on episode only.
  14. section
  15. ul
  16. li.post.shadow(v-for="type in firstRow")
  17. card(:content="firstPostOfType(type)" :type="type")
  18. //- secondRow: 'artist', // This is only ONE post, excerpt on artist
  19. section.max
  20. ul.w-max
  21. li.post.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: ['object', 'technique', 'publication', 'center', 'guide'], exceprt on guide only
  24. section
  25. ul.flipped
  26. li.post.shadow(v-for="type in thirdRow")
  27. .random--wrapper(v-for="post in [...randomPosts, ...allPages.filter(p => p.slug == 'center')].filter(p => p.type == type)")
  28. card(:content="post" :type="type")
  29. </template>
  30. <script>
  31. import { postTypeGetters, scrollTop, heroUtils } 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, heroUtils],
  36. components: { card },
  37. data() {
  38. return {
  39. firstRow: ['episode', 'exhibition', 'event', 'short', 'post'],
  40. secondRow: 'artist', // This is only ONE post
  41. thirdRow: ['object', 'technique', 'publication', 'page', 'guide'],
  42. // ideal iteration
  43. // thirdRow: ['object', 'talks', 'publication', 'center', 'guide'],
  44. }
  45. },
  46. async created() {
  47. // console.log(wp)
  48. const omit = ['page']
  49. for (let type of postTypes) {
  50. const action = `getAll${convertTitleCase(type)}s`
  51. // Limit the amount of posts because we
  52. // only need the most recent
  53. const params = { limit: 1 }
  54. // We try and fetch EVERYTHING except
  55. // for EVENTS and EXHIBITIONS
  56. if (['event', 'exhibition'].includes(type)) {
  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. else if (!omit.includes(type)){
  72. this.$store.dispatch(action, { sortType: null, params })
  73. }
  74. }
  75. if (!this['allPagesLoaded']) {
  76. await this.$store.dispatch('getAllPages', { sortType: null, params: null })
  77. }
  78. await this.checkAndSetHero('welcome')
  79. await this.$store.dispatch('getRandomPosts', ['artist', 'guide', 'object', 'technique', 'publication', 'post'])
  80. },
  81. methods: {
  82. firstPostOfType(type) {
  83. return Object.values(this[`all${convertTitleCase(type)}s`])[0]
  84. },
  85. async checkAndSetHero(type) {
  86. this._clearHero(this.$store)
  87. // We always set a hero no matter what
  88. // Because the hero component will deal
  89. // with how to render based on hero.url
  90. if(!this.allPages) return console.warn('no pages in state', this)
  91. const page = this.allPages.filter(
  92. page => page.slug == type,
  93. )[0]
  94. if(!page) return console.warn(`no page for ${type} found`)
  95. this.$store.commit('SET_HERO', this._setHeroInfo(page))
  96. },
  97. },
  98. }
  99. </script>
  100. <style lang="postcss">
  101. // prettier-ignore
  102. @import '../sss/variables.sss'
  103. @import '../sss/theme.sss'
  104. .page--index
  105. > header
  106. padding: $ms-0
  107. > article
  108. display: flex
  109. justify-content: space-around
  110. flex-direction: column
  111. align-items: stretch
  112. section
  113. ul
  114. list-style: none
  115. li.post
  116. background-color: white
  117. margin: 0 0 0.65em 0
  118. .featured-or-hero-image img
  119. max-height: $max-card-img-height
  120. p.excerpt
  121. -webkit-line-clamp: $card-line-clamp
  122. &.max
  123. > ul
  124. grid-template-columns:
  125. auto
  126. grid-template-rows:
  127. auto
  128. /* min-width 768px */
  129. @media (min-width: $medium)
  130. .page--index
  131. > article
  132. grid-gap: $ms--2 0
  133. > section
  134. ul
  135. display: grid
  136. grid-template-columns:
  137. 49.5% 24.25% 24.25%
  138. grid-template-rows: repeat(2, 1fr)
  139. gap: 0 $ms--2
  140. li
  141. margin: 0
  142. min-height: 10em
  143. &:nth-of-type(2), &:nth-of-type(3), &:nth-of-type(4), &:nth-of-type(5)
  144. /* p.excerpt
  145. -webkit-line-clamp: $card-line-clamp */
  146. .featured-or-hero-image img
  147. /* max-height: calc($max-card-img-height / 2) */
  148. max-height: $max-card-img-height
  149. /* n1 episode */
  150. &:nth-of-type(1)
  151. grid-column-start: 1
  152. grid-row-start: 1
  153. grid-row-end: 3
  154. /* n2 exhibition, n3 events */
  155. &:nth-of-type(2), &:nth-of-type(3)
  156. grid-column-start: 2
  157. grid-row-start: 1
  158. &:nth-of-type(3)
  159. grid-column-start: 3
  160. /* n4 artists, n5 posts */
  161. &:nth-of-type(4), &:nth-of-type(5)
  162. grid-column-start: 2
  163. grid-row-start: 2
  164. &:nth-of-type(5)
  165. grid-column-start: 3
  166. &.flipped
  167. grid-template-columns:
  168. 24.25% 24.25% 49.5%
  169. li
  170. &:nth-of-type(1)
  171. grid-row-end: 2
  172. &:nth-of-type(3)
  173. grid-column-start: 1
  174. grid-row-start: 2
  175. &:nth-of-type(5)
  176. grid-row-start: 1
  177. grid-row-end: 3
  178. &.max
  179. li .featured-or-hero-image img
  180. max-height: $max-card-img-height
  181. &.stickies
  182. .post
  183. min-width: 24.25%
  184. ul
  185. &.flipped
  186. grid-template-columns:
  187. 24.25% 24.25% 49.5%
  188. li
  189. &:nth-of-type(1)
  190. grid-row-end: 2
  191. &:nth-of-type(3)
  192. grid-column-start: 1
  193. grid-row-start: 2
  194. &:nth-of-type(5)
  195. grid-row-start: 1
  196. grid-row-end: 3
  197. &[class^="sticky-"]
  198. display: flex
  199. &.sticky-1
  200. > li .card--info
  201. display: flex
  202. > a:first-of-type
  203. width: 100%
  204. &.sticky-5
  205. grid-template-columns:
  206. 24.25% 24.25% 49.5%
  207. grid-template-rows:
  208. repeat(2, 1fr)
  209. gap: 3% 1%
  210. > li
  211. &:nth-of-type(1)
  212. grid-row-end: 2
  213. &:nth-of-type(2)
  214. grid-column-start: 2
  215. grid-row-start: 1
  216. grid-row-end: 2
  217. &:nth-of-type(3)
  218. grid-column-start: 1
  219. grid-row-start: 2
  220. margin: 0 0 8% 0
  221. &:nth-of-type(4)
  222. grid-column-start: 2
  223. grid-row-start: 2
  224. margin: 0 0 8% 0
  225. &:nth-of-type(5)
  226. grid-column-start: 3
  227. margin: 0 0 4% 0
  228. </style>