-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.js
49 lines (42 loc) · 977 Bytes
/
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
require("dotenv").config()
const path = require(`path`)
const { AIRTABLE_TABLE_NAME: tableName } = process.env
exports.createPages = ({ graphql, actions }) => {
const { createPage } = actions
return new Promise((resolve, reject) => {
graphql(`
{
allAirtable(filter: { table: { eq: "${tableName}" } }) {
nodes {
data {
slug
}
}
}
}
`).then(({ errors, data }) => {
if (errors) {
reject(errors)
}
const component = path.resolve(`./src/templates/single-item.jsx`)
data.allAirtable.nodes.map(({ data: { slug } }) => {
createPage({
component,
context: { slug },
path: `/${slug}`,
})
})
resolve()
})
})
}
exports.onCreatePage = ({ page, actions }) => {
const { createPage } = actions
createPage({
...page,
context: {
...page.context,
tableName,
},
})
}