mirror of https://github.com/curbengh/hexo-yam
fix: function for after_generate return void
This commit is contained in:
parent
bcaa327494
commit
83f62ea518
|
@ -8,10 +8,10 @@ function minifyJson() {
|
|||
const route = hexo.route
|
||||
/** @type {string[]} */
|
||||
const routeList = route.list()
|
||||
const { globOptions, include, verbose, useBigInt } = options
|
||||
const { globOptions, include, verbose } = options
|
||||
|
||||
return Promise.all((match(routeList, include, globOptions)).map(path => {
|
||||
return new Promise((/** @type {(value: string) => void} */ resolve, reject) => {
|
||||
return new Promise((/** @type {(value: void) => void} */ resolve, reject) => {
|
||||
const assetPath = route.get(path)
|
||||
let assetTxt = ''
|
||||
assetPath.on('data', chunk => (assetTxt += chunk))
|
||||
|
@ -20,12 +20,12 @@ function minifyJson() {
|
|||
try {
|
||||
const result = JSON.stringify(JSON.parse(assetTxt))
|
||||
if (verbose) logFn.call(this, assetTxt, result, path, 'json')
|
||||
resolve(route.set(path, result))
|
||||
route.set(path, result)
|
||||
} catch (err) {
|
||||
reject(new Error(`Path: ${path}\n${err}`))
|
||||
}
|
||||
}
|
||||
resolve(assetTxt)
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
}))
|
||||
|
|
|
@ -20,7 +20,7 @@ function minifySvg() {
|
|||
}]
|
||||
|
||||
return Promise.all((match(routeList, include, globOptions)).map(path => {
|
||||
return new Promise((/** @type {(value: string) => void} */ resolve, reject) => {
|
||||
return new Promise((/** @type {(value: void) => void} */ resolve, reject) => {
|
||||
const assetPath = route.get(path)
|
||||
let assetTxt = ''
|
||||
assetPath.on('data', chunk => (assetTxt += chunk))
|
||||
|
@ -29,12 +29,12 @@ function minifySvg() {
|
|||
try {
|
||||
const data = svgOptimize(assetTxt, { ...options, plugins }).data
|
||||
if (verbose) logFn.call(this, assetTxt, data, path, 'svg')
|
||||
resolve(route.set(path, data))
|
||||
route.set(path, data)
|
||||
} catch (err) {
|
||||
reject(new Error(`Path: ${path}\n${err}`))
|
||||
}
|
||||
}
|
||||
resolve(assetTxt)
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
}))
|
||||
|
|
|
@ -12,7 +12,7 @@ function minifyXml() {
|
|||
const { globOptions, include, verbose } = options
|
||||
|
||||
return Promise.all((match(routeList, include, globOptions)).map(path => {
|
||||
return new Promise((/** @type {(value: string) => void} */ resolve, reject) => {
|
||||
return new Promise((/** @type {(value: void) => void} */ resolve, reject) => {
|
||||
const assetPath = route.get(path)
|
||||
let assetTxt = ''
|
||||
assetPath.on('data', chunk => (assetTxt += chunk))
|
||||
|
@ -21,12 +21,12 @@ function minifyXml() {
|
|||
try {
|
||||
const result = compressXml(assetTxt, { ...options })
|
||||
if (verbose) logFn.call(this, assetTxt, result, path, 'xml')
|
||||
resolve(route.set(path, result))
|
||||
route.set(path, result)
|
||||
} catch (err) {
|
||||
reject(new Error(`Path: ${path}\n${err}`))
|
||||
}
|
||||
}
|
||||
resolve(assetTxt)
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
}))
|
||||
|
|
11
lib/zlib.js
11
lib/zlib.js
|
@ -17,7 +17,7 @@ function gzipFn() {
|
|||
if (typeof level !== 'number') level = zlib.constants.Z_BEST_COMPRESSION
|
||||
|
||||
return Promise.all((match(routeList, include, globOptions)).map(path => {
|
||||
return new Promise((/** @type {(value: string) => void} */ resolve, reject) => {
|
||||
return new Promise((/** @type {(value: void) => void} */ resolve, reject) => {
|
||||
const assetPath = route.get(path)
|
||||
let assetTxt = ''
|
||||
assetPath.on('data', chunk => (assetTxt += chunk))
|
||||
|
@ -27,11 +27,12 @@ function gzipFn() {
|
|||
const result = await gzip(assetTxt, { level })
|
||||
if (verbose) logFn.call(this, assetTxt, result, path, 'gzip')
|
||||
resolve(route.set(path + '.gz', result))
|
||||
return
|
||||
} catch (err) {
|
||||
reject(new Error(`Path: ${path}\n${err}`))
|
||||
}
|
||||
}
|
||||
resolve(assetTxt)
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
}))
|
||||
|
@ -48,7 +49,7 @@ function brotliFn() {
|
|||
if (typeof level !== 'number') level = zlib.constants.BROTLI_MAX_QUALITY
|
||||
|
||||
return Promise.all((match(routeList, include, globOptions)).map(path => {
|
||||
return new Promise((/** @type {(value: string) => void} */ resolve, reject) => {
|
||||
return new Promise((/** @type {(value: void) => void} */ resolve, reject) => {
|
||||
const assetPath = route.get(path)
|
||||
let assetTxt = ''
|
||||
assetPath.on('data', chunk => (assetTxt += chunk))
|
||||
|
@ -57,12 +58,12 @@ function brotliFn() {
|
|||
try {
|
||||
const result = await br(assetTxt, { params: { [zlib.constants.BROTLI_PARAM_QUALITY]: level } })
|
||||
if (verbose) logFn.call(this, assetTxt, result, path, 'brotli')
|
||||
resolve(route.set(path + '.br', result))
|
||||
route.set(path + '.br', result)
|
||||
} catch (err) {
|
||||
reject(new Error(`Path: ${path}\n${err}`))
|
||||
}
|
||||
}
|
||||
resolve(assetTxt)
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
}))
|
||||
|
|
|
@ -14,7 +14,7 @@ function zstdFn() {
|
|||
if (typeof level !== 'number') level = undefined
|
||||
|
||||
return Promise.all((match(routeList, include, globOptions)).map(path => {
|
||||
return new Promise((/** @type {(value: string) => void} */ resolve, reject) => {
|
||||
return new Promise((/** @type {(value: void) => void} */ resolve, reject) => {
|
||||
const assetPath = route.get(path)
|
||||
let assetTxt = ''
|
||||
assetPath.on('data', chunk => (assetTxt += chunk))
|
||||
|
@ -24,12 +24,12 @@ function zstdFn() {
|
|||
const input = Buffer.from(assetTxt, 'utf-8')
|
||||
const result = await zstd(input, level)
|
||||
if (verbose) logFn.call(this, assetTxt, result, path, 'zstd')
|
||||
resolve(route.set(path + '.zst', result))
|
||||
route.set(path + '.zst', result)
|
||||
} catch (err) {
|
||||
reject(new Error(`Path: ${path}\n${err}`))
|
||||
}
|
||||
}
|
||||
resolve(assetTxt)
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
}))
|
||||
|
|
Loading…
Reference in New Issue