From 2c5ad1993256763886e9eba454bfe0125a2a6aac Mon Sep 17 00:00:00 2001 From: curbengh <43627182+curbengh@users.noreply.github.com> Date: Fri, 4 Oct 2019 08:27:25 +0100 Subject: [PATCH] fix: utilize hexo.log to display error message --- lib/filter.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/filter.js b/lib/filter.js index f29de60..090cb66 100644 --- a/lib/filter.js +++ b/lib/filter.js @@ -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) } } })