/
gatsby-node.js
131 lines (119 loc) · 3.85 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
const path = require(`path`)
const mkdirp = require(`mkdirp`)
const { MDX_SCOPES_LOCATION } = require(`./constants`)
const defaultOptions = require(`./utils/default-options`)
const fs = require(`fs`)
const {
onCreateNode,
unstable_shouldOnCreateNode,
} = require(`./gatsby/on-create-node`)
/**
* Create Mdx types and resolvers
*/
exports.createSchemaCustomization = require(`./gatsby/create-schema-customization`)
/**
* Check whether to create Mdx nodes from MDX files.
*/
exports.unstable_shouldOnCreateNode = unstable_shouldOnCreateNode
/**
* Create Mdx nodes from MDX files.
*/
exports.onCreateNode = onCreateNode
/**
* Add frontmatter as page context for MDX pages
*/
exports.onCreatePage = require(`./gatsby/on-create-page`)
/**
* Add the webpack config for loading MDX files
*/
exports.onCreateWebpackConfig = require(`./gatsby/create-webpack-config`)
/**
* Add the MDX extensions as resolvable. This is how the page creator
* determines which files in the pages/ directory get built as pages.
*/
exports.resolvableExtensions = (data, pluginOptions) =>
defaultOptions(pluginOptions).extensions
/**
* Convert MDX to JSX so that Gatsby can extract the GraphQL queries.
*/
exports.preprocessSource = require(`./gatsby/preprocess-source`)
/**
* Required config for mdx to function
*/
exports.onCreateBabelConfig = ({ actions }) => {
actions.setBabelPlugin({
name: require.resolve(`@babel/plugin-proposal-object-rest-spread`),
})
}
exports.onPreBootstrap = ({ cache }) => {
mkdirp.sync(path.join(cache.directory, MDX_SCOPES_LOCATION))
}
exports.onPostBootstrap = ({ cache }, pluginOptions) => {
if (pluginOptions.globalScope) {
fs.writeFileSync(
path.join(cache.directory, MDX_SCOPES_LOCATION, `global-scope.js`),
pluginOptions.globalScope
)
}
}
exports.pluginOptionsSchema = function ({ Joi }) {
return Joi.object({
extensions: Joi.array()
.items(Joi.string())
.default([".mdx"])
.description(
`Configure the file extensions that gatsby-plugin-mdx will process`
),
defaultLayouts: Joi.object({})
.unknown(true)
.default({})
.description(`Set the layout components for MDX source types`),
gatsbyRemarkPlugins: Joi.array()
.items(
Joi.string(),
Joi.object({
resolve: Joi.string(),
options: Joi.object({}).unknown(true),
})
)
.default([])
.description(`Use Gatsby-specific remark plugins`),
lessBabel: Joi.boolean()
.default(false)
.description(
"Enable fast parsing mode? This may break certain implied transformation dependencies. Disable if you have problems"
),
remarkPlugins: Joi.array()
.items(
Joi.function(),
Joi.object({}).unknown(true),
Joi.array().items(Joi.object({}).unknown(true), Joi.function())
)
.default([])
.description(`Specify remark plugins`),
rehypePlugins: Joi.array()
.items(
Joi.function(),
Joi.object({}).unknown(true),
Joi.array().items(Joi.object({}).unknown(true), Joi.function())
)
.default([])
.description(`Specify rehype plugins`),
plugins: Joi.array().items(Joi.string(), Joi.object({}).unknown(true)),
mediaTypes: Joi.array()
.items(Joi.string())
.default(["text/markdown", "text/x-markdown"])
.description(`Determine which media types are processed by MDX`),
shouldBlockNodeFromTransformation: Joi.function()
.maxArity(1)
.default(() => () => false)
.description(
`Disable MDX transformation for nodes where this function returns true`
),
root: Joi.string()
.default(process.cwd())
.description(
`[deprecated] This is a legacy option that used to define root directory of the project. It was needed to generate a cache directory location. It currently has no effect.`
),
})
}