diff --git a/starters/blog/gatsby-node.js b/starters/blog/gatsby-node.js index acd164192e90d..df877b369440a 100644 --- a/starters/blog/gatsby-node.js +++ b/starters/blog/gatsby-node.js @@ -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, + }, }) - ) + }) }) }