瀏覽代碼

:bug: url parse and check error prevents proper loading

tags/0.9.0
j 4 年之前
父節點
當前提交
5cba90e63e
共有 2 個檔案被更改,包括 27 行新增12 行删除
  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 查看文件

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

+ 24
- 10
vue-theme/src/utils/helpers.js 查看文件

1
-const convertTitleCase = (type) => {
2
-    if(typeof type !== 'string') return ''
1
+const convertTitleCase = type => {
2
+    if (typeof type !== 'string') return ''
3
     return type.charAt(0).toUpperCase() + type.slice(1)
3
     return type.charAt(0).toUpperCase() + type.slice(1)
4
 }
4
 }
5
 
5
 
37
 const typeFromRoute = route => {
37
 const typeFromRoute = route => {
38
     let type = route.params.type ? route.params.type : route.fullPath.split('/')
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
         // Remove blank path sections and match to postTypes array
41
         // Remove blank path sections and match to postTypes array
42
         type = type
42
         type = type
43
             .filter(pathSection => pathSection != '')
43
             .filter(pathSection => pathSection != '')
44
             .filter(pathSection => postTypes.includes(pathSection))
44
             .filter(pathSection => postTypes.includes(pathSection))
45
-        
45
+
46
         // Only take the first match
46
         // Only take the first match
47
         type = type[0]
47
         type = type[0]
48
         console.log(`type derived from route.path: ${type}`)
48
         console.log(`type derived from route.path: ${type}`)
49
     }
49
     }
50
-    
50
+
51
     return type
51
     return type
52
 }
52
 }
53
 
53
 
54
-const ytThumbnail = (url, desiredSize) =>{
54
+const ytThumbnail = (url, desiredSize) => {
55
     const remove = [
55
     const remove = [
56
         '',
56
         '',
57
         'https:',
57
         'https:',
58
         'http:',
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
     let size = '0'
70
     let size = '0'
64
     switch (desiredSize) {
71
     switch (desiredSize) {
65
         case 'medium':
72
         case 'medium':
78
     return `https://img.youtube.com/vi/${videoId[0]}/${size}.jpg`
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
+}

Loading…
取消
儲存