style: standard

This commit is contained in:
curbengh 2019-08-06 11:57:44 +09:30
parent d72bb5b567
commit 32a519928a
No known key found for this signature in database
GPG Key ID: 21EA847C35D6E034
1 changed files with 27 additions and 27 deletions

View File

@ -33,10 +33,10 @@ function logicHtml (str, data) {
// Return if a path matches exclusion pattern
if (isMatch(path, exclude, globOptions)) return str
let result = Htmlminifier(str, options)
let saved = ((str.length - result.length) / str.length * 100).toFixed(2)
const result = Htmlminifier(str, options)
const saved = ((str.length - result.length) / str.length * 100).toFixed(2)
if (options.logger) {
let log = hexo.log || console.log
const log = hexo.log || console.log
log.log('Minify the html: %s [%s saved]', path, saved + '%')
}
return result
@ -60,10 +60,10 @@ function logicCss (str, data) {
return new Promise((resolve, reject) => {
new CleanCSS(options).minify(str, (err, result) => {
if (err) return reject(err)
let saved = ((str.length - result.styles.length) / str.length * 100).toFixed(2)
const saved = ((str.length - result.styles.length) / str.length * 100).toFixed(2)
resolve(result.styles)
if (options.logger) {
let log = hexo.log || console.log
const log = hexo.log || console.log
log.log('Minify the css: %s [%s saved]', path, saved + '%')
}
})
@ -92,10 +92,10 @@ function logicJs (str, data) {
delete jsOptions.logger
delete jsOptions.globOptions
let result = Terser.minify(str, jsOptions)
let saved = ((str.length - result.code.length) / str.length * 100).toFixed(2)
const result = Terser.minify(str, jsOptions)
const saved = ((str.length - result.code.length) / str.length * 100).toFixed(2)
if (options.logger) {
let log = hexo.log || console.log
const log = hexo.log || console.log
log.log('Minify the js: %s [%s saved]', path, saved + '%')
}
return result.code
@ -107,9 +107,9 @@ function logicSvg () {
// Return if disabled.
if (options.enable === false) return
let route = hexo.route
let routeList = route.list()
let include = options.include
const route = hexo.route
const routeList = route.list()
const include = options.include
const globOptions = options.globOptions
let includeString = include
@ -119,7 +119,7 @@ function logicSvg () {
return Promise.all((micromatch(routeList, include, globOptions)).map(path => {
return new Promise((resolve, reject) => {
// Grab all assets using hexo router
let assetPath = route.get(path)
const assetPath = route.get(path)
let assetTxt = ''
// Extract the content
assetPath.on('data', (chunk) => (assetTxt += chunk))
@ -130,9 +130,9 @@ function logicSvg () {
// Replace the original file with the minified.
route.set(path, result.data)
// Logging
let saved = ((assetTxt.length - result.data.length) / assetTxt.length * 100).toFixed(2)
const saved = ((assetTxt.length - result.data.length) / assetTxt.length * 100).toFixed(2)
if (options.logger) {
let log = hexo.log || console.log
const log = hexo.log || console.log
log.log('Minify the svg: %s [%s saved]', path, saved + '%')
}
resolve(assetTxt)
@ -149,9 +149,9 @@ function logicGzip () {
// Return if disabled.
if (options.enable === false) return
let route = hexo.route
let routeList = route.list()
let include = options.include
const route = hexo.route
const routeList = route.list()
const include = options.include
const globOptions = options.globOptions
let includeString = include
@ -161,7 +161,7 @@ function logicGzip () {
return Promise.all((micromatch(routeList, include, globOptions)).map(path => {
return new Promise((resolve, reject) => {
// Grab all assets using hexo router
let assetPath = route.get(path)
const assetPath = route.get(path)
let assetTxt = ''
// Extract the content
assetPath.on('data', (chunk) => (assetTxt += chunk))
@ -173,9 +173,9 @@ function logicGzip () {
// Save the compressed file to .gz
route.set(path + '.gz', Input)
// Logging
let saved = ((assetTxt.length - Input.toString().length) / assetTxt.length * 100).toFixed(2)
const saved = ((assetTxt.length - Input.toString().length) / assetTxt.length * 100).toFixed(2)
if (options.logger) {
let log = hexo.log || console.log
const log = hexo.log || console.log
log.log('Gzip-compressed %s [%s saved]', path, saved + '%')
}
resolve(assetTxt)
@ -195,9 +195,9 @@ function logicBrotli () {
// Return if disabled.
if (options.enable === false) return
let route = hexo.route
let routeList = route.list()
let include = options.include
const route = hexo.route
const routeList = route.list()
const include = options.include
const globOptions = options.globOptions
let includeString = include
@ -207,23 +207,23 @@ function logicBrotli () {
return Promise.all((micromatch(routeList, include, globOptions)).map(path => {
return new Promise((resolve, reject) => {
// Grab all assets using hexo router
let assetPath = route.get(path)
const assetPath = route.get(path)
let assetTxt = ''
// Extract the content
assetPath.on('data', (chunk) => (assetTxt += chunk))
assetPath.on('end', () => {
if (assetTxt.length) {
// Input has to be buffer for brotli
let input = Buffer.from(assetTxt, 'utf-8')
const input = Buffer.from(assetTxt, 'utf-8')
// brotli defaults to max compression level
br.compress(input, (err, output) => {
if (!err) {
// Save the compressed file to .br
route.set(path + '.br', output)
// Logging
let saved = ((input.length - output.toString().length) / input.length * 100).toFixed(2)
const saved = ((input.length - output.toString().length) / input.length * 100).toFixed(2)
if (options.logger) {
let log = hexo.log || console.log
const log = hexo.log || console.log
log.log('Brotli-compressed %s [%s saved]', path, saved + '%')
}
resolve(assetTxt)