-
-
Save amandeepmittal/ebc80bce480ec1b37ec5bcd9ff24058d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path'); | |
exports.createPages = ({ graphql, actions }) => { | |
const { createPage } = actions; | |
return new Promise((resolve, reject) => { | |
const blogPostTemplate = path.resolve('src/templates/blogPost.js'); | |
// Query for markdown nodes to use in creating pages. | |
resolve( | |
graphql( | |
` | |
query { | |
allMarkdownRemark( | |
sort: { order: ASC, fields: [frontmatter___date] } | |
) { | |
edges { | |
node { | |
frontmatter { | |
path | |
title | |
tags | |
} | |
} | |
} | |
} | |
} | |
` | |
).then(result => { | |
const posts = result.data.allMarkdownRemark.edges; | |
posts.forEach(({ node }) => { | |
const path = node.frontmatter.path; | |
createPage({ | |
path, | |
component: blogPostTemplate, | |
context: { | |
pathSlug: path | |
} | |
}); | |
resolve(); | |
}); | |
}) | |
); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment