-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.js
196 lines (189 loc) · 4.51 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
const path = require(`path`)
const { createFilePath } = require(`gatsby-source-filesystem`)
let s = `
{
portifolio: allMdx(
filter: {fileAbsolutePath: {regex: "/content/portifolio/"}}
sort: { fields: [frontmatter___date], order: DESC }
limit: 1000
) {
edges {
node {
fields {
slug
}
frontmatter {
title
description
date(formatString: "MMMM DD, YYYY")
categorie
image
cover_image
video
text_1
youtube
image_1
text_2
image_2
image_3
text_3
image_4
image_5
text_4
image_6
text_5
image_7
image_8
image_9
image_10
image_11
image_12
image_13
image_14
image_15
image_16
image_17
image_18
image_19
image_20
image_21
image_22
image_23
image_24
image_25
image_26
text_6
text_7
testimonial
author
role
}
}
}
}
news: allMdx(
filter: {fileAbsolutePath: {regex: "/content/news/"}}
sort: { fields: [frontmatter___date], order: DESC }
limit: 1000
) {
edges {
node {
fields {
slug
}
frontmatter {
date(formatString: "DD/M/YYYY")
title
description
image
postType
quote
author
type
}
}
}
}
}
`
const createNewsPages = (result, createPage) => {
const newsTemplate = path.resolve(`./src/templates/news-post.tsx`)
const news = result.data.news.edges
news.forEach((post, index) => {
const previous = index === news.length - 1 ? null : news[index + 1].node
const next = index === 0 ? null : news[index - 1].node
createPage({
path: `${post.node.fields.slug}`,
component: newsTemplate,
context: {
news,
slug: post.node.fields.slug,
previous,
next,
},
})
})
}
const createPortifolio = (result, createPage) => {
const newsTemplate = path.resolve(`./src/templates/portifolio-post.tsx`)
const projects = result.data.portifolio.edges
projects.forEach((post, index) => {
const previous =
index === projects.length - 1 ? null : projects[index + 1].node
const next = index === 0 ? null : projects[index - 1].node
createPage({
path: `${post.node.fields.slug}`,
component: newsTemplate,
context: {
slug: post.node.fields.slug,
previous,
next,
},
})
})
}
exports.createPages = ({ graphql, actions }) => {
const { createPage } = actions
return graphql(s).then((result) => {
if (result.errors) {
throw result.errors
}
createPortifolio(result, createPage)
createNewsPages(result, createPage)
return null
})
}
exports.onCreateNode = ({ node, actions, getNode }) => {
const { createNodeField } = actions
if (node.internal.type === `Mdx`) {
const value = createFilePath({ node, getNode })
createNodeField({
name: `slug`,
node,
value,
})
}
}
exports.createSchemaCustomization = ({ actions }) => {
const { createTypes } = actions
const typeDefs = `
type MdxFrontmatter implements Node {
name: String
author: String
role: String
testimonial: String
author_image: String
description: String
image: String
text_1: String
text_2: String
text_3: String
text_4: String
text_5: String
text_6: String
image_1: String
image_2: String
image_3: String
image_4: String
image_5: String
image_6: String
image_7: String
image_8: String
image_9: String
image_10: String
image_11: String
image_12: String
image_13: String
image_14: String
image_15: String
image_16: String
image_17: String
image_18: String
image_19: String
image_20: String
image_21: String
image_22: String
}
`
createTypes(typeDefs)
}