Minimizing configuration for programmatically generated MDX pages #30258
Unanswered
kelvindecosta
asked this question in
Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Overview
Hey everyone!
I want to use as little configuration as possible to programmatically create pages from
.mdx
files.Behavior
I have 2 types of programmatically generated pages:
pages
posts
I've separated these two types of pages because they would require different templates.
pages
I have configured
gatsby-source-filesystem
to usesrc/pages
aspages
instances.I then configured
gatsby-plugin-mdx
to create pages from thesepages
instances with adefaultLayout
for the same.The template is very simple as it only uses
pageContext
andMDXProvider
.There is no
grapql
query required, and I can easily pull thefrontmatter
frompageContext
.posts
Essentially, I want
posts
instances insrc/posts
each with a customslug
and adate
both of which are derived from the file name.slug
date
src/posts/2021-03-15-hello-world
/blog/2021-03-15-hello-world
Date.UTC(2021, 2, 15)
Currently, I have:
configured
gatsby-source-filesystem
withposts
.used Gatsby Node APIs
created a template with a
pageQuery
.I don't like the fact that there is both a
slug
attribute and afields : { slug }
attribute on theMdx
node.I also think that this has a lot of room for refactoring.
Refactoring
I was wondering if I could
onCreateNode
API by usingcreateResolvers
to:date
attribute directly ontoMdx
, andslug
attribute on theMdx
.gatsby-plugin-page-creator
with theposts
instances and just pointgatsby-plugin-mdx
to adefaultLayout
forposts
.I feel like this would be easier to maintain.
Any suggestions are appreciated!
Beta Was this translation helpful? Give feedback.
All reactions