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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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!