question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make gatsby-plugin-mdx not automatically create pages under src/pages

See original GitHub issue

Summary

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:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
varughesecommented, Jun 2, 2020

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 https://github.com/ChristopherBiscardi/gatsby-mdx/issues/243 on an older version of the plugin.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/gatsbyjs/gatsby/issues/24164#issuecomment-637850429, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADKKYL5LD2ZYIPC74F5P4JLRUV7YTANCNFSM4NDP6ZXQ .

2reactions
jedevccommented, Jun 2, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Creating and Modifying Pages - Gatsby
Gatsby core and plugins can automatically create pages for you. Sometimes the default isn't quite what you want and you need to modify...
Read more >
Error creating custom pages from local plugin within GatsbyJS
Unfortunately, I got error message The plugin "my-custom-plugin" created a page with a component that doesn't exist when running gatsby develop.
Read more >
Use gatsby plugin page creator to auto create pages - Medium
Before the creation of this plugin, react pages for you static site were automatically created in the src/pages directory. That's right, no ......
Read more >
gatsby-plugin-automatic-redirects - npm
Automatically tracks page path changes and creates redirects via Gatsby's ... in the npm registry using gatsby-plugin-automatic-redirects.
Read more >
How to generate pages by createPages API with Gatsby.js
js site with createPages API and enabling the live preview in the Visual Editor. We will use the gatsby-source-storyblok plugin to load our...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found