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.

single.vue 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <template lang="pug">
  2. .page--single.f-row.between
  3. article.f-grow.shadow
  4. header
  5. h1 {{ type }}:{{ $route.params.slug }} single
  6. section
  7. h4 {{ posts[$route.params.slug].title }}
  8. .block-wrapper(v-for="block in posts[$route.params.slug].blocks" v-html="block")
  9. sidebar(v-if="sidebar" :type="`${type}`")
  10. .shadow
  11. h1.t-up single slot
  12. div
  13. p body whatever
  14. </template>
  15. <script>
  16. import { mapGetters } from 'vuex'
  17. import sidebar from '@/components/sidebars/sidebar'
  18. export default {
  19. props: {
  20. sidebar: {
  21. type: Boolean
  22. }
  23. },
  24. components: {
  25. sidebar: sidebar
  26. },
  27. computed: {
  28. ...mapGetters({
  29. allPages: 'allPages',
  30. allPagesLoaded: 'allPagesLoaded',
  31. allPosts: 'allPosts',
  32. allPostsLoaded: 'allPostsLoaded',
  33. allArtists: 'allArtists',
  34. allArtistsLoaded: 'allArtistsLoaded',
  35. allEpisodes: 'allEpisodes',
  36. allEpisodesLoaded: 'allEpisodesLoaded',
  37. }),
  38. type() { // Checks for type and fixes Episodes route edge case
  39. return this.$route.params.type ? this.$route.params.type : this.$route.fullPath.slice(1)
  40. },
  41. posts() {
  42. let type = this.type.charAt(0).toUpperCase() + this.type.slice(1)
  43. // Return list keyed by slug
  44. return Object.values(this[`all${type}`]).reduce((postsMap, post) => {
  45. postsMap[post.slug] = post
  46. return postsMap
  47. }, {})
  48. },
  49. },
  50. mounted() {
  51. // TODO: this should be conditional after checking vuex state
  52. let type = this.$route.params.type
  53. type = type.charAt(0).toUpperCase() + type.slice(1)
  54. this.$store.dispatch(`getAll${type}`)
  55. }
  56. }
  57. </script>