Skip to content

Commit

Permalink
Add support for file argument in remark plugins for gatsby-plugin-mdx (
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin940726 authored Apr 21, 2020
1 parent da535a8 commit 67730fd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
5 changes: 4 additions & 1 deletion packages/gatsby-plugin-mdx/gatsby/on-create-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ module.exports = async ({ page, actions }, pluginOptions) => {
// we're trying to insert and if we don't check we can end up in infinite loops
if (extensions.includes(ext) && !page.context.frontmatter) {
const content = await fs.readFile(page.component, `utf8`)
const code = await mdx(content, options)
const code = await mdx(content, {
filepath: page.component,
...options,
})

// grab the exported frontmatter
const { frontmatter } = extractExports(code)
Expand Down
5 changes: 4 additions & 1 deletion packages/gatsby-plugin-mdx/gatsby/preprocess-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ module.exports = async function preprocessSource(
const ext = path.extname(filename)

if (extensions.includes(ext)) {
const code = await mdx(contents, options)
const code = await mdx(contents, {
filepath: filename,
...options,
})
return code
}
return null
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby-plugin-mdx/utils/gen-mdx.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export const _frontmatter = ${JSON.stringify(data)}`

debug(`running mdx`)
let code = await mdx(content, {
filepath: node.fileAbsolutePath,
...options,
remarkPlugins: options.remarkPlugins.concat(
gatsbyRemarkPluginsAsremarkPlugins
Expand Down

0 comments on commit 67730fd

Please sign in to comment.