ソースを参照

:recycle: consolidating date formatter in helper

tags/0.9.0
J 4年前
コミット
5569efbe45

+ 2
- 4
vue-theme/src/components/card.vue ファイルの表示

22
 
22
 
23
 <script>
23
 <script>
24
 import featuredImage from '@/components/featured-image'
24
 import featuredImage from '@/components/featured-image'
25
+import { formatDate } from '@/utils/helpers'
25
 export default {
26
 export default {
26
     components: { featuredImage },
27
     components: { featuredImage },
27
     props: ['type', 'content', 'wide', 'hide-type'],
28
     props: ['type', 'content', 'wide', 'hide-type'],
28
     methods: {
29
     methods: {
29
-        dateFrom(unix, includeTime) {
30
-            const d = new Date(parseInt(unix) * 1000)
31
-            return includeTime ? d.toLocaleString('en-US', { timeZone: 'UTC' }) : d.toLocaleDateString('en-US', { timeZone: 'UTC' })
32
-        }
30
+        dateFrom: (unix, includeTime) => formatDate(unix, includeTime),
33
     }
31
     }
34
 }
32
 }
35
 </script>
33
 </script>

+ 4
- 6
vue-theme/src/components/sidebars/events.vue ファイルの表示

3
 h3.t-up {{ listType }} events
3
 h3.t-up {{ listType }} events
4
 ul.t-up
4
 ul.t-up
5
     li(v-for="post in events")
5
     li(v-for="post in events")
6
-        featured-image(:post="post", thumbsize="'standard'")
6
+        router-link(:to="`/event/${post.slug}`")
7
+            featured-image(:post="post", thumbsize="'standard'")
7
         router-link(:to="`/event/${post.slug}`")
8
         router-link(:to="`/event/${post.slug}`")
8
             p.t-up {{ post.title }}
9
             p.t-up {{ post.title }}
9
         p {{ dateFrom(post.start, true) }} &ndash; {{ dateFrom(post.end, true) }}
10
         p {{ dateFrom(post.start, true) }} &ndash; {{ dateFrom(post.end, true) }}
12
 <script>
13
 <script>
13
 import featuredImage from '@/components/featured-image'
14
 import featuredImage from '@/components/featured-image'
14
 import { postTypeGetters } from '@/pages/mixin-post-types'
15
 import { postTypeGetters } from '@/pages/mixin-post-types'
15
-import { sortTypes } from '@/utils/helpers'
16
+import { sortTypes, formatDate } from '@/utils/helpers'
16
 
17
 
17
 export default {
18
 export default {
18
     mixins: [postTypeGetters],
19
     mixins: [postTypeGetters],
31
         }
32
         }
32
     },
33
     },
33
     methods: {
34
     methods: {
34
-        dateFrom(unix, includeTime) {
35
-            const d = new Date(parseInt(unix) * 1000)
36
-            return includeTime ? d.toLocaleString('en-US', { timeZone: 'UTC' }) : d.toLocaleDateString('en-US', { timeZone: 'UTC' })
37
-        },
35
+        dateFrom: (unix, includeTime) => formatDate(unix, includeTime),
38
         async getPosts() {
36
         async getPosts() {
39
             this.$store.commit('CLEAR_EVENTS')
37
             this.$store.commit('CLEAR_EVENTS')
40
             const upcoming = this.$store.dispatch(
38
             const upcoming = this.$store.dispatch(

+ 4
- 6
vue-theme/src/components/sidebars/exhibitions.vue ファイルの表示

3
 h3.t-up {{ listType }} exhibitions
3
 h3.t-up {{ listType }} exhibitions
4
 ul.t-up
4
 ul.t-up
5
     li(v-for="post in exhibitions")
5
     li(v-for="post in exhibitions")
6
-        featured-image(:post="post", thumbsize="'standard'")
6
+        router-link(:to="`/exhibition/${post.slug}`")
7
+            featured-image(:post="post", thumbsize="'standard'")
7
         router-link(:to="`/exhibition/${post.slug}`")
8
         router-link(:to="`/exhibition/${post.slug}`")
8
             p.t-up {{ post.title }}
9
             p.t-up {{ post.title }}
9
         p {{ dateFrom(post.start, false) }} &ndash; {{ dateFrom(post.end, false) }}
10
         p {{ dateFrom(post.start, false) }} &ndash; {{ dateFrom(post.end, false) }}
12
 <script>
13
 <script>
13
 import featuredImage from '@/components/featured-image'
14
 import featuredImage from '@/components/featured-image'
14
 import { postTypeGetters } from '@/pages/mixin-post-types'
15
 import { postTypeGetters } from '@/pages/mixin-post-types'
15
-import { sortTypes } from '@/utils/helpers'
16
+import { sortTypes, formatDate } from '@/utils/helpers'
16
 
17
 
17
 export default {
18
 export default {
18
     mixins: [postTypeGetters],
19
     mixins: [postTypeGetters],
31
         }
32
         }
32
     },
33
     },
33
     methods: {
34
     methods: {
34
-        dateFrom(unix, includeTime) {
35
-            const d = new Date(parseInt(unix) * 1000)
36
-            return includeTime ? d.toLocaleString('en-US', { timeZone: 'UTC' }) : d.toLocaleDateString('en-US', { timeZone: 'UTC' })
37
-        },
35
+        dateFrom: (unix, includeTime) => formatDate(unix, includeTime),
38
         async getPosts() {
36
         async getPosts() {
39
             this.$store.commit('CLEAR_EXHIBITIONS')
37
             this.$store.commit('CLEAR_EXHIBITIONS')
40
             const upcoming = this.$store.dispatch(
38
             const upcoming = this.$store.dispatch(

+ 4
- 6
vue-theme/src/pages/single.vue ファイルの表示

47
 
47
 
48
 import { postTypeGetters, scrollTop, heroUtils } from './mixin-post-types'
48
 import { postTypeGetters, scrollTop, heroUtils } from './mixin-post-types'
49
 
49
 
50
-import { postTypes, sortTypes, convertTitleCase, dePluralize, typeFromRoute } from '@/utils/helpers'
50
+import { postTypes, sortTypes, convertTitleCase, dePluralize, typeFromRoute, formatDate } from '@/utils/helpers'
51
 
51
 
52
 const TIMEOUT = 1
52
 const TIMEOUT = 1
53
 
53
 
174
         /**
174
         /**
175
          * Date Object from unix strings from db
175
          * Date Object from unix strings from db
176
          */
176
          */
177
-        dateFrom(unix, includeTime) {
178
-            const d = new Date(parseInt(unix) * 1000)
179
-            return includeTime ? d.toLocaleString('en-US', { timeZone: 'UTC' }) : d.toLocaleDateString('en-US', { timeZone: 'UTC' })
180
-        },
177
+        dateFrom: (unix, includeTime) => formatDate(unix, includeTime),
181
 
178
 
182
         async loadPostData() {
179
         async loadPostData() {
183
             this.loading = true
180
             this.loading = true
200
 
197
 
201
             // Look if it exists before you try and load everything!
198
             // Look if it exists before you try and load everything!
202
             if (!singlePostData) {
199
             if (!singlePostData) {
203
-                console.error('Could not find single post in store; Fetching everything...')
200
+                console.warn('Could not find single post in store; Fetching everything...')
204
                 const res = await this.$store.dispatch(
201
                 const res = await this.$store.dispatch(
205
                     `getAll${convertTitleCase(this.type)}s`,
202
                     `getAll${convertTitleCase(this.type)}s`,
206
                     { sortType: null, params: null}
203
                     { sortType: null, params: null}
222
         },
219
         },
223
     },
220
     },
224
     watch: {
221
     watch: {
222
+        // This fires navigating to and away
225
         $route(to, from) {
223
         $route(to, from) {
226
             // Only load post data when navigating TO a single page
224
             // Only load post data when navigating TO a single page
227
             const path = to.fullPath.split('/').filter(p => p)
225
             const path = to.fullPath.split('/').filter(p => p)

+ 6
- 0
vue-theme/src/utils/helpers.js ファイルの表示

90
     return `https://img.youtube.com/vi/${videoId[0]}/${size}.jpg`
90
     return `https://img.youtube.com/vi/${videoId[0]}/${size}.jpg`
91
 }
91
 }
92
 
92
 
93
+const formatDate = (unix, includeTime) => {
94
+    const d = new Date(parseInt(unix) * 1000)
95
+    return includeTime ? d.toLocaleString('en-US', { timeZone: 'UTC' }) : d.toLocaleDateString('en-US', { timeZone: 'UTC' })
96
+}
97
+
93
 export {
98
 export {
94
     convertTitleCase,
99
     convertTitleCase,
95
     dePluralize,
100
     dePluralize,
97
     sortTypes,
102
     sortTypes,
98
     postTypes,
103
     postTypes,
99
     ytThumbnail,
104
     ytThumbnail,
105
+    formatDate
100
 }
106
 }

読み込み中…
キャンセル
保存