Skip to content

Commit 9c6a317

Browse files
committed
refactor: move some mixins
1 parent d083932 commit 9c6a317

File tree

2 files changed

+48
-43
lines changed

2 files changed

+48
-43
lines changed

components/ArticleAndPage.vue

+38-5
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
<div class="details">
3434
<span>{{ longTimestamp(data.date) }}</span>
3535
<span class="separator">|</span>
36-
<nuxt-link class="author fancy" :to="`/authors/${getAuthor(data).slug}`">{{
37-
getAuthor(data).name
38-
}}</nuxt-link>
36+
<nuxt-link class="author fancy" :to="`/authors/${data._embedded.author[0].slug}`">
37+
<span>{{ data._embedded.author[0].name }}</span>
38+
</nuxt-link>
3939
</div>
4040
</div>
4141
<div class="content" v-html="data.content.rendered"></div>
@@ -47,6 +47,8 @@
4747
</template>
4848

4949
<script>
50+
import * as Vibrant from 'node-vibrant';
51+
5052
import FeaturedImage from '~/components/FeaturedImage.vue';
5153
import Comments from '~/components/Comments';
5254
@@ -57,8 +59,6 @@ export default {
5759
},
5860
5961
mixins: {
60-
getAuthor: Function,
61-
getColorAccentStyles: Function,
6262
getFeaturedImage: Function,
6363
longTimestamp: Function
6464
},
@@ -93,6 +93,39 @@ export default {
9393
});
9494
}
9595
}
96+
},
97+
98+
getColorAccentStyles(article) {
99+
return new Promise(function(resolve, reject) {
100+
const image =
101+
article._embedded['wp:featuredmedia'][0].media_details.sizes.thumbnail.source_url;
102+
103+
Vibrant.from(image).getPalette((err, palette) => {
104+
if (!err && palette.DarkMuted) {
105+
const { r, g, b } = palette.DarkMuted;
106+
107+
resolve(`
108+
<style>
109+
html,
110+
.featured-image .image-height {
111+
background: rgb(${r},${g},${b}) !important
112+
}
113+
main a {
114+
color: rgb(${r},${g},${b}) !important
115+
}
116+
main a:hover {
117+
color: rgb(${r},${g},${b}) !important
118+
}
119+
main a::after {
120+
background: rgb(${r},${g},${b}) !important
121+
}
122+
</style>
123+
`);
124+
} else {
125+
reject(err);
126+
}
127+
});
128+
});
96129
}
97130
},
98131

plugins/mixins.js

+10-38
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import Vue from 'vue';
22
import { differenceInDays, format, formatDistanceStrict } from 'date-fns';
3-
import * as Vibrant from 'node-vibrant';
43

54
Vue.mixin({
65
methods: {
@@ -21,6 +20,7 @@ Vue.mixin({
2120
return formatDistanceStrict(articleDate, todayDate, { addSuffix: true });
2221
}
2322
},
23+
2424
/**
2525
* Returns date formatted like 'May 9, 2017'
2626
* @param {String} date
@@ -30,6 +30,9 @@ Vue.mixin({
3030
return format(new Date(date), 'MMM d, yyyy');
3131
},
3232

33+
/**
34+
* Handles the click event of the header logo
35+
*/
3336
homeScrollTop() {
3437
if (window.location.pathname === '/') {
3538
this.$scrollTo(document, 500);
@@ -38,49 +41,18 @@ Vue.mixin({
3841
}
3942
},
4043

41-
getAuthor(article) {
42-
return article._embedded.author[0];
43-
},
44-
44+
/**
45+
* Returns the featured media object of the given article and size
46+
* @param {Object} article
47+
* @param {String} size
48+
* @return {Object} featured media object
49+
*/
4550
getFeaturedImage(article, size) {
4651
const featuredImage = article._embedded['wp:featuredmedia'];
4752

4853
if (featuredImage) {
4954
return featuredImage[0].media_details.sizes[size];
5055
}
51-
},
52-
53-
getColorAccentStyles(article) {
54-
return new Promise(function(resolve, reject) {
55-
const image =
56-
article._embedded['wp:featuredmedia'][0].media_details.sizes.thumbnail.source_url;
57-
58-
Vibrant.from(image).getPalette((err, palette) => {
59-
if (!err && palette.DarkMuted) {
60-
const { r, g, b } = palette.DarkMuted;
61-
62-
resolve(`
63-
<style>
64-
html,
65-
.featured-image .image-height {
66-
background: rgb(${r},${g},${b}) !important
67-
}
68-
main a {
69-
color: rgb(${r},${g},${b}) !important
70-
}
71-
main a:hover {
72-
color: rgb(${r},${g},${b}) !important
73-
}
74-
main a::after {
75-
background: rgb(${r},${g},${b}) !important
76-
}
77-
</style>
78-
`);
79-
} else {
80-
reject(err);
81-
}
82-
});
83-
});
8456
}
8557
}
8658
});

0 commit comments

Comments
 (0)