website/gatsby-node.js

37 lines
764 B
JavaScript

const path = require("path");
exports.createPages = async ({ actions, graphql, reporter }) => {
const { createPage } = actions;
const noteTemplate = path.resolve(`src/templates/note.tsx`);
const result = await graphql(`{
allMdx(
limit: 10,
filter: {fileAbsolutePath: {glob: "**/src/notes/*"}}
) {
edges {
node {
frontmatter {
path
}
id
}
}
}
}`);
if (result.errors) {
reporter.panicOnBuild(`Error while running GraphQL query.`);
return;
}
result.data.allMdx.edges.forEach(({ node }) => {
createPage({
path: `/notes/${node.frontmatter.path}`,
component: noteTemplate,
context: {
id: node.id,
}
});
});
}