Skip to content

Instantly share code, notes, and snippets.

@onefriendaday
Created September 29, 2018 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save onefriendaday/3460c2ead0779d34097dc82042cd341a to your computer and use it in GitHub Desktop.
Save onefriendaday/3460c2ead0779d34097dc82042cd341a to your computer and use it in GitHub Desktop.
Global settings story with Gatsby and Storyblok
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
}
})
})
})
)
})
})
}
@ovsw
Copy link

ovsw commented Dec 31, 2018

Should change second query from:

allStoryblokEntry {
              edges {....

to:

allStoryblokEntry (filter: { slug: { ne: "settings" } }) {
              edges {...

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 in gatsby build, gatsby will pass the settings page along with the other pages and try to build HTML for it, thus making a call to an undefined component settings and crashing the build with Minified React error #130.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment