From 0089858eb82b4139ef0b39a6b6c5431f5577d0dd Mon Sep 17 00:00:00 2001 From: Mingyu Gu Date: Fri, 29 Jun 2018 15:49:13 +0800 Subject: [PATCH 1/3] Fixed 'exclude' config does not work issue Matching paths require add the `{ matchBase: true }` paramter --- lib/filter.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/filter.js b/lib/filter.js index 8aa00c4..e7795d3 100644 --- a/lib/filter.js +++ b/lib/filter.js @@ -20,7 +20,7 @@ function logic_html(str, data) { if (path && exclude && exclude.length) { for (var i = 0, len = exclude.length; i < len; i++) { - if (minimatch(path, exclude[i])) return str; + if (minimatch(path, exclude[i], {matchBase: true})) return str; } } @@ -46,7 +46,7 @@ function logic_css(str, data) { if (path && exclude && exclude.length) { for (var i = 0, len = exclude.length; i < len; i++) { - if (minimatch(path, exclude[i])) return str; + if (minimatch(path, exclude[i], {matchBase: true})) return str; } } @@ -76,7 +76,7 @@ function logic_js(str, data) { if (path && exclude && exclude.length) { for (var i = 0, len = exclude.length; i < len; i++) { - if (minimatch(path, exclude[i])) return str; + if (minimatch(path, exclude[i], {matchBase: true})) return str; } } From 8300b7247893593d18223fae57a86a7a56ae9ff3 Mon Sep 17 00:00:00 2001 From: mygu Date: Fri, 29 Jun 2018 16:08:47 +0800 Subject: [PATCH 2/3] Add a print log configuration switch to solve compilation performance problems --- index.js | 3 +++ lib/filter.js | 24 ++++++++++++++---------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index 3eb3538..2b9426a 100644 --- a/index.js +++ b/index.js @@ -6,6 +6,7 @@ var assign = require('object-assign'); // HTML minifier hexo.config.neat_html = assign({ enable: true, + logger: true, exclude: [], ignoreCustomComments: [/^\s*more/], removeComments: true, @@ -20,6 +21,7 @@ var assign = require('object-assign'); // Css minifier hexo.config.neat_css = assign({ enable: true, + logger: true, exclude: ['*.min.css'] }, hexo.config.neat_css); @@ -27,6 +29,7 @@ var assign = require('object-assign'); hexo.config.neat_js = assign({ enable: true, mangle: true, + logger: true, output: {}, compress: {}, exclude: ['*.min.js'] diff --git a/lib/filter.js b/lib/filter.js index e7795d3..1bdad6d 100644 --- a/lib/filter.js +++ b/lib/filter.js @@ -24,10 +24,12 @@ function logic_html(str, data) { } } - var log = hexo.log || console.log; var result = Htmlminifier(str, options); var saved = ((str.length - result.length) / str.length * 100).toFixed(2); - log.log('neat the html: %s [ %s saved]', path, saved + '%'); + if (options.logger) { + var log = hexo.log || console.log; + log.log('neat the html: %s [ %s saved]', path, saved + '%'); + } var prefix = '"; var end = ''; result = prefix + result + end; @@ -50,16 +52,18 @@ function logic_css(str, data) { } } - var log = hexo.log || console.log; - return new Promise(function(resolve, reject) { - new CleanCSS(options).minify(str, function(err, result) { + return new Promise(function (resolve, reject) { + new CleanCSS(options).minify(str, function (err, result) { if (err) return reject(err); var saved = ((str.length - result.styles.length) / str.length * 100).toFixed(2); var prefix = '/* build time:' + Date().toLocaleString() + "*/\n"; var end = '\n/* rebuild by neat */'; var css_result = prefix + result.styles + end; resolve(css_result); - log.log('neat the css: %s [ %s saved]', path, saved + '%'); + if (options.logger) { + var log = hexo.log || console.log; + log.log('neat the css: %s [ %s saved]', path, saved + '%'); + } }); }); } @@ -80,18 +84,18 @@ function logic_js(str, data) { } } - var log = hexo.log || console; var result = UglifyJS.minify(str, options); var saved = ((str.length - result.code.length) / str.length * 100).toFixed(2); - log.log('neat the js: %s [ %s saved]', path, saved + '%'); + if (options.logger) { + var log = hexo.log || console.log; + log.log('neat the js: %s [ %s saved]', path, saved + '%'); + } var prefix = '// build time:' + Date().toLocaleString() + "\n"; var end = '\n//rebuild by neat '; var js_result = prefix + result.code + end; return js_result; } - - module.exports = { logic_html: logic_html, logic_css: logic_css, From b44d0244305a2be3c57aeb4a88cd7a460dbdec99 Mon Sep 17 00:00:00 2001 From: mygu Date: Fri, 29 Jun 2018 16:11:00 +0800 Subject: [PATCH 3/3] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index d194cf0..d56fdd6 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ neat_html: exclude: ``` - **enable** - Enable the plugin. Defaults to `true`. +- **logger** - Print log switch. Defaults to `true`. - **exclude**: Exclude files **Note:** there are so many params please see '[HTMLMinifier](https://github.com/kangax/html-minifier)' ---------- @@ -37,6 +38,7 @@ neat_css: - '*.min.css' ``` - **enable** - Enable the plugin. Defaults to `true`. +- **logger** - Print log switch. Defaults to `true`. - **exclude**: Exclude files ---------- @@ -52,6 +54,7 @@ neat_js: ``` - **enable** - Enable the plugin. Defaults to `true`. - **mangle**: Mangle file names +- **logger** - Print log switch. Defaults to `true`. - **output**: Output options - **compress**: Compress options - **exclude**: Exclude files