Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[gatsby-plugin-mdx] Add support for file argument in remark plugins #21489

Merged
merged 1 commit into from
Apr 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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