Skip to content

Instantly share code, notes, and snippets.

@Dantheman720
Last active September 10, 2019 20:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dantheman720/950f66758c29f6dbdaff3b183328c54a to your computer and use it in GitHub Desktop.
Save Dantheman720/950f66758c29f6dbdaff3b183328c54a to your computer and use it in GitHub Desktop.
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