Make gatsby-plugin-mdx not automatically create pages under src/pages
See original GitHub issueSummary
Is there a way to stop gatsby plugin mdx from automatically creating pages in src/pages
so that I can provide a custom template using createPages
?
Can we update the plugin or the documentation to make it more explicit, more emphasis that it does this?
Relevant information
When creating a page with MDX and gatsby-source-filesystem
, say I have this structure:
- src
- pages
- mdx-post.mdx
- md-post.md
- templates
- regular-template.js
- mdx-template.js
gatsby-node.js:
...
{
resolve: `gatsby-plugin-mdx`,
options: {
defaultLayouts: {
default: require.resolve(
`${__dirname}/src/templates/mdx-template.js`
),
},
},
},
...
When I use gatsby-plugin-mdx
, I cannot use a graphql pageQuery
in my mdx-template.s
.
How can I update MDX to use this?
Related issue - #16224
The underlying thing I want to do is, I have a graphql field created on my mdx
nodes that I want to access in mdx-template.js
.
However, since I cannot do a page query so I cannnot access this. (I cannot do a page query since I cannot use createPages
, since everything in src/pages
is automatically created by the mdx plugin)
I am down to make a PR to add this change / or update documentation if needed!
Thanks!
File contents (if changed)
gatsby-config.js
: N/A
package.json
: N/A
gatsby-node.js
: N/A
gatsby-browser.js
: N/A
gatsby-ssr.js
: N/A
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:11 (5 by maintainers)
Top GitHub Comments
Agree, is there some way we can turn this off via a configuration to the plug-in so we can use createPages and keep MDX files in src pages?
On Tue, Jun 2, 2020 at 6:58 PM Justin Chadwell notifications@github.com wrote:
Thanks for the explanation!
I get that that all mdx and js files in
src/pages
are converted into a page - but, this same behaviour isn’t extended to just plain md files, when using remark. Because of the difference here, it can cause friction from users trying to switch from remark into mdx.It feels like the behaviour between the plugins should be relatively consistent, at least because on the surface they seem to make an effort to do so, by supporting the same plugins, etc.
It also looks like this discussion has come up before here on an older version of the plugin.