Skip to content

Commit

Permalink
Improve createPages of blog starter (#10781)
Browse files Browse the repository at this point in the history
## Description
Remove extra promise in `starters/blog/gatsby-node.js`.

## Related Issues
The same fixes is made for these pull requests.

gatsbyjs/gatsby#10357
gatsbyjs/gatsby#10777
  • Loading branch information
GatsbyJS Bot committed Jan 2, 2019
1 parent 979ce59 commit b3299d4
Showing 1 changed file with 35 additions and 41 deletions.
76 changes: 35 additions & 41 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,55 +4,49 @@ const { createFilePath } = require(`gatsby-source-filesystem`)
exports.createPages = ({ graphql, actions }) => {
const { createPage } = actions

return new Promise((resolve, reject) => {
const blogPost = path.resolve(`./src/templates/blog-post.js`)
resolve(
graphql(
`
{
allMarkdownRemark(
sort: { fields: [frontmatter___date], order: DESC }
limit: 1000
) {
edges {
node {
fields {
slug
}
frontmatter {
title
}
}
const blogPost = path.resolve(`./src/templates/blog-post.js`)
return graphql(
`
{
allMarkdownRemark(
sort: { fields: [frontmatter___date], order: DESC }
limit: 1000
) {
edges {
node {
fields {
slug
}
frontmatter {
title
}
}
}
`
).then(result => {
if (result.errors) {
console.log(result.errors)
reject(result.errors)
}
}
`
).then(result => {
if (result.errors) {
throw result.errors
}

// Create blog posts pages.
const posts = result.data.allMarkdownRemark.edges
// Create blog posts pages.
const posts = result.data.allMarkdownRemark.edges

posts.forEach((post, index) => {
const previous =
index === posts.length - 1 ? null : posts[index + 1].node
const next = index === 0 ? null : posts[index - 1].node
posts.forEach((post, index) => {
const previous = index === posts.length - 1 ? null : posts[index + 1].node
const next = index === 0 ? null : posts[index - 1].node

createPage({
path: post.node.fields.slug,
component: blogPost,
context: {
slug: post.node.fields.slug,
previous,
next,
},
})
})
createPage({
path: post.node.fields.slug,
component: blogPost,
context: {
slug: post.node.fields.slug,
previous,
next,
},
})
)
})
})
}

Expand Down

0 comments on commit b3299d4

Please sign in to comment.