forked from hygraph/gatsby-starter-hygraph-blog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.js
119 lines (112 loc) · 2.45 KB
/
gatsby-node.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
const path = require('path')
exports.createPages = async ({ actions: { createPage }, graphql }) => {
const { data } = await graphql(
`
{
pages: allGraphCmsPage {
nodes {
id
content {
markdownNode {
childMdx {
body
}
}
}
seo {
description
image {
url
}
keywords
title
}
slug
subtitle
title
}
}
posts: allGraphCmsPost(sort: { fields: date, order: ASC }) {
edges {
nextPost: next {
slug
title
}
page: node {
id
author {
id
name
title
}
content {
markdownNode {
childMdx {
body
}
}
}
date: formattedDate
excerpt
seo {
description
image {
url
}
keywords
title
}
slug
title
}
previousPost: previous {
slug
title
}
}
}
}
`
)
if (data.errors) throw data.errors
data.posts.edges.forEach(({ nextPost, page, previousPost }) => {
createPage({
component: path.resolve('./src/templates/blog-post.js'),
context: {
id: page.id,
page,
previousPost,
nextPost,
},
path: `/posts/${page.slug}`,
})
})
data.pages.nodes.forEach((page) => {
createPage({
component: path.resolve('./src/templates/default-page.js'),
context: {
page,
},
path: `/${page.slug}`,
})
})
}
exports.createResolvers = ({ createResolvers }) => {
const resolvers = {
GraphCMS_Post: {
formattedDate: {
type: 'String',
resolve: (source) => {
const date = new Date(source.date)
return new Intl.DateTimeFormat('en-US', {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric',
}).format(date)
},
},
},
}
createResolvers(resolvers)
}