Created
December 12, 2019 20:55
-
-
Save starsinmypockets/99c0bd99f10831e81dffde19ee65062f to your computer and use it in GitHub Desktop.
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
// 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