Skip to content

Instantly share code, notes, and snippets.

@starsinmypockets
Created December 12, 2019 20:55
Show Gist options
  • Save starsinmypockets/99c0bd99f10831e81dffde19ee65062f to your computer and use it in GitHub Desktop.
Save starsinmypockets/99c0bd99f10831e81dffde19ee65062f to your computer and use it in GitHub Desktop.
// This is untested, but it removes several uneccessary layers of
// functions and callbacks and should do about the same thing as
// the original code
const path = require(`path`)
module.exports = async ({ actions, graphql }) => {
const GET_VISUALS = `
query GET_VISUALS {
wpgraphql {
mediaItems {
nodes {
content
altText
termSlugs
guid
description
id
caption
slug
}
}
}
}
`
//
const { createPage } = actions
const data = await graphql(GET_VISUALS, { first: 100, after: null })
const { wpgraphql: {
mediaItems: {
nodes,
},
},
} = data
const visualTemplate = path.resolve(`./src/templates/visual.js`)
nodes.forEach(visual => {
console.log(`create visual: ${visual.slug}`)
createPage({
path: `/${visual.slug}`,
component: visualTemplate,
context: visual,
})
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment