Просмотр исходного кода

:recycle: trying to unify set hero logic

tags/0.9.0
J 4 лет назад
Родитель
Сommit
cae85883fa
2 измененных файлов: 23 добавлений и 7 удалений
  1. 21
    5
      vue-theme/src/pages/index.vue
  2. 2
    2
      vue-theme/src/pages/list.vue

+ 21
- 5
vue-theme/src/pages/index.vue Просмотреть файл

@@ -84,11 +84,21 @@ export default {
84 84
     methods: {
85 85
         async checkAndSetHero(type) {
86 86
             if (!this['allPagesLoaded']) {
87
-                await this.$store.dispatch('getAllPages')
87
+                await this.$store.dispatch('getAllPages', { sortType: null, params: null })
88 88
             }
89
-            const page = this.allPages[type]
90
-            if (!page) return
91
-            let json = { url: page.featured, heroType: 'image' }
89
+            // We always set a hero no matter what
90
+            // Because the hero component will deal
91
+            // with how to render based on hero.url
92
+            const page = this.allPages.filter(
93
+                page => page.slug == type + 's',
94
+            )[0]
95
+            let hero = { url: null, heroType: null }
96
+            
97
+            // Clear the hero and bail
98
+            if(!page) return this.$store.commit('SET_HERO', hero)
99
+
100
+            hero.url = page.featured
101
+            hero.heroType = 'image'
92 102
             if (
93 103
                 page.hero &&
94 104
                 JSON.parse(page.hero) &&
@@ -97,7 +107,13 @@ export default {
97 107
                 json = JSON.parse(page.hero)
98 108
                 json.heroType = 'video'
99 109
             }
100
-            this.$store.commit('SET_HERO', json)
110
+            // No featured or youTube
111
+            if (!hero.url) {
112
+                hero.heroType = null
113
+            }
114
+            // Set the hero text to the post title or excerpt
115
+            hero.text = page && page.excerpt ? page.excerpt : page.title
116
+            this.$store.commit('SET_HERO', hero)
101 117
         },
102 118
         firstPostOfType(type) {
103 119
             return Object.values(this[`all${convertTitleCase(type)}s`])[0]

+ 2
- 2
vue-theme/src/pages/list.vue Просмотреть файл

@@ -132,7 +132,7 @@ export default {
132 132
         },
133 133
         async checkAndSetHero(type) {
134 134
             if (!this['allPagesLoaded']) {
135
-                await this.$store.dispatch('getAllPages', { sortType: null, params: null})
135
+                await this.$store.dispatch('getAllPages', { sortType: null, params: null })
136 136
             }
137 137
 
138 138
             // We always set a hero no matter what
@@ -195,7 +195,7 @@ export default {
195 195
                 // console.warn('sort not found:', sort)
196 196
                 sort = null
197 197
             }
198
-            
198
+
199 199
             // TODO: Track last loaded page per post type
200 200
             // Less http calls
201 201
             this.page = 1

Загрузка…
Отмена
Сохранить