NEXT craftinamerica.org. Base setup for headless wordpress https://www.craftinamerica.org
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

index.vue 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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(action, {
  59. sortType: sortTypes.currentAndUpcoming,
  60. params,
  61. })
  62. // If no current or upcoming, get past events
  63. // to fill in the blanks
  64. if (eventsOrExhibitions.length < 1) {
  65. this.$store.dispatch(action, {
  66. sortType: sortTypes.past,
  67. params,
  68. })
  69. }
  70. } else if (!omit.includes(type)) {
  71. this.$store.dispatch(action, { sortType: null, params })
  72. }
  73. }
  74. if (!this['allPagesLoaded']) {
  75. await this.$store.dispatch('getAllPages', {
  76. sortType: null,
  77. params: null,
  78. })
  79. }
  80. await this.checkAndSetHero('welcome')
  81. await this.$store.dispatch('getRandomPosts', [
  82. 'artist',
  83. 'guide',
  84. 'object',
  85. 'technique',
  86. 'publication',
  87. 'post',
  88. ])
  89. },
  90. methods: {
  91. firstPostOfType(type) {
  92. return Object.values(this[`all${convertTitleCase(type)}s`])[0]
  93. },
  94. async checkAndSetHero(type) {
  95. this._clearHero(this.$store)
  96. // We always set a hero no matter what
  97. // Because the hero component will deal
  98. // with how to render based on hero.url
  99. if (!this.allPages) return console.warn('no pages in state', this)
  100. const page = this.allPages.filter(page => page.slug == type)[0]
  101. if (!page) return console.warn(`no page for ${type} found`)
  102. this.$store.commit('SET_HERO', this._setHeroInfo(page))
  103. },
  104. },
  105. }
  106. </script>
  107. <style lang="postcss">
  108. // prettier-ignore
  109. @import '../sss/variables.sss'
  110. @import '../sss/theme.sss'
  111. .page--index
  112. > header
  113. padding: $ms-0
  114. > article
  115. display: flex
  116. justify-content: space-around
  117. flex-direction: column
  118. align-items: stretch
  119. section
  120. ul
  121. list-style: none
  122. li.post
  123. background-color: white
  124. margin: 0 0 0.65em 0
  125. .featured-or-hero-image img
  126. max-height: $max-card-img-height
  127. p.excerpt
  128. -webkit-line-clamp: $card-line-clamp
  129. &.flipped
  130. li
  131. &:nth-of-type(4)
  132. /* p.excerpt, p.read-more
  133. display: none */
  134. header
  135. padding: 0.57em 0
  136. a
  137. display: none
  138. &.max
  139. > ul
  140. grid-template-columns:
  141. auto
  142. grid-template-rows:
  143. auto
  144. &.stickies // stickies grid on mobile
  145. ul
  146. display: grid
  147. grid-template-columns: repeat(2, 1fr)
  148. grid-gap: $ms--2
  149. &.flipped
  150. li
  151. &:nth-of-type(4)
  152. header
  153. padding: 0
  154. a
  155. display: block
  156. /* min-width 768px */
  157. @media (min-width: $medium)
  158. .page--index
  159. > article
  160. grid-gap: $ms--2 0
  161. > section
  162. ul
  163. display: grid
  164. grid-template-columns:
  165. 49.5% 24.35% 24.35%
  166. grid-template-rows: repeat(2, 1fr)
  167. gap: 0 $ms--2
  168. li
  169. margin: 0
  170. min-height: 10em
  171. &:nth-of-type(2), &:nth-of-type(3), &:nth-of-type(4), &:nth-of-type(5)
  172. /* p.excerpt
  173. -webkit-line-clamp: $card-line-clamp */
  174. .featured-or-hero-image img
  175. /* max-height: calc($max-card-img-height / 2) */
  176. max-height: $max-card-img-height
  177. /* n1 episode */
  178. &:nth-of-type(1)
  179. grid-column-start: 1
  180. grid-row-start: 1
  181. grid-row-end: 3
  182. /* n2 exhibition, n3 events */
  183. &:nth-of-type(2), &:nth-of-type(3)
  184. grid-column-start: 2
  185. grid-row-start: 1
  186. &:nth-of-type(3)
  187. grid-column-start: 3
  188. /* n4 artists, n5 posts */
  189. &:nth-of-type(4), &:nth-of-type(5)
  190. grid-column-start: 2
  191. grid-row-start: 2
  192. &:nth-of-type(5)
  193. grid-column-start: 3
  194. &.flipped
  195. grid-template-columns:
  196. 24.35% 24.35% 49.5%
  197. li
  198. &:nth-of-type(1)
  199. grid-row-end: 2
  200. &:nth-of-type(3)
  201. grid-column-start: 1
  202. grid-row-start: 2
  203. &:nth-of-type(5)
  204. grid-row-start: 1
  205. grid-row-end: 3
  206. &.max
  207. li .featured-or-hero-image img
  208. max-height: $max-card-img-height
  209. &.stickies
  210. .post
  211. min-width: 24.35%
  212. max-width: 32.73%
  213. ul
  214. &.flipped
  215. grid-template-columns:
  216. 24.35% 24.35% 49.5%
  217. li
  218. &:nth-of-type(1)
  219. grid-row-end: 2
  220. &:nth-of-type(3)
  221. grid-column-start: 1
  222. grid-row-start: 2
  223. &:nth-of-type(5)
  224. grid-row-start: 1
  225. grid-row-end: 3
  226. &:nth-of-type(4)
  227. header
  228. padding: 0
  229. a
  230. display: block
  231. &[class^="sticky-"]
  232. display: flex
  233. &.sticky-1
  234. > li .card--info
  235. display: flex
  236. > a:first-of-type
  237. width: 100%
  238. &.sticky-5
  239. grid-template-columns:
  240. 24.35% 24.35% 49.5%
  241. grid-template-rows:
  242. repeat(2, 1fr)
  243. gap: 3% 1%
  244. > li
  245. &:nth-of-type(1)
  246. grid-row-end: 2
  247. &:nth-of-type(2)
  248. grid-column-start: 2
  249. grid-row-start: 1
  250. grid-row-end: 2
  251. &:nth-of-type(3)
  252. grid-column-start: 1
  253. grid-row-start: 2
  254. margin: 0 0 8% 0
  255. &:nth-of-type(4)
  256. grid-column-start: 2
  257. grid-row-start: 2
  258. margin: 0 0 8% 0
  259. &:nth-of-type(5)
  260. grid-column-start: 3
  261. margin: 0 0 4% 0
  262. </style>