瀏覽代碼

:bug: fixes featured-image or hero loading parse bug | created component for hero vs featured image logic

tags/0.9.0
J 4 年之前
父節點
當前提交
39ea7697ba
共有 2 個文件被更改,包括 49 次插入17 次删除
  1. 32
    0
      vue-theme/src/components/featured-image.vue
  2. 17
    17
      vue-theme/src/pages/list.vue

+ 32
- 0
vue-theme/src/components/featured-image.vue 查看文件

@@ -0,0 +1,32 @@
1
+<template lang="pug">
2
+.featured-or-hero-image
3
+    img(v-if="featured" :src="featured" alt="post thumbnail")
4
+    img(v-else-if="hero && hero.url" :src="getThumbnailFromYt(hero.url)" alt="post thumbnail from YouTube")
5
+    
6
+    //- Errors
7
+    p(v-else-if="hero && !hero.url") ERROR: hero url undefined
8
+    p(v-else) ERROR: no featured image or hero
9
+</template>
10
+
11
+<script>
12
+import { ytThumbnail } from '@/utils/helpers'
13
+
14
+export default {
15
+    props: {
16
+        post: { required:true }
17
+    },
18
+    computed: {
19
+        featured() {
20
+            return this.post.featuredImage ? this.post.featuredImage : null
21
+        },
22
+        hero() {
23
+            return this.post.hero && JSON.parse(this.post.hero) ? JSON.parse(this.post.hero) : null
24
+        }
25
+    },
26
+    methods: {
27
+        getThumbnailFromYt(url) {
28
+            return ytThumbnail(url, 'medium')
29
+        }
30
+    }
31
+}
32
+</script>

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

@@ -3,25 +3,20 @@
3 3
     article.f-grow
4 4
         header.f-row.center.t-up
5 5
             h1 {{ type }} list
6
+            h3(v-if="!loaded") loading...
6 7
             span(v-if="sortBy")
7 8
                 h1 &nbsp;sorted by {{ sortBy.replace('-', ' ') }}
8 9
 
9
-        .posts(v-if="posts" :class="{ 'is-grid': grid }")
10
+        .posts(v-if="posts && loaded" :class="{ 'is-grid': grid }")
10 11
             section(v-for="post in posts" :key="post.slug").shadow.post
11
-                router-link(:to="`/${type}/${post.slug}`")
12
-                    p {{post.featured}}
13
-                    ul.f-row
14
-                        img(v-if="post.featured" :src="post.featured" alt="post thumbnail")
15
-                        img(v-else-if="JSON.parse(post.hero) && JSON.parse(post.hero).url" :src="getThumbnailFromYt(JSON.parse(post.hero).url)" alt="post thumbnail from YouTube")
16
-                        p(v-else-if="post.hero") ERROR: {{ post.hero }}
17
-                        p(v-else) ERROR: no thumbnail
18
-                        li.f-col.between
19
-                            h2.t-up {{ post.title }}
20
-                            h4 {{ post.date }}
21
-                            p Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras eu elit in ex pharetra volutpat ac at magna. Duis libero est, imperdiet non sollicitudin vel, eleifend at ante...
12
+                header
13
+                    router-link(:to="`/${type}/${post.slug}`")
14
+                        featured-image(:post="post")
15
+                        h2.t-up {{ post.title }}
16
+                article
17
+                    h4 {{ post.date }}
18
+                    p Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras eu elit in ex pharetra volutpat ac at magna. Duis libero est, imperdiet non sollicitudin vel, eleifend at ante...
22 19
 
23
-        //- posts not grid
24
-        
25 20
         footer
26 21
             p {{ `${type} count: ${Object.values(posts).length}` }}
27 22
             p {{ `show sidebar: ${sidebar}` }}
@@ -35,13 +30,14 @@
35 30
 </template>
36 31
 
37 32
 <script>
33
+import featuredImage from '@/components/featured-image'
38 34
 import sidebar from '@/components/sidebars/sidebar'
39 35
 import { postTypeGetters, scrollTop } from './mixin-post-types'
40 36
 
41 37
 import { convertTitleCase, typeFromRoute, sortTypes, ytThumbnail } from '@/utils/helpers'
42 38
 
43 39
 export default {
44
-    components: { sidebar },
40
+    components: { sidebar, featuredImage },
45 41
     props: {
46 42
         sidebar: { type: Boolean },
47 43
         grid: { type: Boolean },
@@ -56,6 +52,11 @@ export default {
56 52
             let type = convertTitleCase(this.type)
57 53
             return this.sortBy ? `getAll${type.split('/')[0]}` : `getAll${type}`
58 54
         },
55
+        loaded() {
56
+            let type = convertTitleCase(this.type)
57
+            if(!type) return
58
+            return this[`all${type}Loaded`]
59
+        },
59 60
         posts() {
60 61
             let type = convertTitleCase(this.type)
61 62
             if(!type) return
@@ -85,11 +86,11 @@ export default {
85 86
             
86 87
             // Sorting
87 88
             let sort = this.sortBy ? this.sortBy : this.$route.path.split('/').pop()
89
+            
88 90
             if(Object.values(sortTypes).includes(sort)) {
89 91
                 console.log('trying to sort by:', sort)
90 92
                 console.log(`sortTypes includes ${sort}:`, Object.values(sortTypes).includes(sort))
91 93
             }
92
-
93 94
             // Is this a sort type?
94 95
             if(this.type !== sort || !Object.values(sortTypes).includes(sort)) sort = null
95 96
             
@@ -113,7 +114,6 @@ export default {
113 114
     created() {
114 115
         let type = convertTitleCase(this.type)
115 116
         // console.log('already loaded ?:', this[`all${type}Loaded`])
116
-        
117 117
         if(!this[`all${type}Loaded`]) this.setHeroAndGetPosts()
118 118
     }
119 119
 }

Loading…
取消
儲存