Created
December 3, 2018 17:37
-
-
Save patricoferris/31b262c53cd8810b2fe68638efad6505 to your computer and use it in GitHub Desktop.
Gatsby Node API (1/2)
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
// Defining what should happen whenever we create a new node | |
exports.onCreateNode = ({ node, getNode, actions }) => { | |
const { createNode, createNodeField } = actions | |
// Check if the node being passed is the right type (our markdown content) | |
if (node.internal.type === 'MarkdownRemark') { | |
// Generate a new slug for this file using the createFilePath function | |
// Note we are setting the basePath as pages that way the slug will also include subdirectories | |
const slug = createFilePath({ node, getNode , basePath: 'pages'}); | |
// Add a new field to node of name 'slug' with value slug | |
createNodeField({ | |
node, | |
name: `slug`, | |
value: slug | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment