build(aio): capture and log errors and warnings when post-processing HTML

This commit is contained in:
Peter Bacon Darwin
2017-04-28 11:34:01 +01:00
committed by Matias Niemelä
parent 9945ce2259
commit 64335d3521
3 changed files with 38 additions and 5 deletions

View File

@ -17,7 +17,7 @@ const rehype = require('rehype');
* @property plugins {Function[]} the rehype plugins that will modify the HAST.
*
*/
module.exports = function postProcessHtml() {
module.exports = function postProcessHtml(log, createDocMessage) {
return {
$runAfter: ['docs-rendered'],
$runBefore: ['writing-files'],
@ -30,8 +30,18 @@ module.exports = function postProcessHtml() {
docs
.filter(doc => this.docTypes.indexOf(doc.docType) !== -1)
.forEach(doc =>
doc.renderedContent = engine.processSync(doc.renderedContent).contents);
.forEach(doc => {
const vFile = engine.processSync(doc.renderedContent);
vFile.messages.forEach(m => {
const message = createDocMessage(m.message, doc);
if (m.fatal) {
throw new Error(message);
} else {
log.warn(message);
}
});
doc.renderedContent = vFile.contents;
});
}
};
};