gatsby-mdx | Utilities to work with MDX and netlify-cms in Gatsby sites | Content Management System library
kandi X-RAY | gatsby-mdx Summary
kandi X-RAY | gatsby-mdx Summary
Utilities to work with MDX and netlify-cms in Gatsby sites
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of gatsby-mdx
gatsby-mdx Key Features
gatsby-mdx Examples and Code Snippets
Community Discussions
Trending Discussions on gatsby-mdx
QUESTION
So, I'm using the gatsby-mdx plugin to create a site from MDX files. I want to create an association between the SitePage object and the Mdx object so that I can do one graphQL query of the SitePage edges in order to construct a site navigation.
Much of my code is in TypeScript, so ignore any type annotations if you're wondering WTF those are.
Things I've tried Using FieldsMy first thought was to use the onCreateNode
API, grab the MDX node, and add it to the SitePage using the createNodeField
action. That all works great, B-U-T the gatsby-mdx plugin adds a bunch of other info to their node later using the setFieldsOnGraphQLNodeType
API (which occurs after the onCreateNode
API). I want those fields (such as frontmatter and tableOfContents) to be available in later graphql queries, but they aren't using this method.
setFieldsOnGraphQLNodeType
I figured I could just extend the SitePage object the same way gatsby-mdx was extending the Mdx node.
The key problem I ran into here was that I couldn't figure out how to create the Mdx GraphQL node type.
...ANSWER
Answered 2019-Feb-22 at 04:11So I finally found a better solution (than my previous attempt, which involves pumping mdx node into page’s context
).
Gatsby has a undocumented method to link nodes to one another:
Yes, you can can use createNodeField with the not-yet-documented ___NODE syntax to create links between nodes.
So, the steps are like this:
- In
createPage
, store theid
of the Mdx node to SitePage node. - In
onCreateNode
, if node isSitePage
, usecreateNodeField
with theMdx___NODE
as field name and Mdx node's id as value.
My gatsby-node.js
:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install gatsby-mdx
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page