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)
}
@d4rekanguok
Copy link
Author

@hu0p my apologies for leaving you hanging the other day -- I was afk for a bit. Here's an example code for using createResolvers to transform simple markdown to html. I use json & just change the typename to markdown & haven't tested it yet, but hopefully it can give you an idea, in case you haven't figured out a good solution yet

@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