gatsby-starter-netlify-cms/gatsby-node.js
2017-10-22 09:57:08 -04:00

39 lines
990 B
JavaScript

const path = require('path');
exports.createPages = ({ boundActionCreators, graphql }) => {
const { createPage } = boundActionCreators;
return graphql(`
{
allMarkdownRemark(sort: { order: DESC, fields: [frontmatter___date] }, limit: 1000) {
edges {
node {
excerpt(pruneLength: 400)
html
id
frontmatter {
templateKey
path
date
title
aboutData {
paragraph
}
}
}
}
}
}
`).then(result => {
if (result.errors) {
return Promise.reject(result.errors);
}
result.data.allMarkdownRemark.edges.forEach(({ node }) => {
createPage({
path: node.frontmatter.path,
component: path.resolve(`src/templates/${String(node.frontmatter.templateKey)}.js`),
context: {} // additional data can be passed via context
});
});
});
};