Created
September 29, 2018 18:24
-
-
Save onefriendaday/3460c2ead0779d34097dc82042cd341a to your computer and use it in GitHub Desktop.
Global settings story with Gatsby and Storyblok
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 Promise = require('bluebird') | |
const path = require('path') | |
exports.createPages = ({ graphql, boundActionCreators }) => { | |
const { createPage } = boundActionCreators | |
return new Promise((resolve, reject) => { | |
const storyblokEntry = path.resolve('src/templates/storyblok-entry.js') | |
graphql( | |
`{ | |
allStoryblokEntry( | |
filter: { | |
slug: { eq: "settings" } | |
} | |
) { | |
edges { | |
node { | |
id | |
name | |
created_at | |
published_at | |
uuid | |
slug | |
full_slug | |
content | |
is_startpage | |
parent_id | |
group_id | |
} | |
} | |
} | |
}` | |
).then(result => { | |
if (result.errors) { | |
console.log(result.errors) | |
reject(result.errors) | |
} | |
const globalSettings = result.data.allStoryblokEntry.edges[0].node | |
resolve( | |
graphql( | |
`{ | |
allStoryblokEntry { | |
edges { | |
node { | |
id | |
name | |
created_at | |
published_at | |
uuid | |
slug | |
full_slug | |
content | |
is_startpage | |
parent_id | |
group_id | |
} | |
} | |
} | |
}` | |
).then(result => { | |
if (result.errors) { | |
console.log(result.errors) | |
reject(result.errors) | |
} | |
const entries = result.data.allStoryblokEntry.edges | |
entries.forEach((entry, index) => { | |
createPage({ | |
path: `/${entry.node.full_slug}/`, | |
component: storyblokEntry, | |
context: { | |
globalSettings: globalSettings, | |
story: entry.node | |
} | |
}) | |
}) | |
}) | |
) | |
}) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Should change second query from:
to:
Otherwise, build will fail with generic: "Minified React error #130" (but will work in development, just not production)
This happens because there's no
settings
component to render the page with (nor should there be, since we don't intend to display the settings page on the front-end for the end-user). So, when generating the static HTML ingatsby build
, gatsby will pass thesettings
page along with the other pages and try to build HTML for it, thus making a call to an undefined componentsettings
and crashing the build withMinified React error #130
.