浏览代码

:bug: lots of hero fixes and fail-overs

tags/0.9.0
j 4 年前
父节点
当前提交
05d22fdd48
共有 4 个文件被更改,包括 40 次插入10 次删除
  1. 21
    3
      vue-theme/src/components/hero.vue
  2. 5
    2
      vue-theme/src/pages/list.vue
  3. 4
    0
      vue-theme/src/pages/single.vue
  4. 10
    5
      vue-theme/src/store/index.js

+ 21
- 3
vue-theme/src/components/hero.vue 查看文件

@@ -9,12 +9,20 @@
9 9
         ).embedded
10 10
         .blank.f-col(v-else)
11 11
             h3(v-if="heroText") {{ heroText }}
12
+            img(:src="getThumbnailFromYt(showHero)" alt="hero alt image")
12 13
             button(v-if="showPlaybutton" @click="isPlaying = true") play
14
+    .hero--image(v-else-if="heroType === 'image'")
15
+        .hero--image--overlay.f-col
16
+            div(v-html="heroText")
17
+        img(:src="showHero" alt="hero alt image")
13 18
     .hero--image(v-else)
14
-        img(:src="showHero" alt="hero image")
19
+        .hero--image--overlay.f-col
20
+            div(v-html="heroText")
21
+
15 22
 </template>
16 23
 
17 24
 <script>
25
+import { ytThumbnail } from '@/utils/helpers'
18 26
 import { mapState } from 'vuex'
19 27
 
20 28
 export default {
@@ -39,11 +47,15 @@ export default {
39 47
     methods: {
40 48
         onResize() {
41 49
             this.heroHeight = this.$el.offsetWidth / 1.8
50
+        },
51
+        getThumbnailFromYt(url) {
52
+            return ytThumbnail(url, 'max')
42 53
         }
43 54
     },
44 55
     mounted() {
45 56
         this.heroHeight = this.$el.offsetWidth / 1.8
46
-        this.$nextTick(() => { window.addEventListener('resize', this.onResize) })
57
+        this.$nextTick(() => { 
58
+            window.addEventListener('resize', this.onResize) })
47 59
     },
48 60
     watch: {
49 61
         $route() {
@@ -70,8 +82,14 @@ export default {
70 82
     min-height: 35%
71 83
     width: 100%
72 84
     &--image
85
+        width: 100%
73 86
         > img
74
-            max-width: 100%
87
+            width: 100%
88
+        &--overlay
89
+            color: #ffffff
90
+            position: absolute
91
+            top: 30%
92
+            width: 100%
75 93
     .embedded
76 94
         height: 100%
77 95
         width: 100%

+ 5
- 2
vue-theme/src/pages/list.vue 查看文件

@@ -77,7 +77,6 @@ export default {
77 77
              * so if a sortBy is specified we return it sorted or
78 78
              * we fail over to sorted by date
79 79
              */
80
-            console.log(this.sortBy)
81 80
             return this.sortBy ? this[`all${type}`] : sortedByRecent
82 81
         },
83 82
     },
@@ -104,11 +103,15 @@ export default {
104 103
             }
105 104
             const page = this.allPages[type]
106 105
             if(!page) return
106
+            
107 107
             let json = { url: page.featured, heroType: 'image' }
108 108
             if(page.hero && JSON.parse(page.hero) && JSON.parse(page.hero).url) {
109 109
                 json = JSON.parse(page.hero)
110 110
                 json.heroType = 'video'
111 111
             }
112
+            if(page && page.content) {
113
+                json.text = this.allPages[type].content
114
+            }
112 115
             this.$store.commit('SET_HERO', json)
113 116
         },
114 117
     },
@@ -126,7 +129,7 @@ export default {
126 129
         console.log(`${type} already loaded?:`, this[`all${type}Loaded`])
127 130
         
128 131
         this.checkAndSetHero(this.type)
129
-        console.log(this.$store)
132
+        
130 133
         if(!this[`all${type}Loaded`]) this.getPosts()
131 134
     }
132 135
 }

+ 4
- 0
vue-theme/src/pages/single.vue 查看文件

@@ -145,6 +145,10 @@ export default {
145 145
                 json = JSON.parse(post.hero)
146 146
                 json.heroType = 'video'
147 147
             }
148
+            // No featured or youTube
149
+            if(!json.url) {
150
+                json.heroType = null
151
+            }
148 152
             this.$store.commit('SET_HERO', json)
149 153
         },
150 154
         

+ 10
- 5
vue-theme/src/store/index.js 查看文件

@@ -35,19 +35,24 @@ const mutations = {
35 35
         if (!hero) return
36 36
 
37 37
         if (hero.url) {
38
-            state.hero.text = state.hero.url = hero.url
39
-            state.hero.type = hero.type
38
+            state.hero.text = hero.text
39
+            state.hero.url = hero.url
40
+            state.hero.type = hero.heroType
40 41
 
41
-            state.hero.playbutton = hero.type === 'video' ? true : false
42
+            state.hero.playbutton = hero.heroType === 'video' ? true : false
42 43
         } else {
43
-            state.hero.text = hero
44
+            console.warn('No hero to set')
45
+            state.hero.url = hero.url
46
+            state.hero.type = hero.heroType
47
+            state.hero.text = ''
48
+            state.hero.playbutton = false
44 49
         }
45 50
     },
46 51
     CLEAR_HERO(state) {
47 52
         state.hero = {
48 53
             url: null,
49 54
             type: null,
50
-            text: 'sample hero text',
55
+            text: '',
51 56
             playbutton: false,
52 57
         }
53 58
     },

正在加载...
取消
保存