site/gatsby-node.js

37 lines
978 B
JavaScript
Raw Normal View History

2020-01-15 17:45:50 +03:00
const path = require('path')
const { createFilePath } = require(`gatsby-source-filesystem`)
exports.createPages = async ({ actions, graphql }) => {
const {createPage} = actions;
const courseTemplate = path.resolve(`./src/components/courseTemplate.js`);
const result = await graphql(`{
allMarkdownRemark(
filter: {frontmatter: {
content_type: {eq: "page_education"},
published: {eq: true}}}
){
edges{
node{
html
frontmatter{
title
path
}
}
}
}
}`)
if(result.errors){throw result.errors;}
const courses = result.data.allMarkdownRemark.edges;
courses.forEach(({node}) => {
createPage({
path: node.frontmatter.path,
component: courseTemplate
})
})
}