|
1 | | -import type { GatsbyNode, NodeInput, NodePluginArgs } from "gatsby" |
| 1 | +import type { GatsbyNode, NodeInput } from "gatsby" |
2 | 2 | import type { FileSystemNode } from "gatsby-source-filesystem" |
3 | 3 | import type { Options } from "rehype-infer-description-meta" |
4 | | -import type { IFileNode, IMdxMetadata, IMdxNode, NodeMap } from "./types" |
| 4 | +import type { IFileNode, NodeMap } from "./types" |
5 | 5 |
|
6 | 6 | import path from "path" |
7 | 7 | import { sentenceCase } from "change-case" |
8 | 8 | import fs from "fs-extra" |
9 | 9 | import grayMatter from "gray-matter" |
10 | | -import deepmerge from "deepmerge" |
11 | 10 |
|
12 | 11 | import { |
13 | 12 | defaultOptions, |
14 | 13 | enhanceMdxOptions, |
15 | 14 | IMdxPluginOptions, |
16 | 15 | } from "./plugin-options" |
17 | 16 | import { IGatsbyLayoutLoaderOptions } from "./gatsby-layout-loader" |
18 | | -import compileMDX from "./compile-mdx" |
| 17 | +import { compileMDX, compileMDXWithCustomOptions } from "./compile-mdx" |
19 | 18 | import { IGatsbyMDXLoaderOptions } from "./gatsby-mdx-loader" |
20 | 19 | import remarkInferTocMeta from "./remark-infer-toc-meta" |
21 | 20 |
|
@@ -145,58 +144,6 @@ export const preprocessSource: GatsbyNode["preprocessSource"] = async ( |
145 | 144 | return processedMDX.toString() |
146 | 145 | } |
147 | 146 |
|
148 | | -/** |
149 | | - * This helper function allows you to inject additional plugins and configuration into the MDX |
150 | | - * compilation pipeline. Very useful to create your own resolvers that return custom metadata. |
151 | | - * Internally used to generate the tables of contents and the excerpts. |
152 | | - */ |
153 | | -export const compileMDXWithCustomOptions = async ({ |
154 | | - pluginOptions, |
155 | | - customOptions, |
156 | | - getNode, |
157 | | - getNodesByType, |
158 | | - pathPrefix, |
159 | | - reporter, |
160 | | - cache, |
161 | | - mdxNode, |
162 | | -}: { |
163 | | - pluginOptions: IMdxPluginOptions |
164 | | - customOptions: Partial<IMdxPluginOptions> |
165 | | - getNode: NodePluginArgs["getNode"] |
166 | | - getNodesByType: NodePluginArgs["getNodesByType"] |
167 | | - pathPrefix: string |
168 | | - reporter: NodePluginArgs["reporter"] |
169 | | - cache: NodePluginArgs["cache"] |
170 | | - mdxNode: IMdxNode |
171 | | -}): Promise<{ |
172 | | - processedMDX: string |
173 | | - metadata: IMdxMetadata |
174 | | -} | null> => { |
175 | | - const customPluginOptions = deepmerge( |
176 | | - Object.assign({}, pluginOptions), |
177 | | - customOptions |
178 | | - ) |
179 | | - |
180 | | - // Prepare MDX compile |
181 | | - const mdxOptions = await enhanceMdxOptions(customPluginOptions, { |
182 | | - getNode, |
183 | | - getNodesByType, |
184 | | - pathPrefix, |
185 | | - reporter, |
186 | | - cache, |
187 | | - }) |
188 | | - if (!mdxNode.parent) { |
189 | | - return null |
190 | | - } |
191 | | - const fileNode = getNode(mdxNode.parent) |
192 | | - if (!fileNode) { |
193 | | - return null |
194 | | - } |
195 | | - |
196 | | - // Compile MDX and extract metadata |
197 | | - return compileMDX(mdxNode, fileNode, mdxOptions) |
198 | | -} |
199 | | - |
200 | 147 | export const createSchemaCustomization: GatsbyNode["createSchemaCustomization"] = |
201 | 148 | async ( |
202 | 149 | { getNode, getNodesByType, pathPrefix, reporter, cache, actions, schema }, |
|
0 commit comments