Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. const path = require(`path`)
  2.  
  3. exports.createPages = async ({ graphql, actions }) => {
  4. const { createPage } = actions;
  5. const blogPostTemplate = path.resolve(`src/components/PostLayout.js`);
  6.  
  7. return graphql(`
  8. query {
  9. allPost {
  10. edges {
  11. node {
  12. id
  13. }
  14. }
  15. }
  16. }
  17. `).then((result) => {
  18. if(result.errors) {
  19. throw result.errors;
  20. }
  21. // console.log(JSON.stringify(result, null, 4))
  22. result.data.allPost.edges.map(post => {
  23. createPage({
  24. path: `/post/${post.node.id}`,
  25. component: blogPostTemplate,
  26. context: {
  27. slug: {
  28. eq: post.node.id
  29. }
  30. }
  31. })
  32. })
  33. });
  34.  
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement