/
gatsby-node.js
90 lines (82 loc) · 2.08 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
/**
* Implement Gatsby's Node APIs in this file.
*
* See: https://www.gatsbyjs.org/docs/node-apis/
*/
const path = require(`path`)
const { makeSlug } = require("./src/utils/slug")
const { countCategoriesOrganizations } = require("./src/utils/gatsby")
exports.createPages = async ({ graphql, actions }) => {
const { createPage } = actions
const { data } = await graphql(`
query PagesQuery {
categories: allAirtable(filter: { table: { eq: "Categories" } }) {
nodes {
id
data {
Name
Organizations {
id
data {
Role
}
}
Parent {
id
}
}
}
}
organizations: allAirtable(filter: { table: { eq: "Organizations" } }) {
nodes {
id
data {
Name
Role
}
}
}
capitalTypes: allAirtable(filter: { table: { eq: "Capital Types" } }) {
nodes {
id
data {
Slug
}
}
}
}
`)
const categoryCounts = countCategoriesOrganizations(data.categories.nodes)
data.categories.nodes.forEach(category => {
createPage({
path: `/categories/${makeSlug(category.data.Name)}`,
component: path.resolve(`./src/templates/organizations.js`),
context: {
categoryName: category.data.Name,
categoryId: category.id,
},
})
})
createPage({
path: `/organizations`,
component: path.resolve(`./src/templates/organizations.js`),
})
data.capitalTypes.nodes.forEach(({ id, data: { Slug: slug }}) => {
createPage({
path: `/capital/${slug}`,
component: path.resolve(`./src/pages/capital.js`),
context: {
activeTypeId: id,
active: true
},
})
})
// Create the organizations pages
data.organizations.nodes.forEach(org => {
createPage({
path: `/organizations/${makeSlug(org.data.Name)}`,
component: path.resolve(`./src/templates/organization.js`),
context: { id: org.id },
})
})
}