mirror of https://github.com/curbengh/hexo-yam
Merge 5deaab2a11 into 8849b2bec0
This commit is contained in:
commit
5b09e8274c
|
|
@ -8,7 +8,7 @@ jobs:
|
|||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||
node-version: ["20", "22", "24"]
|
||||
node-version: ["22", "24"]
|
||||
fail-fast: false
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ minify:
|
|||
svg:
|
||||
gzip:
|
||||
brotli:
|
||||
zstd:
|
||||
xml:
|
||||
json:
|
||||
```
|
||||
|
|
@ -53,6 +54,7 @@ minify:
|
|||
- **svg** - See [SVG](#svg) section
|
||||
- **gzip** - See [Gzip](#gzip) section
|
||||
- **brotli** - See [Brotli](#brotli) section
|
||||
- **zstd** - See [Zstd](#zstd) section
|
||||
- **xml** - See [XML](#xml) section
|
||||
- **json** - See [JSON](#json) section
|
||||
|
||||
|
|
@ -246,7 +248,7 @@ minify:
|
|||
```yaml
|
||||
minify:
|
||||
zstd:
|
||||
enable: false
|
||||
enable: true
|
||||
include:
|
||||
- "*.html"
|
||||
- "*.css"
|
||||
|
|
@ -261,12 +263,12 @@ minify:
|
|||
- "*.json"
|
||||
```
|
||||
|
||||
- **enable** - Enable the plugin. Defaults to `false`.
|
||||
- **enable** - Enable the plugin. Defaults to `true`.
|
||||
- **priority** - Plugin's priority. Defaults to `10`.
|
||||
- **verbose** - Verbose output. Defaults to `false`.
|
||||
- **include** - Include files. Support [wildcard](http://www.globtester.com/) pattern(s) in a string or array.
|
||||
- **globOptions** - See [globbing](#globbing) section.
|
||||
- **level** - Compression level. Range `1-22`. Defaults to `3`, or the value of [`DEFAULT_LEVEL`](https://github.com/mongodb-js/zstd/blob/a3a08c61c9045411c8275e248498dbc583457fb5/src/lib.rs#L9)
|
||||
- **level** - Compression level. Range `1-22`. Defaults to `3`, or the value of [`ZSTD_CLEVEL_DEFAULT`](https://nodejs.org/api/zlib.html#zlib_compressor_options_1)
|
||||
|
||||
## Globbing
|
||||
|
||||
|
|
|
|||
2
index.js
2
index.js
|
|
@ -70,7 +70,7 @@ hexo.config.minify.brotli = Object.assign({
|
|||
}, hexo.config.minify.brotli)
|
||||
|
||||
hexo.config.minify.zstd = Object.assign({
|
||||
enable: false,
|
||||
enable: true,
|
||||
priority: 10,
|
||||
verbose: false,
|
||||
include: ['*.html', '*.css', '*.js', '*.txt', '*.ttf', '*.atom', '*.stl', '*.xml', '*.svg', '*.eot', '*.json'],
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@ const zlib = require('node:zlib')
|
|||
const { promisify } = require('node:util')
|
||||
const gzip = promisify(zlib.gzip)
|
||||
const br = promisify(zlib.brotliCompress)
|
||||
const zstd = promisify(zlib.zstdCompress)
|
||||
const { minify: compressXml } = require('minify-xml')
|
||||
const micromatch = require('micromatch')
|
||||
const { compress: zstd } = require('@mongodb-js/zstd')
|
||||
|
||||
const isMatch = (path = '', patterns = [], options = {}) => {
|
||||
if (path && patterns) {
|
||||
|
|
@ -240,7 +240,7 @@ function zstdFn () {
|
|||
const routeList = route.list()
|
||||
const { globOptions, include, verbose } = options
|
||||
let { level } = options
|
||||
if (typeof level !== 'number') level = undefined
|
||||
if (typeof level !== 'number') level = zlib.constants.ZSTD_CLEVEL_DEFAULT
|
||||
|
||||
return Promise.all((match(routeList, include, globOptions)).map((path) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
|
@ -250,8 +250,7 @@ function zstdFn () {
|
|||
assetPath.on('end', async () => {
|
||||
if (assetTxt.length) {
|
||||
try {
|
||||
const input = Buffer.from(assetTxt, 'utf-8')
|
||||
const result = await zstd(input, level)
|
||||
const result = await zstd(assetTxt, { params: { [zlib.constants.ZSTD_c_compressionLevel]: level } })
|
||||
if (verbose) logFn.call(this, assetTxt, result, path, 'zstd')
|
||||
resolve(route.set(path + '.zst', result))
|
||||
} catch (err) {
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
"test": "jest"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 20.9.0"
|
||||
"node": ">= 22.15.0"
|
||||
},
|
||||
"author": "curben",
|
||||
"license": "MIT",
|
||||
|
|
@ -31,8 +31,7 @@
|
|||
"micromatch": "^4.0.2",
|
||||
"minify-xml": "^3.2.0",
|
||||
"svgo": "^4.0.0",
|
||||
"terser": "^5.3.0",
|
||||
"@mongodb-js/zstd": "^2.0.1"
|
||||
"terser": "^5.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"hexo": "^7.1.0",
|
||||
|
|
|
|||
|
|
@ -2,14 +2,16 @@
|
|||
'use strict'
|
||||
|
||||
const Hexo = require('hexo')
|
||||
const { compress: zstd, decompress: unzstd } = require('@mongodb-js/zstd')
|
||||
const zlib = require('zlib')
|
||||
const { promisify } = require('util')
|
||||
const zstd = promisify(zlib.zstdCompress)
|
||||
const unzstd = promisify(zlib.zstdDecompress)
|
||||
|
||||
describe('zstd', () => {
|
||||
const hexo = new Hexo(__dirname)
|
||||
const z = require('../lib/filter').zstdFn.bind(hexo)
|
||||
const path = 'foo.txt'
|
||||
const input = 'Lorem ipsum dolor sit amet consectetur adipiscing elit fusce'
|
||||
const inputBuf = Buffer.from(input, 'utf8')
|
||||
|
||||
beforeEach(() => {
|
||||
hexo.config.minify = {
|
||||
|
|
@ -36,7 +38,7 @@ describe('zstd', () => {
|
|||
output.on('data', (chunk) => (buf.push(chunk)))
|
||||
output.on('end', async () => {
|
||||
const result = Buffer.concat(buf)
|
||||
const expected = await zstd(inputBuf)
|
||||
const expected = await zstd(input)
|
||||
const resultUnzst = await unzstd(result)
|
||||
const expectedUnzst = await unzstd(expected)
|
||||
|
||||
|
|
@ -74,7 +76,7 @@ describe('zstd', () => {
|
|||
output.on('data', (chunk) => (buf.push(chunk)))
|
||||
output.on('end', async () => {
|
||||
const result = Buffer.concat(buf)
|
||||
const expected = await zstd(inputBuf, level)
|
||||
const expected = await zstd(input, { params: { [zlib.constants.ZSTD_c_compressionLevel]: level } })
|
||||
|
||||
expect(result.equals(expected)).toBe(true)
|
||||
})
|
||||
|
|
@ -98,7 +100,7 @@ describe('zstd', () => {
|
|||
output.on('data', (chunk) => (buf.push(chunk)))
|
||||
output.on('end', async () => {
|
||||
const result = Buffer.concat(buf)
|
||||
const expected = await zstd(inputBuf, undefined)
|
||||
const expected = await zstd(input, { params: { [zlib.constants.ZSTD_c_compressionLevel]: zlib.constants.ZSTD_CLEVEL_DEFAULT } })
|
||||
|
||||
expect(result.equals(expected)).toBe(true)
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue