Compare commits

...

75 Commits

Author SHA1 Message Date
MDLeom 4bd000bfee
release: 9.0.0 2024-06-22 02:28:47 +00:00
MDLeom 5fb3349dec
chore(npm): add "zstd" keyword
remove generic keywords
2024-06-22 02:26:43 +00:00
MDLeom 80b2325cbf
chore(npm): "repository" is now an object 2024-06-22 02:25:33 +00:00
MDLeom 812ff614fc
ci: use windows bash
variable is not expanded properly in pwsh
2024-06-11 12:37:53 +00:00
MDLeom 702eb2fa0c
ci: ${} not supported in pwsh 2024-06-11 12:22:08 +00:00
MDLeom a2c810cfb5
ci: install zstd binary 2024-06-11 12:06:41 +00:00
MDLeom 30c33c0ad3
docs: install zstd dependency explicitly
using --force --include=optional flags are excessive
This reverts commit e33fd0ed5d &
1b04f7c8f1.
2024-06-11 11:30:02 +00:00
MDLeom 1c9d91b524
docs(license): update year 2024-06-10 06:19:21 +00:00
MDLeom c18f4c8476
docs: differentiate minify and compress
update snyk badge
2024-06-10 06:18:06 +00:00
MDLeom e33fd0ed5d
build(npm): --force flag to install optional deps
of child deps
required by https://github.com/curbengh/hexo-yam#cannot-find-module-mongodb-jszstd-linux-x64-gnu
2024-06-08 08:11:38 +00:00
MDLeom 73db847fd4
docs: reorder sections
removed outdated http-compression section
2024-06-08 08:11:28 +00:00
Ming Di Leom 7639547408
Merge pull request #157 from curbengh/previewServer
feat: previewServer option
2024-06-07 20:06:54 +09:30
Ming Di Leom f7df26377a
Merge pull request #158 from curbengh/zstd
feat: zstd compression
2024-06-07 19:52:50 +09:30
MDLeom 1b04f7c8f1
docs(zstd): --force flag to install optional deps
of child deps
https://stackoverflow.com/a/42400102
2024-06-07 09:04:05 +00:00
MDLeom 18a5d8108b
test: include optional deps
to include zstd binary
2024-06-06 11:45:53 +00:00
MDLeom 7f2033e553
feat: zstd compression
disabled by default due to lack of server support
close #156
2024-06-06 11:14:57 +00:00
MDLeom e9584b2e0b
feat: previewServer option
BREAKING CHANGE
plugin is now disabled by default when running `hexo server`,
unless previewServer is set to false.

Close #154
Inspired by e778c55f37/index.js (L49)
2024-06-05 11:08:12 +00:00
Ming Di Leom e99e110d39
Merge pull request #155 from curbengh/dependabot/github_actions/codecov/codecov-action-4
chore(deps): bump codecov/codecov-action from 3 to 4
2024-06-05 18:46:36 +09:30
MDLeom a5f19dbe79
ci(codecov): add upload token
https://github.com/codecov/codecov-action/releases/tag/v4.0.0
2024-06-05 09:14:12 +00:00
MDLeom c3ed0c68c7
test: node 22
drop 21, EOL on 2024-06-01
2024-06-05 09:04:31 +00:00
MDLeom f92017f688
test: node 22
drop 21, EOL on 2024-06-01
2024-06-04 08:52:45 +00:00
dependabot[bot] 0abd90c78a
chore(deps): bump codecov/codecov-action from 3 to 4
Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 3 to 4.
- [Release notes](https://github.com/codecov/codecov-action/releases)
- [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/codecov/codecov-action/compare/v3...v4)

---
updated-dependencies:
- dependency-name: codecov/codecov-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-02-01 15:46:21 +00:00
Ming Di Leom 426da85620
Merge pull request #150 from curbengh/dependabot/github_actions/actions/cache-4
chore(deps): bump actions/cache from 3 to 4
2024-01-28 21:14:53 +10:30
Ming Di Leom bfb886abac
Merge pull request #149 from curbengh/dependabot/github_actions/github/codeql-action-3
chore(deps): bump github/codeql-action from 2 to 3
2024-01-28 21:12:39 +10:30
Ming Di Leom d99caafe90
Merge pull request #145 from curbengh/dependabot/github_actions/actions/setup-node-4
chore(deps): bump actions/setup-node from 3 to 4
2024-01-28 21:10:18 +10:30
Ming Di Leom 3cc6f5e79e
Merge pull request #151 from curbengh/dependabot/npm_and_yarn/hexo-7.1.0
chore(deps-dev): bump hexo from 6.3.0 to 7.1.0
2024-01-28 21:06:37 +10:30
Ming Di Leom 56af48f632
Merge pull request #152 from curbengh/html-minifier-terser
refactor: switch html-minifier to html-minifier-terser
2024-01-28 21:04:53 +10:30
MDLeom 0bee9ada0e
refactor: switch html-minifier to html-minifier-terser
https://github.com/kangax/html-minifier/issues/1135
2024-01-28 10:26:21 +00:00
dependabot[bot] 1af8c52cdb
chore(deps-dev): bump hexo from 6.3.0 to 7.1.0
Bumps [hexo](https://github.com/hexojs/hexo) from 6.3.0 to 7.1.0.
- [Release notes](https://github.com/hexojs/hexo/releases)
- [Commits](https://github.com/hexojs/hexo/compare/6.3.0...v7.1.0)

---
updated-dependencies:
- dependency-name: hexo
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-01-19 15:40:47 +00:00
dependabot[bot] 81ceea413d
chore(deps): bump actions/cache from 3 to 4
Bumps [actions/cache](https://github.com/actions/cache) from 3 to 4.
- [Release notes](https://github.com/actions/cache/releases)
- [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md)
- [Commits](https://github.com/actions/cache/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/cache
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-01-18 15:37:36 +00:00
dependabot[bot] 8e937ead21
chore(deps): bump github/codeql-action from 2 to 3
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 2 to 3.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/v2...v3)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-12-13 15:52:54 +00:00
MDLeom 7809098034
ci: node 20
active lts
2023-12-12 08:33:33 +00:00
MDLeom dffeb0cfc7
test: node 21 2023-12-12 08:30:27 +00:00
dependabot[bot] bfcd93edb7
chore(deps): bump actions/setup-node from 3 to 4
Bumps [actions/setup-node](https://github.com/actions/setup-node) from 3 to 4.
- [Release notes](https://github.com/actions/setup-node/releases)
- [Commits](https://github.com/actions/setup-node/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/setup-node
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-10-24 15:47:02 +00:00
Ming Di Leom 2992e8d8e7
Merge pull request #142 from curbengh/dependabot/github_actions/actions/checkout-4
chore(deps): bump actions/checkout from 3 to 4
2023-10-01 15:20:29 +10:30
dependabot[bot] cf7e8f675c
chore(deps): bump actions/checkout from 3 to 4
Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-10-01 04:48:01 +00:00
MDLeom 3523b0fd98
chore(node): drop Node 16
BREAKING CHANGE
Node 16 EOL 2023-09-11
2023-10-01 04:46:39 +00:00
Ming Di Leom df3b0513e7
Merge pull request #143 from curbengh/bun
feat(ci): run linux jobs using Bun
2023-10-01 15:09:17 +10:30
MDLeom dbed65ffeb
feat(ci): run linux jobs using Bun 2023-10-01 04:05:08 +00:00
Ming Di Leom c964cfcf80
Merge pull request #140 from curbengh/node-20
chore(node): require node 16+
2023-10-01 14:06:48 +10:30
MDLeom 793bcd81c4
chore(node): require node 16+
- node 14 EOL 2023-04-30
- add node 20
2023-05-06 06:04:21 +00:00
MDLeom f65e7e7a22
docs: remove deprecated lgtm badge 2023-04-28 08:53:38 +00:00
MDLeom d9e6228960
docs: fix build badge
https://github.com/badges/shields/issues/8671
2023-03-06 09:33:04 +00:00
Ming Di Leom 6c6060f28c
Merge pull request #139 from curbengh/8.0
release: 8.0.0
2022-11-13 11:08:42 +10:30
MDLeom 79f4f24f8e
release: 8.0.0 2022-11-13 00:05:34 +00:00
Ming Di Leom b0575e6fdc
Merge pull request #135 from curbengh/dependabot/npm_and_yarn/svgo-3.0.0
chore(deps): bump svgo from 2.8.0 to 3.0.0
2022-11-06 15:55:40 +10:30
MDLeom a6f434ff8d
fix(svg): ignore empty input 2022-11-06 04:50:36 +00:00
MDLeom a6e2ea0879
fix(svg): svgo@3 now throws error
- cleanupIDs -> cleanupIds
- https://github.com/svg/svgo/releases/tag/v3.0.0
2022-11-06 02:58:07 +00:00
dependabot[bot] 9c8a228e09
chore(deps): bump svgo from 2.8.0 to 3.0.0
Bumps [svgo](https://github.com/svg/svgo) from 2.8.0 to 3.0.0.
- [Release notes](https://github.com/svg/svgo/releases)
- [Changelog](https://github.com/svg/svgo/blob/main/CHANGELOG-old.md)
- [Commits](https://github.com/svg/svgo/compare/v2.8.0...v3.0.0)

---
updated-dependencies:
- dependency-name: svgo
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-11-06 02:58:07 +00:00
Ming Di Leom 4b4d3cb342
Merge pull request #137 from curbengh/node-19
ci(tester): add node 19
2022-11-06 13:26:09 +10:30
MDLeom 8258359f6b
ci(tester): add node 19 2022-11-05 02:02:16 +00:00
Ming Di Leom c6c7d3743a
Merge pull request #134 from curbengh/deps
chore(ga-deps): use latest minor version
2022-10-09 19:53:39 +10:30
MDLeom 777ffabd2b
ci: run snyk & semgrep weekly 2022-10-09 08:00:56 +00:00
MDLeom 5453fc9ee0
chore(deps-dev): bump jest from 28.1.3 to 29.1.2 2022-10-09 07:59:47 +00:00
MDLeom c3b899556a
chore(ga-deps): use latest minor version 2022-10-09 07:58:57 +00:00
Ming Di Leom 866ba28c3c
Merge pull request #133 from curbengh/semgrep-init
ci: semgrep init
2022-10-09 18:09:46 +10:30
MDLeom b54324c154
ci: semgrep init 2022-10-09 07:32:00 +00:00
MDLeom 077055ed0b
release: 7.0.0 2022-05-17 00:59:09 +00:00
MDLeom d54ed360be
chore(node): use Node 16 on codeql 2022-05-17 00:40:28 +00:00
MDLeom 1ae4d77071
chore(dev-deps): bump setup-node from 3.1.1 to 3.2.0 2022-05-17 00:37:59 +00:00
MDLeom 0f73e6ed98
chore(dev-deps): bump codeql-action from 1 to 2 2022-05-17 00:36:57 +00:00
MDLeom 79f15acb79
ci(snyk): run snyk on codeql bump 2022-05-17 00:35:52 +00:00
MDLeom 2ae5520a60
ci(snyk): separate test & monitor 2022-05-13 01:27:05 +00:00
MDLeom ef46c3c6d9
ci(synk): run test & upload to codeql 2022-05-13 01:00:45 +00:00
MDLeom 4648fa32f1
chore(snyk): remove old policy 2022-05-13 00:50:47 +00:00
MDLeom 197836b82b
docs: cleanup previous config changes
- update brotli support status
2022-05-06 06:21:15 +00:00
Ming Di Leom d757c1b5c7
Merge pull request #110 from curbengh/update-deps
chore(node): drop Node 12 & 17, add 18
2022-05-05 14:24:05 +09:30
MDLeom 0623de5252
chore(node): drop Node 12 & 17, add 18
BREAKING CHANGE
2022-05-04 03:17:49 +00:00
MDLeom fbb2c71e87
chore(actions): bump codecov-action from 2.1.0 to 3.1.0 2022-05-04 02:38:28 +00:00
MDLeom b3d09fec7a
chore(actions): bump setup-node from 2.4.1 to 3.1.1 2022-05-04 02:36:40 +00:00
MDLeom 3edbe68008
chore(actions): bump cache from 2.1.6 to 3.0.2 2022-05-04 02:35:32 +00:00
MDLeom 1833ffa76e
chore(actions): bump checkout from 2.3.4 to 3.0.2 2022-05-04 02:35:02 +00:00
MDLeom 63eee78e01
chore(dev-deps): bump standard from 16 to 17 2022-05-04 02:29:34 +00:00
MDLeom 7e81770894
chore(dev-deps): bump jest from 27 to 28 2022-05-04 02:28:59 +00:00
MDLeom 288a4e3232
chore(dev-deps): bump hexo from 5.1.1 to 6.1.0 2022-05-04 02:28:14 +00:00
15 changed files with 587 additions and 226 deletions

View File

@ -6,19 +6,17 @@ jobs:
linter:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.3.4
- name: Use Node.js 14.x
uses: actions/setup-node@v2.4.1
with:
node-version: '14.x'
- uses: actions/checkout@v4
- name: Install Bun
uses: oven-sh/setup-bun@v1
- name: Cache NPM dependencies
uses: actions/cache@v2.1.6
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-npm-cache
restore-keys: |
${{ runner.os }}-npm-cache
- name: Install Dependencies
run: npm install
run: bun install
- name: Lint
run: npm run lint
run: bun run lint

23
.github/workflows/semgrep.yml vendored Normal file
View File

@ -0,0 +1,23 @@
name: Semgrep
on:
pull_request: {}
push:
branches:
- master
paths:
- .github/workflows/semgrep.yml
schedule:
# Weekly
- cron: "0 0 * * 0"
jobs:
semgrep:
name: Scan
runs-on: ubuntu-latest
env:
SEMGREP_APP_TOKEN: ${{ secrets.SEMGREP_APP_TOKEN }}
container:
image: returntocorp/semgrep
if: (github.actor != 'dependabot[bot]')
steps:
- uses: actions/checkout@v4
- run: semgrep ci

View File

@ -2,21 +2,34 @@ name: Snyk
on:
schedule:
# Every day
- cron: '0 0 * * *'
# Weekly
- cron: "0 0 * * 0"
pull_request:
branches:
- "dependabot/github_actions/github/codeql-action**"
jobs:
security:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.3.4
- name: Use Node.js 14.x
uses: actions/setup-node@v2.4.1
with:
node-version: '14.x'
- uses: actions/checkout@v4
- name: Install Bun
uses: oven-sh/setup-bun@v1
- name: Install Dependencies
run: npm install
run: bun install
- name: Run Snyk to check for vulnerabilities
uses: snyk/actions/node@master
continue-on-error: true # To make sure that SARIF upload gets called
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
command: test
args: --sarif-file-output=snyk.sarif
- name: Upload result to GitHub Code Scanning
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: snyk.sarif
- name: Monitor for vulnerabilities
uses: snyk/actions/node@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}

View File

@ -8,22 +8,36 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version: ['12', '14', '16', '17']
node-version: ["18", "20", "22"]
fail-fast: false
steps:
- uses: actions/checkout@v2.3.4
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2.4.1
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Cache NPM dependencies
uses: actions/cache@v2.1.6
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-npm-cache
restore-keys: ${{ runner.os }}-npm-cache
- name: Install Dependencies
run: npm install
- name: Determine zstd binary version
shell: bash
run: |
case "$RUNNER_OS" in
"Linux")
echo "PLATFORM=linux-x64-gnu" >> "$GITHUB_ENV" ;;
"Windows")
echo "PLATFORM=win32-x64-msvc" >> "$GITHUB_ENV" ;;
"macOS")
echo "PLATFORM=darwin-arm64" >> "$GITHUB_ENV" ;;
esac
- name: Install zstd binary
shell: bash
run: npm install "@mongodb-js/zstd-$PLATFORM"
- name: Test
run: npm run test
env:
@ -33,26 +47,30 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
node-version: ['14.x']
node-version: ["20.x"]
steps:
- uses: actions/checkout@v2.3.4
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2.4.1
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Install Bun
uses: oven-sh/setup-bun@v1
- name: Cache NPM dependencies
uses: actions/cache@v2.1.6
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-npm-cache
restore-keys: ${{ runner.os }}-npm-cache
- name: Install Dependencies
run: npm install
run: bun install
- name: Coverage
run: npm run test
env:
CI: true
- name: Upload coverage report to Codecov
uses: codecov/codecov-action@v2.1.0
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: true
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

1
.gitignore vendored
View File

@ -4,3 +4,4 @@ package-lock.json
tmp/
*.log
coverage/
bun.lockb

6
.snyk
View File

@ -2,8 +2,4 @@
version: v1.12.0
# ignores vulnerabilities until expiry date; change duration by modifying expiry date
ignore:
SNYK-JS-LODASH-450202:
- '*':
reason: Patch/update unavailable. Introduced through Snyk.
expires: '2019-12-31T00:00:00.000Z'
patch: {}
patch:

View File

@ -1,6 +1,6 @@
The MIT License (MIT)
Copyright (c) 2018-2019 curbengh, 2016-2018 rozbo
Copyright (c) 2018-2024 curbengh, 2016-2018 rozbo
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

277
README.md
View File

@ -1,68 +1,40 @@
# hexo-yam
[![npm version](https://img.shields.io/npm/v/hexo-yam?logo=npm)](https://www.npmjs.com/package/hexo-yam)
[![Build Status](https://img.shields.io/github/workflow/status/curbengh/hexo-yam/Tester?logo=github)](https://github.com/curbengh/hexo-yam/actions?query=workflow%3ATester)
[![Build Status](https://img.shields.io/github/actions/workflow/status/curbengh/hexo-yam/tester.yml?branch=master&logo=github)](https://github.com/curbengh/hexo-yam/actions?query=workflow%3ATester)
[![codecov](https://img.shields.io/codecov/c/gh/curbengh/hexo-yam?logo=codecov)](https://codecov.io/gh/curbengh/hexo-yam)
[![NPM Dependencies](https://img.shields.io/librariesio/release/npm/hexo-yam)](https://libraries.io/npm/hexo-yam)
[![Known Vulnerabilities](https://img.shields.io/snyk/vulnerabilities/npm/hexo-yam?logo=snyk)](https://snyk.io/test/npm/hexo-yam)
[![Total alerts](https://img.shields.io/lgtm/alerts/g/curbengh/hexo-yam.svg?logo=lgtm)](https://lgtm.com/projects/g/curbengh/hexo-yam/alerts/)
[![Language grade: JavaScript](https://img.shields.io/lgtm/grade/javascript/g/curbengh/hexo-yam.svg?logo=lgtm)](https://lgtm.com/projects/g/curbengh/hexo-yam/context:javascript)
Yet Another Minifier for Hexo. Minify and compress HTML, JS, CSS, SVG, XML and JSON. [Other files](https://github.com/curbengh/hexo-yam/blob/ba77db0094a7c07ea9f70f010bfc15541d4105ca/index.js#L64) are also compressed. Support gzip and [brotli](https://en.wikipedia.org/wiki/Brotli) [compressions](https://en.wikipedia.org/wiki/HTTP_compression).
[![Known Vulnerabilities](https://snyk.io/test/github/curbengh/hexo-yam/badge.svg)](https://snyk.io/test/github/curbengh/hexo-yam)
Yet Another Minifier for Hexo. Minify HTML, JS, CSS, SVG, XML and JSON. Compress static [web assets](https://github.com/curbengh/hexo-yam/blob/ba77db0094a7c07ea9f70f010bfc15541d4105ca/index.js#L64) using gzip, brotli and zstd.
## Table of contents
- [Version 5](#version-5)
- [Installation](#installation)
- [Options](#options)
- [HTML](#html)
- [CSS](#css)
- [JS](#js)
- [SVG](#svg)
- [Gzip](#gzip)
- [Brotli](#brotli)
- [XML](#xml)
- [JSON](#json)
- [Gzip](#gzip)
- [Brotli](#brotli)
- [Zstd](#zstd)
- [Globbing](#globbing)
- [HTTP Compression](#http-compression)
## Version 6
In v6, `svg.plugins:` option should be the following syntax:
``` diff
minify:
svg:
plugins:
# v6
+ removeComments: false
+ cleanupIDs: false
+ builtinPluginName:
+ optionName: 'optionValue'
# v5
- - name: 'removeComments'
- active: false
- - name: 'cleanupIDs'
- active: false
# v4
- - removeComments: false
- - cleanupIDs: false
```
The option only overrides svgo's default plugins, other options are not supported.
## Installation
``` bash
$ npm install hexo-yam --save
```bash
$ npm install --save hexo-yam
```
## Options
``` yaml
```yaml
minify:
enable: true
previewServer: true
html:
css:
js:
@ -74,6 +46,7 @@ minify:
```
- **enable** - Enable the plugin. Defaults to `true`.
- **previewServer** - Disable the plugin when running `hexo server`. Defaults to `true`.
- **html** - See [HTML](#html) section
- **css** - See [CSS](#css) section
- **js** - See [JS](#js) section
@ -85,12 +58,13 @@ minify:
## HTML
``` yaml
```yaml
minify:
html:
enable: true
exclude:
```
- **enable** - Enable the plugin. Defaults to `true`.
- **priority** - Plugin's priority. Defaults to `10`. Set lower value to set higher priority and vice versa.
- **verbose** - Verbose output. Defaults to `false`.
@ -101,13 +75,14 @@ For more options, see [HTMLMinifier](https://github.com/kangax/html-minifier).
## CSS
``` yaml
```yaml
minify:
css:
enable: true
exclude:
- '*.min.css'
- "*.min.css"
```
- **enable** - Enable the plugin. Defaults to `true`.
- **priority** - Plugin's priority. Defaults to `10`.
- **verbose** - Verbose output. Defaults to `false`.
@ -119,13 +94,14 @@ For more options, see [clean-css](https://github.com/jakubpawlowicz/clean-css).
## JS
``` yaml
```yaml
minify:
js:
enable: true
exclude:
- '*.min.js'
- "*.min.js"
```
- **enable** - Enable the plugin. Defaults to `true`.
- **priority** - Plugin's priority. Defaults to `10`.
- **verbose** - Verbose output. Defaults to `false`.
@ -140,14 +116,15 @@ For more options, see [Terser](https://github.com/terser-js/terser).
## SVG
``` yaml
```yaml
minify:
svg:
enable: true
include:
- '*.svg'
- '!*.min.svg'
- "*.svg"
- "!*.min.svg"
```
- **enable** - Enable the plugin. Defaults to `true`.
- **priority** - Plugin's priority. Defaults to `10`.
- **verbose** - Verbose output. Defaults to `false`.
@ -155,82 +132,29 @@ minify:
- Exclude `*.min.svg` by default.
- **plugins** - Plugin options.
- Examples:
``` yaml
```yaml
plugins:
# Retain comments
removeComments: false
# Do not remove unused ID attributes
cleanupIDs: false
cleanupIds: false
```
- For more options, see [svgo](https://github.com/svg/svgo).
- **globOptions** - See [globbing](#globbing) section.
## Gzip
``` yaml
minify:
gzip:
enable: true
include:
- '*.html'
- '*.css'
- '*.js'
- '*.txt'
- '*.ttf'
- '*.atom'
- '*.stl'
- '*.xml'
- '*.svg'
- '*.eot'
- '*.json'
```
- **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.
- Support one-liner, `include: ['*.html','*.css','*.js']`.
- Must include asterisk and single quotes. `.html` is invalid. `'*.html'` is valid.
- **globOptions** - See [globbing](#globbing) section.
- **level** - Compression level; lower value may results in faster compression but slightly larger (compressed) file. Range `1-9`. Defaults to `9`, or the value of [`zlib.constants.Z_BEST_COMPRESSION`](https://nodejs.org/docs/latest-v12.x/api/zlib.html#zlib_zlib_constants)
## Brotli
``` yaml
minify:
brotli:
enable: true
include:
- '*.html'
- '*.css'
- '*.js'
- '*.txt'
- '*.ttf'
- '*.atom'
- '*.stl'
- '*.xml'
- '*.svg'
- '*.eot'
- '*.json'
```
- **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-11`. Defaults to `11`, or the value of [`zlib.constants.BROTLI_MAX_QUALITY`](https://nodejs.org/docs/latest-v12.x/api/zlib.html#zlib_brotli_constants)
## XML
Remove whitespaces in xml.
``` yaml
```yaml
minify:
xml:
enable: false
include:
- '*.xml'
- '!*.min.xml'
- "*.xml"
- "!*.min.xml"
```
- **enable** - Enable the plugin. Defaults to `false`.
- **priority** - Plugin's priority. Defaults to `10`.
- **verbose** - Verbose output. Defaults to `false`.
@ -245,14 +169,15 @@ For more options, see [minify-xml](https://github.com/kristian/minify-xml#option
Remove whitespaces in json.
``` yaml
```yaml
minify:
json:
enable: false
include:
- '*.json'
- '!*.min.json'
- "*.json"
- "!*.min.json"
```
- **enable** - Enable the plugin. Defaults to `false`.
- **priority** - Plugin's priority. Defaults to `10`.
- **verbose** - Verbose output. Defaults to `false`.
@ -260,6 +185,101 @@ minify:
- Exclude `*.min.json` by default.
- **globOptions** - See [globbing](#globbing) section.
## Gzip
```yaml
minify:
gzip:
enable: true
include:
- "*.html"
- "*.css"
- "*.js"
- "*.txt"
- "*.ttf"
- "*.atom"
- "*.stl"
- "*.xml"
- "*.svg"
- "*.eot"
- "*.json"
```
- **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.
- Support one-liner, `include: ['*.html','*.css','*.js']`.
- Must include asterisk and single quotes. `.html` is invalid. `'*.html'` is valid.
- **globOptions** - See [globbing](#globbing) section.
- **level** - Compression level; lower value may results in faster compression but slightly larger (compressed) file. Range `1-9`. Defaults to `9`, or the value of [`zlib.constants.Z_BEST_COMPRESSION`](https://nodejs.org/docs/latest-v12.x/api/zlib.html#zlib_zlib_constants)
## Brotli
```yaml
minify:
brotli:
enable: true
include:
- "*.html"
- "*.css"
- "*.js"
- "*.txt"
- "*.ttf"
- "*.atom"
- "*.stl"
- "*.xml"
- "*.svg"
- "*.eot"
- "*.json"
```
- **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-11`. Defaults to `11`, or the value of [`zlib.constants.BROTLI_MAX_QUALITY`](https://nodejs.org/docs/latest-v12.x/api/zlib.html#zlib_brotli_constants)
## Zstd
```yaml
minify:
zstd:
enable: false
include:
- "*.html"
- "*.css"
- "*.js"
- "*.txt"
- "*.ttf"
- "*.atom"
- "*.stl"
- "*.xml"
- "*.svg"
- "*.eot"
- "*.json"
```
- **enable** - Enable the plugin. Defaults to `false`.
- **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)
### Cannot find module '@mongodb-js/zstd-linux-x64-gnu'
`npm install --save @mongodb-js/zstd-linux-x64-gnu`
- @mongodb-js/zstd-darwin-arm64 (Apple Silicon)
- @mongodb-js/zstd-darwin-x64 (Intel Mac)
- @mongodb-js/zstd-linux-arm64-gnu
- @mongodb-js/zstd-linux-arm64-musl (Alpine)
- @mongodb-js/zstd-linux-x64-gnu
- @mongodb-js/zstd-linux-x64-musl (Alpine)
- @mongodb-js/zstd-win32-x64-msvc
## Globbing
Use "globOptions" to customise how glob patterns match files. Refer to [micromatch](https://github.com/micromatch/micromatch#options) for available options.
@ -268,51 +288,32 @@ Use "globOptions" to customise how glob patterns match files. Refer to [micromat
- basename is disabled depending on each pattern.
- This means the following options would work,
``` yml
```yml
exclude:
- '*foo.html' # basename is enabled
- '**/bar/*/*.html' # basename is automatically disabled
- '*baz.css' # basename is enabled
- "*foo.html" # basename is enabled
- "**/bar/*/*.html" # basename is automatically disabled
- "*baz.css" # basename is enabled
globOptions:
basename: true # default
```
- This behaviour doesn't apply to pattern that starts with `!` (negation).
- This limitation only applies to `include:` option used in svg, gzip and brotli.
- This means the following options would *not* work,
- This means the following options would _not_ work,
``` yml
```yml
include:
- '!foo.svg'
- '!**/bar/*/*.svg'
- "!foo.svg"
- "!**/bar/*/*.svg"
globOptions:
basename: true
```
- basename will stay disabled, if explicitly disabled in "globOptions".
## HTTP Compression
While most modern web browsers [support Brotli](https://www.caniuse.com/#feat=brotli), you also need to consider whether the web/app server, hosting platform, reverse proxy or CDN (whichever relevant to you) support it.
As of Sep 2020, GitHub Pages and GitLab Pages *do not* support brotli yet. You can generate `.br` files, but they won't serve those files.
Name | Brotli support
--- | ---
GitHub Pages | [In consideration](https://github.community/t5/GitHub-Pages/Support-for-pre-compressed-assets-and-brotli-compression/m-p/22055)
GitLab Pages | Yes
Netlify | Yes
Hexo Server | [In progress](https://github.com/hexojs/hexo-server/pull/100)
If you have access to the web server config, you should disable on-the-fly compression for static files (that are already compressed by this plugin),
- [nginx](https://github.com/google/ngx_brotli): Make sure both filter and static modules are enabled. This way pre-compressed `.br` files will be served while dynamic content can be compressed on-the-fly. Protip: `brotli_types text/plain text/css application/javascript application/json image/svg+xml application/xml+rss;` to prevent compressing media files (which are already compressed anyway).
- [Apache](https://httpd.apache.org/docs/2.4/en/mod/mod_brotli.html): See 'Serving pre-compressed content' section of [mod_brotli](https://httpd.apache.org/docs/2.4/en/mod/mod_brotli.html).
- [Caddy](https://caddyserver.com/features): [0.9.4+](https://caddyserver.com/blog/caddy-0_9_4-released) by default support pre-compressed `.gz` `.br` files and on-the-fly gzip compress dynamic files. v2 requires [manual configuration](https://mdleom.com/blog/2020/11/12/caddy2-pre-compressed/), serving them automatically to be supported [in future](https://github.com/caddyserver/caddy/issues/2665).
- [express](https://github.com/expressjs/express)/[connect](https://github.com/senchalabs/connect): Use [pre-compressed-assets](https://github.com/domadams/pre-compressed-assets). You still can continue to use [compression](https://github.com/expressjs/compression)/[shrink-ray-current](https://github.com/Alorel/shrink-ray) for dynamic files.
## Credits
All credits go to the following work:
- [hexo-neat](https://github.com/rozbo/hexo-neat) by rozbo
- gzip feature is inspired by [hexo-generator-optimize](https://github.com/JackyRen/hexo-generator-optimize)

5
bunfig.toml Normal file
View File

@ -0,0 +1,5 @@
[install]
optional = false
[install.lockfile]
save = false

View File

@ -2,7 +2,8 @@
'use strict'
hexo.config.minify = Object.assign({
enable: true
enable: true,
previewServer: true
}, hexo.config.minify)
hexo.config.minify.html = Object.assign({
@ -68,6 +69,14 @@ hexo.config.minify.brotli = Object.assign({
globOptions: { basename: true }
}, hexo.config.minify.brotli)
hexo.config.minify.zstd = Object.assign({
enable: false,
priority: 10,
verbose: false,
include: ['*.html', '*.css', '*.js', '*.txt', '*.ttf', '*.atom', '*.stl', '*.xml', '*.svg', '*.eot', '*.json'],
globOptions: { basename: true }
}, hexo.config.minify.zstd)
hexo.config.minify.xml = Object.assign({
enable: false,
priority: 10,
@ -85,7 +94,7 @@ hexo.config.minify.json = Object.assign({
globOptions: { basename: true }
}, hexo.config.minify.json)
if (hexo.config.minify.enable === true) {
if (hexo.config.minify.enable === true && !(hexo.config.minify.previewServer === true && ['s', 'server'].includes(hexo.env.cmd))) {
const filter = require('./lib/filter')
hexo.extend.filter.register('after_render:html', filter.minifyHtml, hexo.config.minify.html.priority)
hexo.extend.filter.register('after_render:css', filter.minifyCss, hexo.config.minify.css.priority)
@ -93,6 +102,7 @@ if (hexo.config.minify.enable === true) {
hexo.extend.filter.register('after_generate', filter.minifySvg, hexo.config.minify.svg.priority)
hexo.extend.filter.register('after_generate', filter.gzipFn, hexo.config.minify.gzip.priority)
hexo.extend.filter.register('after_generate', filter.brotliFn, hexo.config.minify.brotli.priority)
hexo.extend.filter.register('after_generate', filter.zstdFn, hexo.config.minify.zstd.priority)
hexo.extend.filter.register('after_generate', filter.minifyXml, hexo.config.minify.xml.priority)
hexo.extend.filter.register('after_generate', filter.minifyJson, hexo.config.minify.json.priority)
}

View File

@ -1,6 +1,6 @@
'use strict'
const { minify: htmlMinify } = require('html-minifier')
const { minify: htmlMinify } = require('html-minifier-terser')
const CleanCSS = require('clean-css')
const { minify: terserMinify } = require('terser')
const { optimize: svgOptimize } = require('svgo')
@ -10,6 +10,7 @@ const gzip = promisify(zlib.gzip)
const br = promisify(zlib.brotliCompress)
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) {
@ -59,7 +60,7 @@ function logFn (original, minified, path, ext) {
log.log(`${ext}: ${path} [${saved}% saved]`)
}
function minifyHtml (str, data) {
async function minifyHtml (str, data) {
const hexo = this
const options = hexo.config.minify.html
if (options.enable === false || !str) return
@ -71,7 +72,7 @@ function minifyHtml (str, data) {
if (isMatch(path, exclude, globOptions)) return str
try {
const result = htmlMinify(str, options)
const result = await htmlMinify(str, options)
if (verbose) logFn.call(this, str, result, path, 'html')
return result
@ -152,12 +153,12 @@ function minifySvg () {
assetPath.on('data', (chunk) => (assetTxt += chunk))
assetPath.on('end', async () => {
if (assetTxt.length) {
const { data, error } = svgOptimize(assetTxt, { ...options, plugins })
if (data) {
try {
const { data } = svgOptimize(assetTxt, { ...options, plugins })
if (verbose) logFn.call(this, assetTxt, data, path, 'svg')
resolve(route.set(path, data))
} else if (error) {
reject(new Error(`Path: ${path}\n${error}`))
} catch (err) {
reject(new Error(`Path: ${path}\n${err}`))
}
}
resolve()
@ -230,6 +231,39 @@ function brotliFn () {
}))
}
function zstdFn () {
const hexo = this
const options = hexo.config.minify.zstd
if (options.enable === false) return
const { route } = hexo
const routeList = route.list()
const { globOptions, include, verbose } = options
let { level } = options
if (typeof level !== 'number') level = undefined
return Promise.all((match(routeList, include, globOptions)).map((path) => {
return new Promise((resolve, reject) => {
const assetPath = route.get(path)
let assetTxt = ''
assetPath.on('data', (chunk) => (assetTxt += chunk))
assetPath.on('end', async () => {
if (assetTxt.length) {
try {
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))
} catch (err) {
reject(new Error(`Path: ${path}\n${err}`))
}
}
resolve()
})
})
}))
}
function minifyXml () {
const hexo = this
const options = hexo.config.minify.xml
@ -297,6 +331,7 @@ module.exports = {
minifySvg,
gzipFn,
brotliFn,
zstdFn,
minifyXml,
minifyJson
}

View File

@ -1,7 +1,7 @@
{
"name": "hexo-yam",
"description": "Yet Another Minifier. Minify and compress html, js, css, svg, xml and json",
"version": "6.0.0",
"version": "9.0.0",
"readme": "README.md",
"main": "index.js",
"directories": {
@ -16,36 +16,35 @@
"test": "jest"
},
"engines": {
"node": ">= 12.13.0"
"node": ">= 18.12.0"
},
"author": "curben",
"license": "MIT",
"homepage": "https://github.com/curbengh/hexo-yam",
"repository": "curbengh/hexo-yam",
"repository": {
"type": "git",
"url": "git+https://github.com/curbengh/hexo-yam.git"
},
"dependencies": {
"clean-css": "^5.1.2",
"html-minifier": "^4.0.0",
"html-minifier-terser": "^7.2.0",
"micromatch": "^4.0.2",
"minify-xml": "^3.2.0",
"svgo": "^2.4.0",
"terser": "^5.3.0"
"svgo": "^3.0.0",
"terser": "^5.3.0",
"@mongodb-js/zstd": "^1.2.0"
},
"devDependencies": {
"hexo": "^5.1.1",
"jest": "^27.2.5",
"standard": "^16.0.1"
"hexo": "^7.1.0",
"jest": "^29.1.2",
"standard": "^17.0.0"
},
"keywords": [
"html",
"js",
"css",
"svg",
"xml",
"json",
"minify",
"compress",
"gzip",
"brotli",
"zstd",
"hexo-yam",
"hexo"
],

View File

@ -2,7 +2,7 @@
'use strict'
const Hexo = require('hexo')
const { minify: htmlMinify } = require('html-minifier')
const { minify: htmlMinify } = require('html-minifier-terser')
describe('html', () => {
const hexo = new Hexo(__dirname)
@ -26,105 +26,107 @@ describe('html', () => {
globOptions: { basename: true }
}
}
const expected = htmlMinify(input, defaultCfg.html)
let expected = ''
beforeAll(async () => {
expected = await htmlMinify(input, defaultCfg.html)
})
beforeEach(() => {
hexo.config.minify = JSON.parse(JSON.stringify(defaultCfg))
})
test('default', () => {
const result = h(input, { path })
test('default', async () => {
const result = await h(input, { path })
expect(result).toBe(expected)
})
test('disable', () => {
test('disable', async () => {
hexo.config.minify.html.enable = false
const result = h(input, { path })
const result = await h(input, { path })
expect(result).toBeUndefined()
})
test('empty file', () => {
const result = h('', { path })
test('empty file', async () => {
const result = await h('', { path })
expect(result).toBeUndefined()
})
test('option', () => {
test('option', async () => {
const customOpt = { removeEmptyAttributes: false }
hexo.config.minify.html = customOpt
const result = h(input, { path })
const expected = htmlMinify(input, customOpt)
const result = await h(input, { path })
const expected = await htmlMinify(input, customOpt)
expect(result).toBe(input)
expect(result).toBe(expected)
})
test('option - verbose', () => {
test('option - verbose', async () => {
hexo.config.minify.html.verbose = true
hexo.log.log = jest.fn()
h(input, { path })
await h(input, { path })
expect(hexo.log.log.mock.calls[0][0]).toContain(`html: ${path}`)
})
test('exclude', () => {
test('exclude', async () => {
const exclude = '*.min.html'
hexo.config.minify.html.exclude = exclude
const result = h(input, { path: 'foo/bar.min.html' })
const result = await h(input, { path: 'foo/bar.min.html' })
expect(result).toBe(input)
})
test('exclude - slash in pattern', () => {
test('exclude - slash in pattern', async () => {
const exclude = '**/lectus/**/*.html'
hexo.config.minify.html.exclude = exclude
const result = h(input, { path: 'eleifend/lectus/nullam/dapibus/netus.html' })
const result = await h(input, { path: 'eleifend/lectus/nullam/dapibus/netus.html' })
expect(result).toBe(input)
})
test('exclude - basename is true + slash', () => {
test('exclude - basename is true + slash', async () => {
const exclude = ['**/lectus/**/*.html', 'bar.html']
const globOptions = { basename: true }
hexo.config.minify.html.exclude = exclude
hexo.config.minify.html.globOptions = globOptions
const result = h(input, { path: 'foo/bar.html' })
const result = await h(input, { path: 'foo/bar.html' })
expect(result).toBe(input)
})
test('exclude - basename is false + slash', () => {
test('exclude - basename is false + slash', async () => {
const exclude = ['**/lectus/**/*.html', 'bar.html']
const globOptions = { basename: false }
hexo.config.minify.html.exclude = exclude
hexo.config.minify.html.globOptions = globOptions
const result = h(input, { path: 'foo/bar.html' })
const result = await h(input, { path: 'foo/bar.html' })
expect(result).toBe(expected)
})
test('null', () => {
test('null', async () => {
hexo.config.minify.html.exclude = null
hexo.config.minify.html.globOptions = null
const result = h(input, { path: null })
const result = await h(input, { path: null })
expect(result).toBe(expected)
})
test('invalid string', () => {
test('invalid string', async () => {
const invalid = '<html><>?:"{}|_+</html>'
expect(() => {
h(invalid, { path })
}).toThrow(`Path: ${path}\nError: Parse Error`)
await expect(h(invalid, { path })).rejects.toThrow('Parse Error: <>?:"{}|_+</html>')
})
})

View File

@ -71,7 +71,7 @@ describe('svg', () => {
test('option', async () => {
const customOpt = {
cleanupIDs: false
cleanupIds: false
}
hexo.config.minify.svg.plugins = customOpt
plugins = [{
@ -117,10 +117,14 @@ describe('svg', () => {
const input = '{}'
hexo.route.set(path, input)
const { error } = svgOptimize(input, { plugins })
expect(error).toBeDefined()
await expect(s()).rejects.toThrow(`Path: ${path}\n${error}`)
let expected
try {
svgOptimize(input, { plugins })
} catch (err) {
expected = err
}
expect(expected).toBeDefined()
await expect(s()).rejects.toThrow(`Path: ${path}\n${expected}`)
})
test('include - exclude *.min.svg by default', async () => {

256
test/zstd.test.js Normal file
View File

@ -0,0 +1,256 @@
/* eslint-env jest */
'use strict'
const Hexo = require('hexo')
const { compress: zstd, decompress: unzstd } = require('@mongodb-js/zstd')
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 = {
zstd: {
enable: true,
verbose: false,
include: ['*.html', '*.css', '*.js', '*.txt', '*.ttf', '*.atom', '*.stl', '*.xml', '*.svg', '*.eot', '*.json'],
globOptions: { basename: true }
}
}
hexo.route.set(path, input)
})
afterEach(() => {
const routeList = hexo.route.list()
routeList.forEach((path) => hexo.route.remove(path))
})
test('default', async () => {
await z()
const output = hexo.route.get(path.concat('.zst'))
const buf = []
output.on('data', (chunk) => (buf.push(chunk)))
output.on('end', async () => {
const result = Buffer.concat(buf)
const expected = await zstd(inputBuf)
const resultUnzst = await unzstd(result)
const expectedUnzst = await unzstd(expected)
expect(result.equals(expected)).toBe(true)
expect(resultUnzst.toString()).toBe(input)
expect(expectedUnzst.toString()).toBe(input)
})
})
test('disable', async () => {
hexo.config.minify.zstd.enable = false
const result = await z()
expect(result).toBeUndefined()
})
test('empty file', async () => {
hexo.route.set(path, '')
const routeList = hexo.route.list()
expect(routeList).not.toContain(path.concat('.zst'))
const result = await z()
expect(result).toBeDefined()
expect(result[0]).toBeUndefined()
})
test('option', async () => {
const level = 1
hexo.config.minify.zstd.level = level
await z()
const output = hexo.route.get(path.concat('.zst'))
const buf = []
output.on('data', (chunk) => (buf.push(chunk)))
output.on('end', async () => {
const result = Buffer.concat(buf)
const expected = await zstd(inputBuf, level)
expect(result.equals(expected)).toBe(true)
})
})
test('option - verbose', async () => {
hexo.config.minify.zstd.verbose = true
hexo.log.log = jest.fn()
await z()
expect(hexo.log.log.mock.calls[0][0]).toContain(`zstd: ${path}`)
})
test('option - level is string', async () => {
const level = 'foo'
hexo.config.minify.zstd.level = level
await z()
const output = hexo.route.get(path.concat('.zst'))
const buf = []
output.on('data', (chunk) => (buf.push(chunk)))
output.on('end', async () => {
const result = Buffer.concat(buf)
const expected = await zstd(inputBuf, undefined)
expect(result.equals(expected)).toBe(true)
})
})
test('include - exclude non-text file by default', async () => {
const path = 'foo.jpg'
hexo.route.set(path, input)
await z()
const result = hexo.route.get(path.concat('.zst'))
expect(result).toBeUndefined()
})
test('include - basename', async () => {
hexo.config.minify.zstd.include = 'bar.txt'
const path = 'foo/bar.txt'
hexo.route.set(path, input)
await z()
const result = hexo.route.get(path.concat('.zst'))
expect(result).toBeDefined()
})
test('include - slash in pattern', async () => {
hexo.config.minify.zstd.include = '**/lectus/**/*.txt'
const path = 'eleifend/lectus/nullam/dapibus/netus.txt'
hexo.route.set(path, input)
await z()
const result = hexo.route.get(path.concat('.zst'))
expect(result).toBeDefined()
})
test('include - basename + slash + basename enabled', async () => {
hexo.route.remove(path)
const paths = [
'lorem/ipsum/dolor.html',
'gravida/sociis/erat/ante.css',
'aptent/elementum.js',
'felis/blandit/cursus.svg'
]
hexo.config.minify.zstd.include = [
'*.html',
'**/sociis/**/*.css'
]
paths.forEach((inpath) => {
hexo.route.set(inpath, input)
})
await z()
const routeList = hexo.route.list()
const expected = [
'lorem/ipsum/dolor.html.zst',
'gravida/sociis/erat/ante.css.zst'
]
const notExpected = [
'aptent/elementum.js.zst',
'felis/blandit/cursus.svg.zst'
]
expect(routeList).toEqual(expect.arrayContaining(expected))
expect(routeList).toEqual(expect.not.arrayContaining(notExpected))
})
test('include - basename + slash + basename disabled', async () => {
hexo.route.remove(path)
const paths = [
'lorem/ipsum/dolor.html',
'gravida/sociis/erat/ante.css',
'aptent/elementum.js',
'felis/blandit/cursus.svg'
]
hexo.config.minify.zstd.include = [
'*.html',
'**/sociis/**/*.css'
]
hexo.config.minify.zstd.globOptions = {
basename: false
}
paths.forEach((inpath) => {
hexo.route.set(inpath, input)
})
await z()
const routeList = hexo.route.list()
const expected = [
'gravida/sociis/erat/ante.css.zst'
]
const notExpected = [
'lorem/ipsum/dolor.html.zst',
'aptent/elementum.js.zst',
'felis/blandit/cursus.svg.zst'
]
expect(routeList).toEqual(expect.arrayContaining(expected))
expect(routeList).toEqual(expect.not.arrayContaining(notExpected))
})
test('include - reverse pattern + basename disabled', async () => {
hexo.route.remove(path)
const paths = [
'lorem/ipsum/dolor.html',
'gravida/sociis/erat/ante.css',
'aptent/elementum.js',
'felis/blandit/cursus.svg'
]
hexo.config.minify.zstd.include = [
'!dolor.html'
]
hexo.config.minify.zstd.globOptions = {
basename: false
}
paths.forEach((inpath) => {
hexo.route.set(inpath, input)
})
await z()
const routeList = hexo.route.list()
const expected = paths.map((path) => path.concat('.zst'))
expect(routeList).toEqual(expect.arrayContaining(expected))
})
test('blns', async () => {
const blns = require('./fixtures/blns.json')
for (const nStr of blns) {
hexo.route.remove(path)
hexo.route.set(path, nStr)
await z()
const output = hexo.route.get(path.concat('.zst'))
const buf = []
output.on('data', (chunk) => (buf.push(chunk)))
output.on('end', async () => {
const result = Buffer.concat(buf)
const resultUnzst = await unzstd(result)
expect(resultUnzst.toString()).toBe(nStr)
})
}
})
})