-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.js
70 lines (66 loc) · 1.69 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
const path = require("path")
const siteData = require("./siteData.json")
const map = require("lodash/map")
exports.createPages = async ({ graphql, actions }) => {
const { createPage } = actions
let gql = `{
allPublisherpages {
nodes {
data {
title
slug
body
dependencies
}
}
}
`
map(siteData.objects, (value, key) => {
let newKey = key.replace("-", "")
newKey = newKey.charAt(0).toUpperCase() + newKey.slice(1)
gql += `all${newKey} {
nodes {
data {
title
slug
content
id
}
}
}`
})
gql += "}"
const result = await graphql(gql)
return Promise.all(
// Pages
result.data.allPublisherpages.nodes.map(async node => {
console.log(`Making page ${node.data.slug}`)
await createPage({
path: node.data.slug,
component: path.resolve("./src/pages/page.js"),
context: {
url: node.data.slug,
dependencies: node.data.dependencies || [],
},
})
}),
map(siteData.objects, (value, key) => {
if (key !== "publisher-pages") {
let newKey = key.replace("-", "")
newKey = newKey.charAt(0).toUpperCase() + newKey.slice(1)
result.data[`all${newKey}`].nodes.map(async node => {
console.log(`Making ${key} ${node.data.slug}`)
await createPage({
path: `${key}/${node.data.slug}`,
component: path.resolve("./src/pages/data_item.js"),
context: {
url: node.data.slug,
key: key.replace("-", ""),
id: node.data.id,
},
})
})
}
})
)
}