gatsby-starter-netlify-cms/gatsby-node.js
2017-10-18 17:43:20 -04:00

37 lines
912 B
JavaScript

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