-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.js
136 lines (131 loc) · 3.7 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
const Promise = require('bluebird');
const path = require('path');
exports.createPages = ({ graphql, actions }) => {
const { createPage } = actions;
return new Promise((resolve, reject) => {
const PostTemplate = path.resolve('./src/templates/Post.js');
const ServicePortfolio = path.resolve('./src/components/ServicePortfolio/index.js')
const ProjectTemplate = path.resolve('./src/templates/Project/index.js')
resolve(
graphql(
`
{
allContentfulPost {
edges {
node {
id
slug
title
photo {
file {
url
}
}
content {
json
}
}
}
}
allContentfulService {
edges {
node {
newName
categories
newColor
category
}
}
}
allContentfulPortfolio {
edges {
node {
active
asset {
file {
url
}
}
category
subcategory
clientName
colorTitle
contentful_id
description {
description
}
linkProject
subtitle
title
titlePortfolioPage
type
banner {
file {
url
}
}
bannerDimensions
designAssets {
description
file {
url
details {
image {
height
width
}
}
fileName
}
}
}
}
}
}
`,
).then((result) => {
if (result.errors) {
console.log(result.errors);
reject(result.errors);
}
const posts = result.data.allContentfulPost.edges;
const services = result.data.allContentfulService.edges;
const projects = result.data.allContentfulPortfolio.edges;
services.forEach((service) => {
createPage({
path: `/portfolio/${service.node.category}/`,
component: ServicePortfolio,
context: {
newName: service.node.newName,
categories: service.node.categories,
newColor: service.node.newColor,
categoryType: service.node.category,
},
});
});
posts.forEach((post) => {
createPage({
path: `/news/${post.node.slug}/`,
component: PostTemplate,
context: {
slug: post.node.slug,
},
});
});
projects && projects.forEach((project) => {
if(project.active){
createPage({
path: `/portfolio/${project.node.category}/${project.node.contentful_id}/`,
component: ProjectTemplate,
context: {
servicesInfo: services,
projectType: project.node.type,
project: project.node,
},
});
}
});
}),
);
});
};