1
1
<template >
2
2
<article class =" single-article" >
3
3
<ArticleFeaturedImage
4
- v-if =" featuredImage "
4
+ v-if =" getFeaturedImage(article, 'large') "
5
5
:expanded =" expanded"
6
- :featured-image =" featuredImage "
6
+ :featured-image =" getFeaturedImage(article, 'large') "
7
7
/>
8
8
<transition name =" slide-fade" >
9
- <div class =" narrow" :class =" { expanded: expanded, 'no-featured-image': !featuredImage }" >
9
+ <div
10
+ class =" narrow"
11
+ :class =" { expanded: expanded, 'no-featured-image': !getFeaturedImage(article, 'large') }"
12
+ >
10
13
<button
11
14
class =" expand-featured-image"
12
15
title =" Show full image"
13
- @click.prevent =" expandFeaturedImage "
16
+ @click.prevent =" expanded = !expanded "
14
17
:class =" { expanded: expanded }"
15
- v-if =" featuredImage "
18
+ v-if =" getFeaturedImage(article, 'large') "
16
19
>
17
20
<svg
18
21
fill =" #000000"
30
33
<div class =" details" >
31
34
<span >{{ longTimestamp(article.date) }}</span >
32
35
<span class =" separator" >|</span >
33
- <nuxt-link class =" author fancy" :to =" `/authors/${author .slug}`" >{{
34
- author .name
36
+ <nuxt-link class =" author fancy" :to =" `/authors/${getAuthor(article) .slug}`" >{{
37
+ getAuthor(article) .name
35
38
}}</nuxt-link >
36
39
</div >
37
40
</div >
44
47
</template >
45
48
46
49
<script >
47
- import * as Vibrant from ' node-vibrant' ;
48
50
import ArticleFeaturedImage from ' ~/components/ArticleFeaturedImage.vue' ;
49
51
import ArticleComments from ' ~/components/ArticleComments' ;
50
52
51
- if (process .browser ) {
52
- require (' lightgallery.js' );
53
- require (' lg-zoom.js' );
54
- require (' lg-thumbnail.js' );
55
- }
56
-
57
53
export default {
58
54
async asyncData ({ app, store, params }) {
59
- let article = await app .$axios .get (
60
- ` ${ process .env .WORDPRESS_API_URL } /wp/v2/posts?slug=${ params .article } &_embed`
61
- );
62
- store .commit (' setArticle' , article .data [0 ]);
63
- },
64
-
65
- beforeMount () {
66
- if (this .featuredImage ) {
67
- let img = this .article ._embedded [' wp:featuredmedia' ][0 ].media_details .sizes .thumbnail
68
- .source_url ;
69
-
70
- Vibrant .from (img).getPalette ((err , palette ) => {
71
- if (! err) {
72
- this .$store .commit (' setFeaturedColor' , palette);
73
- }
74
- });
75
- }
55
+ const { data } = await app .$axios .get (` ${ process .env .WORDPRESS_API_URL } /wp/v2/posts` , {
56
+ params: {
57
+ slug: params .article ,
58
+ _embed: true
59
+ }
60
+ });
61
+ return { article: data[0 ] };
76
62
},
77
63
78
64
mixins: {
65
+ getAuthor: Function ,
66
+ getColorAccentStyles: Function ,
67
+ getFeaturedImage: Function ,
79
68
longTimestamp: Function
80
69
},
81
70
@@ -84,98 +73,37 @@ export default {
84
73
ArticleComments
85
74
},
86
75
87
- computed: {
88
- article () {
89
- return this .$store .state .article ;
90
- },
91
- author () {
92
- return this .$store .state .article ._embedded .author [0 ];
93
- },
94
- featuredImage () {
95
- let featuredImage = this .$store .state .article ._embedded [' wp:featuredmedia' ];
96
-
97
- if (featuredImage) {
98
- return (
99
- featuredImage[0 ].media_details .sizes .large ||
100
- featuredImage[0 ].media_details .sizes .full ||
101
- false
102
- );
103
- } else {
104
- return null ;
105
- }
106
- }
107
- },
108
-
109
76
data () {
110
77
return {
111
- disqusReady: false ,
112
78
expanded: false ,
113
79
colorAccentStyles: null
114
80
};
115
81
},
116
82
117
- head () {
118
- return {
119
- title: ` ${ this .article .title .rendered } | ${ this .$store .state .meta .name } ` ,
120
- meta: [{ description: this .article .excerpt .rendered }]
121
- };
122
- },
123
-
124
83
methods: {
125
- expandFeaturedImage () {
126
- if (! this .expanded ) {
127
- this .$router .push ({ query: { image: null } });
128
- } else {
129
- this .$router .push ({ query: null });
130
- }
131
- this .expanded = ! this .expanded ;
132
- },
133
- loadFeaturedImageExpanded () {
134
- if (this .$route .query .image === null ) {
135
- this .expanded = true ;
136
- }
137
- },
138
- gallery () {
84
+ initGallery () {
139
85
let galleries = document .querySelectorAll (' .content > .gallery' );
140
86
141
- for (let i = 0 ; i < galleries .length ; i++ ) {
142
- lightGallery (galleries[i], {
143
- download: false ,
144
- selector: ' a'
145
- });
87
+ if (galleries .length ) {
88
+ if (process .browser ) {
89
+ require (' lightgallery.js' );
90
+ require (' lg-zoom.js' );
91
+ require (' lg-thumbnail.js' );
92
+ }
93
+
94
+ for (let i = 0 ; i < galleries .length ; i++ ) {
95
+ lightGallery (galleries[i], {
96
+ download: false ,
97
+ selector: ' a'
98
+ });
99
+ }
146
100
}
147
101
}
148
102
},
149
103
150
104
mounted () {
151
- this .gallery ();
152
- this .loadFeaturedImageExpanded ();
153
- },
154
-
155
- watch: {
156
- ' $store.state.featuredColor' () {
157
- const { DarkMuted } = this .$store .state .featuredColor ;
158
-
159
- if (DarkMuted) {
160
- this .colorAccentStyles = `
161
- <style>
162
- html,
163
- .featured-image .image-height {
164
- background: rgb(${ DarkMuted ._rgb [0 ]} ,${ DarkMuted ._rgb [1 ]} ,${ DarkMuted ._rgb [2 ]} ) !important
165
- }
166
- main a {
167
- color: rgb(${ DarkMuted ._rgb [0 ]} ,${ DarkMuted ._rgb [1 ]} ,${ DarkMuted ._rgb [2 ]} ) !important
168
- }
169
- main a:hover {
170
- color: rgb(${ DarkMuted ._rgb [0 ]} ,${ DarkMuted ._rgb [1 ]} ,${ DarkMuted ._rgb [2 ]} ) !important
171
- }
172
- main a::after {
173
- background: rgb(${ DarkMuted ._rgb [0 ]} ,${ DarkMuted ._rgb [1 ]} ,${ DarkMuted ._rgb [2 ]} ) !important
174
- }
175
- </style>
176
- ` ;
177
- }
178
- }
105
+ this .initGallery ();
106
+ this .getColorAccentStyles (this .article ).then (styles => (this .colorAccentStyles = styles));
179
107
}
180
108
};
181
109
</script >
0 commit comments