Skip to content

Commit

Permalink
split out preprocessSource into ./gatsby/`
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherBiscardi committed Jun 27, 2019
1 parent 702cfb6 commit 38bf79b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
16 changes: 1 addition & 15 deletions packages/gatsby-plugin-mdx/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
const path = require("path");
const mkdirp = require("mkdirp");
const { MDX_WRAPPERS_LOCATION, MDX_SCOPES_LOCATION } = require("./constants");

const defaultOptions = require("./utils/default-options");
const mdx = require("./utils/mdx");

/**
* Create Mdx nodes from MDX files.
Expand Down Expand Up @@ -35,19 +33,7 @@ exports.resolvableExtensions = (data, pluginOptions) =>
/**
* Convert MDX to JSX so that Gatsby can extract the GraphQL queries.
*/
exports.preprocessSource = async function preprocessSource(
{ filename, contents },
pluginOptions
) {
const { extensions, ...options } = defaultOptions(pluginOptions);
const ext = path.extname(filename);

if (extensions.includes(ext)) {
const code = await mdx(contents, options);
return code;
}
return null;
};
exports.preprocessSource = require("./gatsby/preprocess-source");

/**
* Required config for mdx to function
Expand Down
17 changes: 17 additions & 0 deletions packages/gatsby-plugin-mdx/gatsby/preprocess-source.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const path = require("path");
const mdx = require("../utils/mdx");
const defaultOptions = require("../utils/default-options");

module.exports = async function preprocessSource(
{ filename, contents },
pluginOptions
) {
const { extensions, ...options } = defaultOptions(pluginOptions);
const ext = path.extname(filename);

if (extensions.includes(ext)) {
const code = await mdx(contents, options);
return code;
}
return null;
};

0 comments on commit 38bf79b

Please sign in to comment.