-
Notifications
You must be signed in to change notification settings - Fork 10.3k
/
nodes.ts
36 lines (28 loc) · 895 Bytes
/
nodes.ts
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
import { IGatsbyNode } from "../redux/types"
import { store } from "../redux"
/**
* Get content for a node from the plugin that created it.
*/
export async function loadNodeContent(node: IGatsbyNode): Promise<string> {
if (typeof node.internal.content === `string`) {
return node.internal.content
}
// Load plugin's loader function
const plugin = store
.getState()
.flattenedPlugins.find(plug => plug.name === node.internal.owner)
if (!plugin) {
throw new Error(
`Could not find owner plugin of node for loadNodeContent with owner \`${node.internal.owner}\``
)
}
const { loadNodeContent } = require(plugin.resolve)
if (!loadNodeContent) {
throw new Error(
`Could not find function loadNodeContent for plugin ${plugin.name}`
)
}
const content = await loadNodeContent(node)
node.internal.content = content
return content
}