You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: Build markdown nodes from CMS RichText fields (#98)
* feat: Build markdown nodes for CMS markdown fields
Can be used with MDX
* feat: Add buildMarkdownNodes configuration option
Defaults to false
* style: Linting
* chore(demo): Add MDX dependencies
* chore(demo): Update demo to use MDX
* fix: Remove optional chaining
Eventually transpile with Babel
* docs: Update README to include markdownNode usage
* docs: Add link to demo source
For a full MDX example
- Build markdown nodes for all [`RichText`](https://graphcms.com/docs/reference/fields/rich-text) fields in your GraphCMS schema. [Learn more](#using-markdown-nodes).
71
+
68
72
## Downloading local image assets
69
73
70
74
This source plugin provides the option to download and cache GraphCMS assets in your Gatsby project. This enables you to use [`gatsby-image`](https://www.gatsbyjs.org/packages/gatsby-image), for image loading optimizations, with your GraphCMS image assets.
@@ -107,3 +111,51 @@ You can then use the fragments from [`gatsby-transformer-sharp`](https://www.gat
107
111
```
108
112
109
113
For more information on using `gatsby-image`, please see the [documentation](https://www.gatsbyjs.org/packages/gatsby-image/?=#how-to-use).
114
+
115
+
## Using markdown nodes
116
+
117
+
This source plugin provides the option to build markdown nodes for all `RichText` fields in your GraphCMS schema, which in turn can be used with [MDX](https://mdxjs.com).
118
+
119
+
To enable this, add `buildMarkdownNodes: true` to your plugin configuration.
120
+
121
+
```js
122
+
// gatsby-config.js
123
+
module.exports= {
124
+
plugins: [
125
+
{
126
+
resolve:'gatsby-source-graphcms',
127
+
options: {
128
+
endpoint:process.env.GRAPHCMS_ENDPOINT,
129
+
buildMarkdownNodes:true,
130
+
},
131
+
},
132
+
],
133
+
}
134
+
```
135
+
136
+
Enabling this option adds a `markdownNode` nested field to all `RichText` fields on the generated Gatsby schema.
137
+
138
+
### Usage with `gatsby-plugin-mdx`
139
+
140
+
These newly built nodes can be used with [`gatsby-plugin-mdx`](https://www.gatsbyjs.org/packages/gatsby-plugin-mdx) to render markdown from GraphCMS.
141
+
142
+
Once installed, you will be able to query for `MDX` fields using a query similar to the one below.
143
+
144
+
```gql
145
+
{
146
+
allGraphCmsPost {
147
+
nodes {
148
+
id
149
+
content {
150
+
markdownNode {
151
+
childMdx {
152
+
body
153
+
}
154
+
}
155
+
}
156
+
}
157
+
}
158
+
}
159
+
```
160
+
161
+
Check out the [demo source](https://github.com/GraphCMS/gatsby-source-graphcms/tree/next/demo) for an example of a full MDX implementation.
0 commit comments