-
-
Save derekeder/1311af63c8db8e23992b5cebdb134973 to your computer and use it in GitHub Desktop.
example of gatsby-node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Based on Gatsby docs at https://www.gatsbyjs.com/docs/creating-and-modifying-pages/ | |
const path = require("path") | |
exports.createPages = async ({ graphql, actions, reporter }) => { | |
const { createPage } = actions | |
const result = await graphql( | |
` | |
{ | |
allOccupationsJson { | |
edges { | |
node { | |
occupation_slug | |
} | |
} | |
} | |
} | |
` | |
) | |
if (result.errors) { | |
reporter.panicOnBuild(`Error while running GraphQL query.`) | |
return | |
} | |
const jobDetailTemplate = path.resolve(`src/templates/job-detail.js`) | |
result.data.allOccupationsJson.edges.forEach(({ node }) => { | |
const path = 'job/' + node.occupation_slug | |
createPage({ | |
path, | |
component: jobDetailTemplate, | |
context: { | |
pagePath: node.occupation_slug | |
}, | |
}) | |
}) | |
const placeNames = [ | |
"alabama", | |
"alaska", | |
"arizona", | |
"arkansas", | |
"california", | |
"colorado", | |
"connecticut", | |
"delaware", | |
"district_of_columbia", | |
"florida", | |
"georgia", | |
"guam", | |
"hawaii", | |
"idaho", | |
"illinois", | |
"indiana", | |
"iowa", | |
"kansas", | |
"kentucky", | |
"louisiana", | |
"maine", | |
"maryland", | |
"massachusetts", | |
"michigan", | |
"minnesota", | |
"mississippi", | |
"missouri", | |
"montana", | |
"nebraska", | |
"nevada", | |
"new_hampshire", | |
"new_jersey", | |
"new_mexico", | |
"new_york", | |
"north_carolina", | |
"north_dakota", | |
"ohio", | |
"oklahoma", | |
"oregon", | |
"pennsylvania", | |
"puerto_rico", | |
"rhode_island", | |
"south_carolina", | |
"south_dakota", | |
"tennessee", | |
"texas", | |
"utah", | |
"vermont", | |
"virgin_islands", | |
"virginia", | |
"washington", | |
"west_virginia", | |
"wisconsin", | |
"wyoming" | |
] | |
const placeDetailTemplate = path.resolve(`src/templates/place-detail.js`) | |
placeNames.forEach(name => { | |
const path = 'place/' + name | |
createPage({ | |
path, | |
component: placeDetailTemplate | |
}) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment