fix: utilize hexo.log to display error message

This commit is contained in:
curbengh 2019-10-04 08:27:25 +01:00
parent 680ee73a03
commit 2c5ad19932
No known key found for this signature in database
GPG Key ID: 21EA847C35D6E034
1 changed files with 9 additions and 4 deletions

View File

@ -24,6 +24,11 @@ function verbose (original, minified, path, ext) {
log.log(`${ext}: ${path} [${saved}% saved]`)
}
function error (msg) {
const log = this.log || console
log.error(msg)
}
function minifyHtml (str, data) {
const hexo = this
const options = hexo.config.minify.html
@ -64,7 +69,7 @@ async function minifyCss (str, data) {
if (options.logger) verbose.call(this, str, result.styles, path, 'css')
return result.styles
} catch (err) {
throw new Error(err)
error(err)
}
}
@ -122,8 +127,8 @@ function minifySvg () {
if (options.logger) verbose.call(this, assetTxt, result.data, path, 'svg')
resolve(route.set(path, result.data))
} catch (err) {
error(err)
reject(err)
throw new Error(err)
}
}
})
@ -159,8 +164,8 @@ function gzipFn () {
if (options.logger) verbose.call(this, assetTxt, result.toString(), path, 'gzip')
resolve(route.set(path + '.gz', result))
} catch (err) {
error(err)
reject(err)
throw new Error(err)
}
}
})
@ -198,8 +203,8 @@ function brotliFn () {
if (options.logger) verbose.call(this, input, result.toString(), path, 'brotli')
resolve(route.set(path + '.br', result))
} catch (err) {
error(err)
reject(err)
throw new Error(err)
}
}
})