Skip to content

Instantly share code, notes, and snippets.

@d4rekanguok
Created August 14, 2019 19:18
Show Gist options
  • Save d4rekanguok/8b1cd3954d27be9a51cf392af485598c to your computer and use it in GitHub Desktop.
Save d4rekanguok/8b1cd3954d27be9a51cf392af485598c to your computer and use it in GitHub Desktop.
const unified = require('unified')
const remarkParse = require('remark-parse')
const remarkHtml = require('remark-html')
exports.createResolvers = ({
createResolvers,
}) => {
const toHTML = async (source) => {
const vfile = await unified()
.use(remarkParse)
.use(remarkHtml)
.process(source)
return vfile.contents
}
const resolvers = {
MarkdownRemarkFrontmatter: {
text: {
resolve: async (source) => {
const html = await toHTML(source.text)
return html
},
},
},
}
return createResolvers(resolvers)
}
@hu0p
Copy link

hu0p commented Aug 19, 2019

Hey there! No problem at all. I did manage to infer part of this myself, but I was using onCreateNode instead. This actually seems cleaner though, so thanks for that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment