-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgatsby-node.js
More file actions
executable file
·77 lines (68 loc) · 2.04 KB
/
gatsby-node.js
File metadata and controls
executable file
·77 lines (68 loc) · 2.04 KB
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
const path = require(`path`)
exports.onCreateNode = ({ node, actions, getNode }) => {
const { createNodeField } = actions
let slug
if (node.internal.type === `Airtable` && node.table === `Charities`) {
slug = `/${node.data.Name.replace(/ /g, '-')
.replace(/[,&]/g, '')
.toLowerCase()}/`
// Add slug as a field on the node.
createNodeField({ node, name: `slug`, value: slug })
}
}
exports.createPages = ({ graphql, actions }) => {
const { createPage, createRedirect } = actions
return new Promise((resolve, reject) => {
const pages = []
const tempChar = path.resolve(`src/templates/CharityTemplate.js`)
// Query for all markdown "nodes" and for the slug we previously created.
resolve(
graphql(
`
{
allAirtable(filter: { table: { eq: "Donations" } }) {
edges {
node {
id
data {
EffortName
Website
Description
Image {
url
}
}
}
}
}
}
`
).then(result => {
if (result.errors) {
result.errors.forEach(error => {
console.log(error)
})
reject(result.errors)
}
result.data.allAirtable.edges.forEach(edge => {
let path = edge.node.data.EffortName.replace(/ /g, '-')
.replace(/[,&]/g, '')
.toLowerCase()
createPage({
path: path, // required, we don't have frontmatter for this page hence separate if()
component: tempChar,
context: {
name: edge.node.data.EffortName,
link: edge.node.data.Url,
heading: edge.node.data.EffortName,
Description: edge.node.data.Description,
desc: edge.node.data.Description,
image: edge.node.data.Image,
},
})
})
return
})
)
})
}