Last active
September 10, 2019 20:26
-
-
Save Dantheman720/950f66758c29f6dbdaff3b183328c54a to your computer and use it in GitHub Desktop.
Gatsby file for generating pages.
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 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, | |
}, | |
}) | |
}) | |
} |
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
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