Ver código fonte

:bug: url parse and check error prevents proper loading

tags/0.9.0
j 4 anos atrás
pai
commit
5cba90e63e
2 arquivos alterados com 27 adições e 12 exclusões
  1. 3
    2
      vue-theme/src/pages/list.vue
  2. 24
    10
      vue-theme/src/utils/helpers.js

+ 3
- 2
vue-theme/src/pages/list.vue Ver arquivo

@@ -6,13 +6,13 @@
6 6
             span(v-if="sortBy")
7 7
                 h1  sorted by {{ sortBy.replace('-', ' ') }}
8 8
 
9
-        .posts(:class="{ 'is-grid': grid }")
9
+        .posts(v-if="posts" :class="{ 'is-grid': grid }")
10 10
             section(v-for="post in posts" :key="post.slug").shadow.post
11 11
                 router-link(:to="`/${type}/${post.slug}`")
12 12
                     p {{post.featured}}
13 13
                     ul.f-row
14 14
                         img(v-if="post.featured" :src="post.featured" alt="post thumbnail")
15
-                        img(v-else-if="post.hero && JSON.parse(post.hero).url" :src="getThumbnailFromYt(JSON.parse(post.hero).url)" alt="post thumbnail from YouTube")
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 16
                         p(v-else-if="post.hero") ERROR: {{ post.hero }}
17 17
                         p(v-else) ERROR: no thumbnail
18 18
                         li.f-col.between
@@ -103,6 +103,7 @@ export default {
103 103
     },
104 104
     watch: {
105 105
         $route(to, from){
106
+            console.log(this.sidebar)
106 107
             let type = convertTitleCase(this.type)
107 108
             let sort = this.sortBy ? this.sortBy : to.path.split('/').pop()
108 109
             

+ 24
- 10
vue-theme/src/utils/helpers.js Ver arquivo

@@ -1,5 +1,5 @@
1
-const convertTitleCase = (type) => {
2
-    if(typeof type !== 'string') return ''
1
+const convertTitleCase = type => {
2
+    if (typeof type !== 'string') return ''
3 3
     return type.charAt(0).toUpperCase() + type.slice(1)
4 4
 }
5 5
 
@@ -37,29 +37,36 @@ const postTypes = [
37 37
 const typeFromRoute = route => {
38 38
     let type = route.params.type ? route.params.type : route.fullPath.split('/')
39 39
 
40
-    if(!route.params.type) {
40
+    if (!route.params.type) {
41 41
         // Remove blank path sections and match to postTypes array
42 42
         type = type
43 43
             .filter(pathSection => pathSection != '')
44 44
             .filter(pathSection => postTypes.includes(pathSection))
45
-        
45
+
46 46
         // Only take the first match
47 47
         type = type[0]
48 48
         console.log(`type derived from route.path: ${type}`)
49 49
     }
50
-    
50
+
51 51
     return type
52 52
 }
53 53
 
54
-const ytThumbnail = (url, desiredSize) =>{
54
+const ytThumbnail = (url, desiredSize) => {
55 55
     const remove = [
56 56
         '',
57 57
         'https:',
58 58
         'http:',
59
-        'youtu.be'
59
+        'youtu.be',
60
+        'www.youtube.com',
61
+        'youtube.com',
62
+        'embed'
60 63
     ]
61
-    const videoId = url.split('/').filter(urlSection => !remove.includes(urlSection))
62
-    
64
+    const videoId = url
65
+        .split('/')
66
+        .filter(urlSection => !remove.includes(urlSection))
67
+        
68
+    // Uncomment to see what the url transformer is finding
69
+    // console.log('video:', videoId[0])
63 70
     let size = '0'
64 71
     switch (desiredSize) {
65 72
         case 'medium':
@@ -78,4 +85,11 @@ const ytThumbnail = (url, desiredSize) =>{
78 85
     return `https://img.youtube.com/vi/${videoId[0]}/${size}.jpg`
79 86
 }
80 87
 
81
-export { convertTitleCase, dePluralize, typeFromRoute, sortTypes, postTypes, ytThumbnail }
88
+export {
89
+    convertTitleCase,
90
+    dePluralize,
91
+    typeFromRoute,
92
+    sortTypes,
93
+    postTypes,
94
+    ytThumbnail,
95
+}

Carregando…
Cancelar
Salvar