Skip to content

Commit 183adda

Browse files
committed
implemented createPages API
1 parent db4fbcf commit 183adda

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

gatsby-node.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const path = require('path');
2+
3+
exports.createPages = ({ boundActionCreators, graphql }) => {
4+
const { createPage } = boundActionCreators;
5+
6+
const blogPostTemplate = path.resolve(`src/templates/blog-post.js`);
7+
8+
return graphql(`{
9+
allMarkdownRemark(
10+
sort: { order: DESC, fields: [frontmatter___date] }
11+
limit: 1000
12+
) {
13+
edges {
14+
node {
15+
excerpt(pruneLength: 250)
16+
html
17+
id
18+
frontmatter {
19+
path
20+
date
21+
title
22+
}
23+
}
24+
}
25+
}
26+
}`).then(result => {
27+
if (result.errors) {
28+
return Promise.reject(result.errors);
29+
}
30+
result.data.allMarkdownRemark.edges.forEach(({ node }) => {
31+
createPage({
32+
path: node.frontmatter.path,
33+
component: blogPostTemplate,
34+
context: {} // additional data can be passed via context
35+
});
36+
});
37+
});
38+
}

0 commit comments

Comments
 (0)