Migrate to Netlify Today

Netlify announces the next evolution of Gatsby Cloud. Learn more

Creating Slugs for Pages

The logic for creating slugs from file names can get tricky, the gatsby-source-filesystem plugin ships with a function for creating them.

Install

npm install gatsby-source-filesystem

Create slugs in gatsby-node.js

Add your new slugs directly onto the MarkdownRemark nodes. Any data you add to nodes is available to query later with GraphQL.

To do so, you’ll use a function passed to our API implementation called createNodeField. This function allows you to create additional fields on nodes created by other plugins.

Query created slugs

Open refresh GraphiQL, then run this GraphQL query to see all your slugs:

Start building today on Netlify!
Edit this page on GitHub
© 2023 Gatsby, Inc.