Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. const path = require("path");
  2.  
  3. //Create dynamically blog pages
  4. exports.createPages = async ({ graphql, actions, reporter }) => {
  5. const { createPage } = actions;
  6.  
  7. const markdownFiles = await graphql(`
  8. {
  9. allMarkdownRemark {
  10. nodes {
  11. html
  12. frontmatter {
  13. author
  14. date
  15. title
  16. slug
  17. }
  18. }
  19. }
  20. }
  21. `);
  22.  
  23. if (markdownFiles.errors) {
  24. reporter.panicOnBuild("Error while creating blog pages!");
  25. return;
  26. }
  27.  
  28. const blogPostTemplate = path.resolve("src/templates/blog-post.js");
  29.  
  30. markdownFiles.data.allMarkdownRemark.nodes.forEach(markdownFile => {
  31. createPage({
  32. path: `blog/${markdownFile.frontmatter.slug}`,
  33. component: blogPostTemplate,
  34. context: {
  35. slug: markdownFile.frontmatter.slug
  36. }
  37. });
  38. });
  39.  
  40. reporter.info(JSON.stringify(markdownFiles, null, 2));
  41. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement