Last active
March 20, 2019 10:20
-
-
Save ronaldlangeveld/ff6fa578515bcc4a0a0750390007dc07 to your computer and use it in GitHub Desktop.
Ghost gatsby
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 _ = require(`lodash`) | |
const Promise = require(`bluebird`) | |
const path = require(`path`) | |
exports.createPages = ({ graphql, actions }) => { | |
const { createPage } = actions | |
const createPosts = new Promise((resolve, reject) => { | |
const postTemplate = path.resolve(`./src/templates/blogTemplate.js`) | |
resolve( | |
graphql(` | |
{ | |
allGhostPost( | |
sort: {order: ASC, fields: published_at}, | |
filter: { | |
slug: {ne: "data-schema"} | |
} | |
) { | |
edges { | |
node { | |
slug | |
} | |
} | |
} | |
}` | |
).then((result) => { | |
if (result.errors) { | |
return reject(result.errors) | |
} | |
if (!result.data.allGhostPost) { | |
return resolve() | |
} | |
const items = result.data.allGhostPost.edges | |
_.forEach(items, ({ node }) => { | |
// This part here defines, that our posts will use | |
// a `/:slug/` permalink. | |
node.url = `/${node.slug}/` | |
createPage({ | |
path: node.url, | |
component: path.resolve(postTemplate), | |
context: { | |
// Data passed to context is available | |
// in page queries as GraphQL variables. | |
slug: node.slug, | |
}, | |
}) | |
}) | |
return resolve() | |
}) | |
) | |
}) | |
return Promise.all([createPosts]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment