-
Notifications
You must be signed in to change notification settings - Fork 10.3k
/
mdx-node-with-scope.js
45 lines (38 loc) · 1004 Bytes
/
mdx-node-with-scope.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
37
38
39
40
41
42
43
44
45
const { createContentDigest } = require(`gatsby-core-utils`)
const { findImportsExports } = require(`../utils/gen-mdx`)
async function createMdxNodeWithScope({ id, node, content, ...helpers }) {
const {
frontmatter,
scopeImports,
scopeExports,
scopeIdentifiers,
} = await findImportsExports({
node,
rawInput: content,
absolutePath: node.absolutePath,
...helpers,
})
const mdxNode = {
id,
children: [],
parent: node.id,
internal: {
content,
type: `Mdx`,
},
excerpt: frontmatter.excerpt,
exports: scopeExports,
rawBody: content,
frontmatter: {
title: ``, // always include a title
...frontmatter,
},
}
// Add path to the markdown file path
if (node.internal.type === `File`) {
mdxNode.fileAbsolutePath = node.absolutePath
}
mdxNode.internal.contentDigest = createContentDigest(mdxNode)
return { mdxNode, scopeIdentifiers, scopeImports }
}
module.exports = createMdxNodeWithScope