forked from gatsbyjs/gatsby
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gatsby methods clean up (gatsbyjs#111)
- Loading branch information
1 parent
27ec005
commit e7ea583
Showing
6 changed files
with
121 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
packages/gatsby-plugin-mdx/gatsby/create-webpack-config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
const path = require("path"); | ||
const escapeStringRegexp = require("escape-string-regexp"); | ||
const defaultOptions = require("../utils/default-options"); | ||
|
||
module.exports = ( | ||
{ stage, loaders, plugins, actions, getNodes }, | ||
pluginOptions | ||
) => { | ||
const options = defaultOptions(pluginOptions); | ||
const testPattern = new RegExp( | ||
options.extensions.map(ext => `${escapeStringRegexp(ext)}$`).join("|") | ||
); | ||
const mdxTestPattern = new RegExp( | ||
options.extensions | ||
.concat(".deck-mdx") | ||
.map(ext => `${escapeStringRegexp(ext)}$`) | ||
.join("|") | ||
); | ||
|
||
const decks = options.decks.map(ext => `${escapeStringRegexp(ext)}`); | ||
|
||
actions.setWebpackConfig({ | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.js$/, | ||
include: path.resolve(__dirname, ".cache/gatsby-mdx"), | ||
use: [loaders.js()] | ||
}, | ||
{ | ||
test: testPattern, | ||
exclude: decks, | ||
use: [ | ||
loaders.js(), | ||
{ | ||
loader: "gatsby-mdx/mdx-loader", | ||
options: { | ||
getNodes, | ||
pluginOptions: options | ||
} | ||
} | ||
] | ||
}, | ||
{ | ||
test: mdxTestPattern, | ||
include: decks, | ||
use: [ | ||
loaders.js(), | ||
{ loader: "gatsby-mdx/mdx-deck-post-loader" }, | ||
{ loader: "mdx-deck/loader" } | ||
] | ||
}, | ||
{ | ||
test: /.deck-mdx$/, | ||
use: [ | ||
loaders.js(), | ||
{ loader: "gatsby-mdx/mdx-deck-post-loader" }, | ||
{ loader: "mdx-deck/loader" } | ||
] | ||
} | ||
] | ||
}, | ||
plugins: [ | ||
plugins.define({ | ||
__DEVELOPMENT__: stage === `develop` || stage === `develop-html` | ||
}) | ||
] | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
packages/gatsby-plugin-mdx/on-create-node.js → ...atsby-plugin-mdx/gatsby/on-create-node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const path = require("path"); | ||
const fs = require("fs-extra"); | ||
const merge = require("lodash/merge"); | ||
const defaultOptions = require("../utils/default-options"); | ||
const extractExports = require("../utils/extract-exports"); | ||
const mdx = require("../utils/mdx"); | ||
|
||
module.exports = async ({ page, actions }, pluginOptions) => { | ||
const { createPage, deletePage } = actions; | ||
const { extensions, ...options } = defaultOptions(pluginOptions); | ||
const ext = path.extname(page.component); | ||
|
||
if (extensions.includes(ext)) { | ||
const content = await fs.readFile(page.component, "utf8"); | ||
const code = await mdx(content, options); | ||
|
||
// grab the exported frontmatter | ||
const { frontmatter } = extractExports(code); | ||
|
||
deletePage(page); | ||
createPage( | ||
merge( | ||
{ | ||
context: { | ||
frontmatter: { | ||
...frontmatter | ||
} | ||
} | ||
}, | ||
page | ||
) | ||
); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
// noop | ||
/** | ||
* Welcome to gastby-mdx! | ||
* | ||
* Start reading in gatsby-node.js | ||
*/ |