mirror of
https://github.com/nature-of-code/noc-book-2
synced 2024-11-17 07:49:05 +01:00
35 lines
699 B
JavaScript
35 lines
699 B
JavaScript
const path = require('path');
|
|
|
|
module.exports = async ({ graphql, actions, reporter }) => {
|
|
const { createPage } = actions;
|
|
|
|
const result = await graphql(`
|
|
query {
|
|
allChaptersJson {
|
|
edges {
|
|
node {
|
|
slug
|
|
id
|
|
}
|
|
}
|
|
}
|
|
}
|
|
`);
|
|
|
|
if (result.errors) {
|
|
reporter.panicOnBuild('🚨 ERROR: Loading "createPages" query');
|
|
}
|
|
|
|
// Create a page for each chapter
|
|
const pages = result.data.allChaptersJson.edges;
|
|
|
|
pages.forEach(({ node }) => {
|
|
createPage({
|
|
path: `/${node.slug}/`,
|
|
component: path.resolve(`./src/layouts/ChapterLayout.js`),
|
|
context: {
|
|
id: node.id,
|
|
},
|
|
});
|
|
});
|
|
};
|