forked from zslabs/gatsby-plugin-mdx-frontmatter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.js
36 lines (35 loc) · 909 Bytes
/
gatsby-node.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
exports.createSchemaCustomization = ({
actions: { createFieldExtension },
createContentDigest,
}) => {
createFieldExtension({
name: 'mdx',
extend() {
return {
type: 'String',
resolve(source, args, context, info) {
// Grab field
const value = source[info.fieldName]
if (typeof value === 'undefined') {
return null;
}
// Isolate MDX
const mdxType = info.schema.getType('Mdx')
// Grab just the body contents of what MDX generates
const { resolve } = mdxType.getFields().body
return resolve(
{
rawBody: value,
internal: {
contentDigest: createContentDigest(value), // Used for caching
},
},
args,
context,
info
)
},
}
},
})
}