Created
October 29, 2018 17:44
-
-
Save onefriendaday/8e31b85464817eccfa371f8ad3e0fca6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 datasourceEntries = result.data.allStoryblokDataSourceEntry.edges | |
resolve( | |
graphql( | |
`{ | |
allStoryblokDataSourceEntry { | |
edges { | |
node { | |
id | |
name | |
value | |
data_source | |
} | |
} | |
} | |
}` | |
).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: { | |
datasourceEntries: datasourceEntries, | |
story: entry.node | |
} | |
}) | |
}) | |
}) | |
) | |
}) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment