-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.js
142 lines (130 loc) · 2.56 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
const path = require('path')
const slash = require('slash')
exports.createPages = async ({ graphql, actions }) => {
const { createPage } = actions
const opportunities = path.resolve('./src/templates/opportunities.js')
const companyStory = path.resolve('./src/templates/company-stories.js')
const companyStorySingle = path.resolve(
'./src/templates/company-stories-single.js'
)
const opportunitySingle = path.resolve(
'./src/templates/opportunities-single.js'
)
const factSingle = path.resolve('./src/templates/fact-single.js')
const templates = {
opportunity: opportunities,
company_story: companyStory,
}
const contact = path.resolve('./src/templates/contact.js')
/**
* Create company_story single page
*/
const companyStoryResult = await graphql(`
{
allWordpressWpCompanyStory {
nodes {
path
slug
}
}
}
`)
companyStoryResult.data.allWordpressWpCompanyStory.nodes.forEach(node => {
createPage({
path: node.path,
component: companyStorySingle,
context: {
slug: node.slug,
},
})
})
/**
* Create opportunities single page
*/
const opportunityResult = await graphql(`
{
allWordpressWpOpportunity {
nodes {
path
slug
}
}
}
`)
opportunityResult.data.allWordpressWpOpportunity.nodes.forEach(node => {
createPage({
path: node.path,
component: opportunitySingle,
context: {
slug: node.slug,
},
})
})
/**
* Create fact single page
*/
const factResult = await graphql(`
{
allWordpressWpFact {
nodes {
path
slug
}
}
}
`)
factResult.data.allWordpressWpFact.nodes.forEach(node => {
createPage({
path: node.path,
component: factSingle,
context: {
slug: node.slug,
},
})
})
/**
* Create kontakta oss page
*/
createPage({
path: 'kontakta-oss',
component: contact,
})
/**
* Create pages for all navigation items
*/
const navigationItemsResult = await graphql(`
{
allWordpressWpApiMenusMenusItems {
edges {
node {
items {
wordpress_id
title
description
object
url
}
}
}
}
}
`)
navigationItemsResult.data.allWordpressWpApiMenusMenusItems.edges
.map(edge => edge.node.items)
.reduce((pre, current) => pre.concat(current))
.filter(item => item.object !== 'custom')
.forEach(item => {
createPage({
path: item.url
.split('/')
.filter(Boolean)
.pop(),
component: slash(templates[item.object]),
context: {
title: item.title,
wordpress_id: item.object_id,
slug: item.object,
},
})
})
}