|
|
@@ -19,16 +19,15 @@ import { mapGetters } from 'vuex'
|
|
19
|
19
|
import sidebar from '@/components/sidebars/sidebar'
|
|
20
|
20
|
import gallery from '@/components/gallery/'
|
|
21
|
21
|
|
|
|
22
|
+import { convertTitleCase, typeFromRoute } from '@/utils/helpers'
|
|
|
23
|
+
|
|
22
|
24
|
export default {
|
|
23
|
25
|
props: {
|
|
24
|
26
|
sidebar: {
|
|
25
|
27
|
type: Boolean
|
|
26
|
28
|
}
|
|
27
|
29
|
},
|
|
28
|
|
- components: {
|
|
29
|
|
- sidebar: sidebar,
|
|
30
|
|
- gallery: gallery
|
|
31
|
|
- },
|
|
|
30
|
+ components: { sidebar, gallery },
|
|
32
|
31
|
data() {
|
|
33
|
32
|
return {
|
|
34
|
33
|
images: [],
|
|
|
@@ -58,10 +57,10 @@ export default {
|
|
58
|
57
|
return flags.every(Boolean)
|
|
59
|
58
|
},
|
|
60
|
59
|
type() { // Checks for type and fixes Episodes route edge case
|
|
61
|
|
- return this.$route.params.type ? this.$route.params.type : this.$route.fullPath.slice(1)
|
|
|
60
|
+ return typeFromRoute(this.$route)
|
|
62
|
61
|
},
|
|
63
|
62
|
posts() {
|
|
64
|
|
- let type = this.convertTitleCase(this.type)
|
|
|
63
|
+ let type = convertTitleCase(this.type)
|
|
65
|
64
|
|
|
66
|
65
|
if(!type) return []
|
|
67
|
66
|
|
|
|
@@ -73,38 +72,33 @@ export default {
|
|
73
|
72
|
}
|
|
74
|
73
|
},
|
|
75
|
74
|
methods: {
|
|
76
|
|
- convertTitleCase(type) {
|
|
77
|
|
- return type.charAt(0).toUpperCase() + type.slice(1)
|
|
78
|
|
- },
|
|
79
|
75
|
pageBlocks(posts) {
|
|
80
|
|
- if(this.images.length < 1) return []
|
|
|
76
|
+ if(!posts) return []
|
|
81
|
77
|
return posts[this.$route.params.slug].blocks.map(block => {
|
|
82
|
78
|
if(block) return block
|
|
83
|
79
|
})
|
|
84
|
80
|
},
|
|
85
|
81
|
checkForImages(posts) {
|
|
86
|
82
|
if(Object.keys(posts).length == 0) return
|
|
87
|
|
-
|
|
|
83
|
+ console.log(posts)
|
|
88
|
84
|
this.pageBlocks(posts).forEach(block => {
|
|
89
|
|
- if(!block) return
|
|
90
|
|
-
|
|
|
85
|
+ console.log(block)
|
|
91
|
86
|
const doc = new DOMParser().parseFromString(block, 'text/html')
|
|
92
|
87
|
const gallery = doc.querySelectorAll('.blocks-gallery-item img')
|
|
93
|
|
-
|
|
94
|
|
- // add captions
|
|
95
|
|
- if(gallery.length) {
|
|
96
|
|
- this.images = [].slice.call(gallery).map(
|
|
97
|
|
- item => { return item.src }
|
|
98
|
|
- )
|
|
99
|
|
- }
|
|
|
88
|
+
|
|
|
89
|
+ if(!gallery || gallery.length < 1) return
|
|
|
90
|
+
|
|
|
91
|
+ this.images = [].slice.call(gallery).map(item => {
|
|
|
92
|
+ return item.src
|
|
|
93
|
+ })
|
|
100
|
94
|
})
|
|
101
|
95
|
},
|
|
102
|
96
|
checkAndSetHero(posts) {
|
|
103
|
97
|
const post = posts[this.$route.params.slug]
|
|
104
|
|
- if(post && post.hero){
|
|
105
|
|
- const json = JSON.parse(post.hero)
|
|
106
|
|
- this.$store.commit('SET_HERO', json)
|
|
107
|
|
- }
|
|
|
98
|
+ if(!post || ! post.hero) return
|
|
|
99
|
+
|
|
|
100
|
+ const json = JSON.parse(post.hero)
|
|
|
101
|
+ this.$store.commit('SET_HERO', json)
|
|
108
|
102
|
}
|
|
109
|
103
|
},
|
|
110
|
104
|
watch: {
|
|
|
@@ -116,16 +110,18 @@ export default {
|
|
116
|
110
|
|
|
117
|
111
|
// Gottas be on the next render tick
|
|
118
|
112
|
this.$nextTick(() => {
|
|
119
|
|
- const blocks = this.pageBlocks(newVal)
|
|
120
|
113
|
let gallery
|
|
121
|
|
- blocks.forEach(block => {
|
|
|
114
|
+ this.pageBlocks(newVal).forEach(block => {
|
|
|
115
|
+ if(!block) return
|
|
122
|
116
|
gallery = document.querySelectorAll('.blocks-gallery-item figure')
|
|
123
|
117
|
})
|
|
124
|
118
|
|
|
125
|
119
|
if(!gallery || gallery.length < 1) return
|
|
126
|
120
|
|
|
127
|
121
|
gallery.forEach((item, i) => {
|
|
128
|
|
- item.addEventListener('mouseup', event => { this.fullscreengallery = i })
|
|
|
122
|
+ item.addEventListener('mouseup', event => {
|
|
|
123
|
+ this.fullscreengallery = i
|
|
|
124
|
+ })
|
|
129
|
125
|
})
|
|
130
|
126
|
})
|
|
131
|
127
|
|
|
|
@@ -133,7 +129,7 @@ export default {
|
|
133
|
129
|
},
|
|
134
|
130
|
created() {
|
|
135
|
131
|
if(!this.allLoaded) {
|
|
136
|
|
- let type = this.convertTitleCase(this.$route.params.type)
|
|
|
132
|
+ let type = convertTitleCase(this.$route.params.type)
|
|
137
|
133
|
console.log('Retrieving...', type)
|
|
138
|
134
|
this.$store.dispatch(`getAll${type}`)
|
|
139
|
135
|
}
|