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