-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconfig.js
48 lines (42 loc) · 1.58 KB
/
config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
|-------------------------------------------------------------------------------
| Development config https://maizzle.com/docs/environments
|-------------------------------------------------------------------------------
|
| This is the base configuration that Maizzle will use when you run commands
| like `npm run build` or `npm run dev`. Additional config files will
| inherit these settings, and can override them when necessary.
|
*/
import axios from 'axios'
/** @type {import('@maizzle/framework').Config} */
export default {
build: {
endpoint: 'https://css-tricks.com/wp-json/wp/v2/posts?page=1&per_page=7&offset=1&_embed=1',
content: ['emails/**/*.html'],
},
async beforeCreate({config}) {
try {
// Fetch data from endpoint
const { data } = await axios.get(config.build.endpoint)
// Create the posts object
config.posts = {}
// Create a collection of 'all' posts that we fetched
config.posts.all = data
// Create an object with the last two posts
config.posts.lastTwo = data.slice(-2)
// Set featured image
config.posts.featured = {}
config.posts.featured.image = data[0]._embedded['wp:featuredmedia'][0]['source_url'] || 'https://via.placeholder.com/600x400'
} catch (error) {
console.error(error)
}
},
formattedDate(str) {
const date = new Date(str)
return date.toLocaleDateString('en-US', {day: 'numeric', month: 'short', year: 'numeric'})
},
truncate(str, count = 60, clamp = ' [...]') {
return `${str.split(' ').splice(0, count).join(' ')}${clamp}`
},
}