Guest User

Untitled

a guest
Jan 16th, 2019
68
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const path = require(`path`)
  2. const { createFilePath } = require(`gatsby-source-filesystem`)
  3.  
  4. var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
  5. global.XMLHttpRequest = XMLHttpRequest;
  6.  
  7. exports.onCreateNode = ({ node, getNode, actions }) => {
  8.   const { createNodeField } = actions
  9.   if (node.internal.type === 'MarkdownRemark') {
  10.     const slug = createFilePath({ node, getNode, basePath: 'pages/posts' })
  11.     createNodeField({
  12.       node,
  13.       name: 'slug',
  14.       value: slug,
  15.     });
  16.   }
  17. }
  18.  
  19. exports.createPages = ({ graphql, actions }) => {
  20.   const { createPage } = actions
  21.   return new Promise((resolve, reject) => {
  22.     graphql(`
  23.     {
  24.       allMarkdownRemark {
  25.         edges {
  26.           node {
  27.             fields {
  28.               slug
  29.             }
  30.           }
  31.         }
  32.       }
  33.     }
  34.    `).then(result => {
  35.       result.data.allMarkdownRemark.edges.forEach(({ node }) => {
  36.         createPage({
  37.           path: node.fields.slug,
  38.           component: path.resolve(`./src/templates/blog-post.js`),
  39.           context: {
  40.             slug: node.fields.slug,
  41.           },
  42.         })
  43.       })
  44.       resolve()
  45.     })
  46.   })
  47. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×