Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. const path = require("path")
  2. const slash = require("slash")
  3.  
  4. exports.createPages = async ({ graphql, actions }) => {
  5. const { createPage } = actions
  6.  
  7. const result = await graphql(`
  8. {
  9. allStrapiRecipe {
  10. edges {
  11. node {
  12. description
  13. recipename
  14. ingredients {
  15. amount
  16. measurement
  17. name
  18. }
  19. id
  20. strapiId
  21. slug
  22. excerpt
  23. picture {
  24. childImageSharp {
  25. fluid {
  26. src
  27. }
  28. }
  29. }
  30. }
  31. }
  32. }
  33. }
  34. `)
  35.  
  36. if (result.errors) {
  37. throw new Error(result.errors)
  38. }
  39.  
  40. const { allStrapiRecipe } = result.data
  41.  
  42. const recipeTemplate = path.resolve("./src/templates/recipe.js")
  43.  
  44. allStrapiRecipe.edges.forEach(edge => {
  45. createPage({
  46. path: edge.node.slug,
  47. component: slash(recipeTemplate),
  48. context: {
  49. ...edge.node,
  50. },
  51. })
  52. })
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement