forked from openoakland/openousd-site
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.js
76 lines (66 loc) · 1.88 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
const path = require(`path`)
var slugify = require('slugify')
exports.createSchemaCustomization = ({ actions }) => {
const { createTypes } = actions
// Defining types because Gatsby is making some Int values String
// which breaks sortign and computation
const typeDefs = `
type CentralProgramsJson implements Node {
staff_roles: [StaffRole]
staff_bargaining_units: [StaffBargainingUnit]
}
type StaffRole {
eoy_total_positions_for_role: Int
role_description: String
}
type StaffBargainingUnit {
abbreviation: String
description: String
eoy_total_positions_for_bu: Int
}
`
createTypes(typeDefs)
}
exports.onCreateNode = ({ node, actions, getNode }) => {
if (node.internal.type === `CentralProgramsJson`) {
const { createNodeField } = actions
// Some program names include parentheses, remove those so they don't end up in path
const slugifyOptions = {
remove: /[*+~.()'"!:@/]/g,
lower: true
}
const slug = slugify(node.name, slugifyOptions)
// Add a slug field which can be used later to generate page slug
createNodeField({
name: `slug`,
node,
value: slug,
})
}}
exports.createPages = async ({ graphql, actions }) => {
const { createPage } = actions
// code is the site code / OUSD identifier for program
const result = await graphql(`
query {
allCentralProgramsJson {
nodes {
name
code
fields {
slug
}
}
}
}
`)
result.data.allCentralProgramsJson.nodes.forEach(node => {
createPage({
path: `central-programs/${node.fields.slug}`,
component: path.resolve(`./src/components/central-program.js`),
context: {
// Data passed to context is available
// in page queries as GraphQL variables.
code: node.code,
},
})
})}