Skip to content

Commit

Permalink
refactor(gatsby-plugin-create-client-paths): remove promise (#15015)
Browse files Browse the repository at this point in the history
  • Loading branch information
sidharthachatterjee authored and GatsbyJS Bot committed Jun 21, 2019
1 parent e69800b commit 784d20f
Showing 1 changed file with 17 additions and 24 deletions.
41 changes: 17 additions & 24 deletions packages/gatsby-plugin-create-client-paths/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,29 @@ const validatePrefixEntry = prefix => {
}
}

exports.onCreatePage = ({ page, store, actions }, { prefixes }) => {
exports.onCreatePage = ({ page, actions }, { prefixes }) => {
const { createPage } = actions
const re = {}
prefixes.forEach(validatePrefixEntry)

return new Promise(resolve => {
// Don't set matchPath again if it's already been set.
if (page.matchPath || page.path.match(/dev-404-page/)) {
return resolve()
}

prefixes.forEach(prefix => {
if (!re[prefix]) {
// Remove the * from the prefix and memoize
const trimmedPrefix = prefix.replace(/\*$/, ``)
re[prefix] = new RegExp(`^${trimmedPrefix}`)
}

// Ensure that the path ends in a trailing slash, since it can be removed.
const path = page.path.match(/\/$/) ? page.path : `${page.path}/`
// Don't set matchPath again if it's already been set.
if (page.matchPath || page.path.match(/dev-404-page/)) {
return
}

if (path.match(re[prefix])) {
page.matchPath = prefix.replace(/\*$/, `*`)
createPage(page)
return true
}
prefixes.forEach(prefix => {
if (!re[prefix]) {
// Remove the * from the prefix and memoize
const trimmedPrefix = prefix.replace(/\*$/, ``)
re[prefix] = new RegExp(`^${trimmedPrefix}`)
}

return false
})
// Ensure that the path ends in a trailing slash, since it can be removed.
const path = page.path.match(/\/$/) ? page.path : `${page.path}/`

return resolve()
if (path.match(re[prefix])) {
page.matchPath = prefix.replace(/\*$/, `*`)
createPage(page)
}
})
}

0 comments on commit 784d20f

Please sign in to comment.