Created
August 14, 2019 19:18
-
-
Save d4rekanguok/8b1cd3954d27be9a51cf392af485598c to your computer and use it in GitHub Desktop.
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
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) | |
} |
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
@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