This repository has been archived on 2022-06-22. You can view files and clone it, but cannot push or open issues or pull requests.
usaco-guide/gatsby-node.js
2020-06-03 15:18:17 -07:00

33 lines
No EOL
820 B
JavaScript

exports.createPages = async ({ actions, graphql, reporter }) => {
const { createPage } = actions;
const moduleTemplate = require.resolve(`./src/templates/moduleTemplate.js`);
const result = await graphql(`
{
allMarkdownRemark {
edges {
node {
frontmatter {
slug
}
}
}
}
}
`);
// Handle errors
if (result.errors) {
reporter.panicOnBuild(`Error while running GraphQL query.`);
return;
}
result.data.allMarkdownRemark.edges.forEach(({ node }) => {
if (!node.frontmatter.slug) return;
createPage({
path: node.frontmatter.slug,
component: moduleTemplate,
context: {
// additional data can be passed via context
slug: node.frontmatter.slug,
},
});
});
};