From 7e85bd63380cb695d36d4ffc3d484a17455a19f5 Mon Sep 17 00:00:00 2001 From: curbengh <43627182+curbengh@users.noreply.github.com> Date: Wed, 11 Sep 2019 02:15:19 +0100 Subject: [PATCH] feat: enable plugin by default and update options naming --- index.js | 114 +++++++++++++++++++++++++------------------------- lib/filter.js | 12 +++--- 2 files changed, 62 insertions(+), 64 deletions(-) diff --git a/index.js b/index.js index 40eae3e..383dd5b 100644 --- a/index.js +++ b/index.js @@ -1,70 +1,68 @@ /* global hexo */ 'use strict' -if (hexo.config.neat_enable === true) { - // HTML minifier - hexo.config.neat_html = Object.assign({ - enable: true, - logger: false, - exclude: [], - collapseBooleanAttributes: true, - collapseWhitespace: true, - // Ignore '' https://hexo.io/docs/tag-plugins#Post-Excerpt - ignoreCustomComments: [/^\s*more/], - removeComments: true, - removeEmptyAttributes: true, - removeScriptTypeAttributes: true, - removeStyleLinkTypeAttributes: true, - minifyJS: true, - minifyCSS: true, - globOptions: { basename: true } - }, hexo.config.neat_html) +hexo.config.minify = Object.assign({ + enable: true +}, hexo.config.minify) - // CSS minifier - hexo.config.neat_css = Object.assign({ - enable: true, - logger: false, - exclude: ['*.min.css'], - level: 2, - globOptions: { basename: true } - }, hexo.config.neat_css) +hexo.config.minify.html = Object.assign({ + enable: true, + logger: false, + exclude: [], + collapseBooleanAttributes: true, + collapseWhitespace: true, + // Ignore '' https://hexo.io/docs/tag-plugins#Post-Excerpt + ignoreCustomComments: [/^\s*more/], + removeComments: true, + removeEmptyAttributes: true, + removeScriptTypeAttributes: true, + removeStyleLinkTypeAttributes: true, + minifyJS: true, + minifyCSS: true, + globOptions: { basename: true } +}, hexo.config.minify.html) - // Javascript minifier - hexo.config.neat_js = Object.assign({ - enable: true, - logger: false, - exclude: ['*.min.js'], - compress: {}, - mangle: true, - output: {}, - globOptions: { basename: true } - }, hexo.config.neat_js) +hexo.config.minify.css = Object.assign({ + enable: true, + logger: false, + exclude: ['*.min.css'], + level: 2, + globOptions: { basename: true } +}, hexo.config.minify.css) - // SVG minifier - hexo.config.neat_svg = Object.assign({ - enable: true, - logger: false, - include: ['*.svg', '!*.min.svg'], - plugins: [], - globOptions: { basename: true } - }, hexo.config.neat_svg) +hexo.config.minify.js = Object.assign({ + enable: true, + logger: false, + exclude: ['*.min.js'], + compress: {}, + mangle: true, + output: {}, + globOptions: { basename: true } +}, hexo.config.minify.js) - // gzip compression - hexo.config.neat_gzip = Object.assign({ - enable: true, - logger: false, - include: ['*.html', '*.css', '*.js', '*.txt', '*.ttf', '*.atom', '*.stl', '*.xml', '*.svg', '*.eot', '*.json'], - globOptions: { basename: true } - }, hexo.config.neat_gzip) +hexo.config.minify.svg = Object.assign({ + enable: true, + logger: false, + include: ['*.svg', '!*.min.svg'], + plugins: [], + globOptions: { basename: true } +}, hexo.config.minify.svg) - // brotli compression - hexo.config.neat_brotli = Object.assign({ - enable: true, - logger: false, - include: ['*.html', '*.css', '*.js', '*.txt', '*.ttf', '*.atom', '*.stl', '*.xml', '*.svg', '*.eot', '*.json'], - globOptions: { basename: true } - }, hexo.config.neat_brotli) +hexo.config.minify.gzip = Object.assign({ + enable: true, + logger: false, + include: ['*.html', '*.css', '*.js', '*.txt', '*.ttf', '*.atom', '*.stl', '*.xml', '*.svg', '*.eot', '*.json'], + globOptions: { basename: true } +}, hexo.config.minify.gzip) +hexo.config.minify.brotli = Object.assign({ + enable: true, + logger: false, + include: ['*.html', '*.css', '*.js', '*.txt', '*.ttf', '*.atom', '*.stl', '*.xml', '*.svg', '*.eot', '*.json'], + globOptions: { basename: true } +}, hexo.config.minify.brotli) + +if (hexo.config.minify.enable === true) { const filter = require('./lib/filter') hexo.extend.filter.register('after_render:html', filter.logicHtml) hexo.extend.filter.register('after_render:css', filter.logicCss) diff --git a/lib/filter.js b/lib/filter.js index da9e10a..fc65c4f 100644 --- a/lib/filter.js +++ b/lib/filter.js @@ -18,7 +18,7 @@ function isMatch (path, patterns, options) { function logicHtml (str, data) { const hexo = this - const options = hexo.config.neat_html + const options = hexo.config.minify.html // Return if disabled. if (options.enable === false) return @@ -44,7 +44,7 @@ function logicHtml (str, data) { function logicCss (str, data) { const hexo = this - const options = hexo.config.neat_css + const options = hexo.config.minify.css if (options.enable === false) return const path = data.path @@ -72,7 +72,7 @@ function logicCss (str, data) { function logicJs (str, data) { const hexo = this - const options = hexo.config.neat_js + const options = hexo.config.minify.js if (options.enable === false) return const path = data.path @@ -103,7 +103,7 @@ function logicJs (str, data) { function logicSvg () { const hexo = this - const options = hexo.config.neat_svg + const options = hexo.config.minify.svg // Return if disabled. if (options.enable === false) return @@ -145,7 +145,7 @@ function logicSvg () { function logicGzip () { const hexo = this - const options = hexo.config.neat_gzip + const options = hexo.config.minify.gzip // Return if disabled. if (options.enable === false) return @@ -191,7 +191,7 @@ function logicGzip () { function logicBrotli () { const hexo = this - const options = hexo.config.neat_brotli + const options = hexo.config.minify.brotli // Return if disabled. if (options.enable === false) return