Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Gatsby file for generating pages.
const path = require("path")
const slash = require("slash")
exports.createPages = async ({ graphql, actions }) => {
const { createPage } = actions
const result = await graphql(`
{
allStrapiRecipe {
edges {
node {
description
recipename
ingredients {
amount
measurement
name
}
id
strapiId
slug
excerpt
picture {
childImageSharp {
fluid {
src
}
}
}
}
}
}
}
`)
if (result.errors) {
throw new Error(result.errors)
}
const { allStrapiRecipe } = result.data
const recipeTemplate = path.resolve("./src/templates/recipe.js")
allStrapiRecipe.edges.forEach(edge => {
createPage({
path: edge.node.slug,
component: slash(recipeTemplate),
context: {
...edge.node,
},
})
})
}
import React from "react"
import Layout from "../components/layout";
export default({pageContext}) => {
return (
<Layout>
<pre>{JSON.stringify(pageContext, undefined, 2)}</pre>
</Layout>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment