Gatsby: Add slug for all models

Created on 16 Jul 2020  Β·  9Comments  Β·  Source: gatsbyjs/gatsby

PR #25726 introduced slug directly in gatsby-plugin-mdx. Ideally, we'd be able to abstract this code to cover remark and other use cases. This will allow us to remove the MDX specific code and unlock this default field for all File based pages.

help wanted stale? feature or enhancement

All 9 comments

On avoiding conflicting with slug already being defined in say a node type created by gatsby-transformer-json (the json file might already have a slug field) β€” we could name the auto-generated slug filepathSlug β€” this makes it clear too where it comes from so would be less confusing in case it's not needed by someone.

@connorlindsey @LinnJS interested in picking this up?

@KyleAMathews I'd be happy to pick it up!

Awesome thanks! This is a perfectly complement to the work on the new
routing APIs so it'll be great to get it in.

--
Kyle Mathews

Blog: http://bricolage.io http://bricolage.io
Twitter: http://twitter.com/kylemathews

On Wed, Jul 22, 2020 at 8:08 PM Connor Lindsey notifications@github.com
wrote:

@KyleAMathews https://github.com/KyleAMathews I'd be happy to pick it
up!

β€”
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/gatsbyjs/gatsby/issues/25799#issuecomment-662797507,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAARLBZTIXPTLEDLHHV6DSTR46SS7ANCNFSM4O4V6N6Q
.

@laurieontech Hi, I had a few questions

Where should the filepathSlug be implemented/added? It seems like adding filepathSlug to gatsby-plugin-filesystem/create-file-node.js would work. Not sure if there is another plugin it should be implemented in or if it should be added as a util somewhere.

What file types should be supported or should it be added to all File types? I assume the path would only be useful on html, md, and mdx (might be missing some uses cases), but I also don't think there's any harm in just adding it to all File types.

Thanks!

Thanks for the interest in picking this up @connorlindsey! That's part of why this issue is vague. There isn't a clear direction for what the behavior should be and where we'd want to do this, e.g. gatsby-source-filesystem vs. gatsby core itself. I'll let @KyleAMathews chime in since I know he had some ideas.

The best way to do this would be to build it into core β€” automatically add the field to Nodes which are created from File like MarkdownRemark, MDX, JSON/YAML nodes etc. β€” that'll be trickier to figure out and land though β€” so what I'd do is take what @laurieontech did and turn it into a utility library (perhaps in gatsby-core-utils) which we add directly to different transformers β€” then later, assuming the pattern is working well, we move it to core.

How's that sound @laurieontech / @pieh?

Seems reasonable to me.

Hiya!

This issue has gone quiet. Spooky quiet. πŸ‘»

We get a lot of issues, so we currently close issues after 60 days of inactivity. It’s been at least 20 days since the last update here.
If we missed this issue or if you want to keep it open, please reply here.
As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks for being a part of the Gatsby community! πŸ’ͺπŸ’œ

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jimfilippou picture jimfilippou  Β·  3Comments

kalinchernev picture kalinchernev  Β·  3Comments

brandonmp picture brandonmp  Β·  3Comments

hobochild picture hobochild  Β·  3Comments

totsteps picture totsteps  Β·  3Comments