mirror of https://github.com/curbengh/hexo-yam
feat: allow custom file extension for compressions
This commit is contained in:
parent
02b323868a
commit
528486761d
30
README.md
30
README.md
|
@ -37,7 +37,7 @@ neat_html:
|
|||
- **enable** - Enable the plugin. Defaults to `true`.
|
||||
- **logger** - Verbose output. Defaults to `false`.
|
||||
- **exclude** - Exclude files. Support [wildcard](https://github.com/micromatch/nanomatch#features) glob pattern.
|
||||
- It can be specified as a one-liner, `[*.min.html, *.note.html]`.
|
||||
- Support one-liner, `exclude: [*.min.html, *.note.html]`.
|
||||
- To exclude a file, double asterisk and the full path must be specified, `**/themes/typing/source/js/source.js`.
|
||||
- `*source.js` also works, but it also excludes `resource.js`.
|
||||
- Test glob pattern on the web using [Globtester](http://www.globtester.com/).
|
||||
|
@ -81,18 +81,46 @@ For more options, see [Terser](https://github.com/terser-js/terser).
|
|||
``` yaml
|
||||
neat_gzip:
|
||||
enable: true
|
||||
include:
|
||||
- '*.html'
|
||||
- '*.css'
|
||||
- '*.js'
|
||||
- '*.txt'
|
||||
- '*.ttf'
|
||||
- '*.atom'
|
||||
- '*.stl'
|
||||
- '*.xml'
|
||||
- '*.svg'
|
||||
- '*.eot'
|
||||
- '*.json'
|
||||
```
|
||||
- **enable** - Enable the plugin. Defaults to `true`.
|
||||
- **logger** - Verbose output. Defaults to `false`.
|
||||
- **include** - Include files. Support wildcard pattern.
|
||||
- Support one-liner, `include: ['*.html','*.css','*.js']`.
|
||||
- Must include asterisk and single quotes. `.html` is invalid. `'*.html'` is valid.
|
||||
|
||||
----------
|
||||
|
||||
``` yaml
|
||||
neat_brotli:
|
||||
enable: true
|
||||
include:
|
||||
- '*.html'
|
||||
- '*.css'
|
||||
- '*.js'
|
||||
- '*.txt'
|
||||
- '*.ttf'
|
||||
- '*.atom'
|
||||
- '*.stl'
|
||||
- '*.xml'
|
||||
- '*.svg'
|
||||
- '*.eot'
|
||||
- '*.json'
|
||||
```
|
||||
- **enable** - Enable the plugin. Defaults to `true`.
|
||||
- **logger** - Verbose output. Defaults to `false`.
|
||||
- **include** - Include files. Support wildcard pattern.
|
||||
|
||||
## HTTP Compression
|
||||
While most modern web browsers [support](https://www.caniuse.com/#feat=brotli) Brotli, you also need to consider whether the web/app server, hosting platform, reverse proxy or CDN (whichever relevant to you) support it.
|
||||
|
|
10
index.js
10
index.js
|
@ -33,16 +33,18 @@ if (hexo.config.neat_enable === true) {
|
|||
compress: {}
|
||||
}, hexo.config.neat_js)
|
||||
|
||||
// html, css, js compression
|
||||
// gzip compression
|
||||
hexo.config.neat_gzip = Object.assign({
|
||||
enable: true,
|
||||
logger: false
|
||||
logger: false,
|
||||
include: ['*.html','*.css','*.js','*.txt','*.ttf','*.atom','*.stl','*.xml','*.svg','*.eot','*.json']
|
||||
}, hexo.config.neat_gzip)
|
||||
|
||||
// html, css, js compression
|
||||
// brotli compression
|
||||
hexo.config.neat_brotli = Object.assign({
|
||||
enable: true,
|
||||
logger: false
|
||||
logger: false,
|
||||
include: ['*.html','*.css','*.js','*.txt','*.ttf','*.atom','*.stl','*.xml','*.svg','*.eot','*.json']
|
||||
}, hexo.config.neat_brotli)
|
||||
|
||||
const filter = require('./lib/filter')
|
||||
|
|
|
@ -94,11 +94,9 @@ function logicGzip () {
|
|||
|
||||
let route = hexo.route
|
||||
let routeList = route.list()
|
||||
let include = options.include
|
||||
|
||||
return Promise.all(routeList.filter(path => (path.endsWith('.html') || path.endsWith('.js') || path.endsWith('.css')
|
||||
|| path.endsWith('.xml') || path.endsWith('.json') || path.endsWith('.txt')
|
||||
|| path.endsWith('.ttf') || path.endsWith('.atom') || path.endsWith('.stl')
|
||||
|| path.endsWith('.svg') || path.endsWith('.eot'))).map(path => {
|
||||
return Promise.all((nanomatch(routeList, include, { matchBase: true })).map(path => {
|
||||
return new Promise((resolve, reject) => {
|
||||
// Grab all assets using hexo router
|
||||
let assetPath = route.get(path)
|
||||
|
@ -137,11 +135,9 @@ function logicBrotli () {
|
|||
|
||||
let route = hexo.route
|
||||
let routeList = route.list()
|
||||
let include = options.include
|
||||
|
||||
return Promise.all(routeList.filter(path => (path.endsWith('.html') || path.endsWith('.js') || path.endsWith('.css')
|
||||
|| path.endsWith('.xml') || path.endsWith('.json') || path.endsWith('.txt')
|
||||
|| path.endsWith('.ttf') || path.endsWith('.atom') || path.endsWith('.stl')
|
||||
|| path.endsWith('.svg') || path.endsWith('.eot'))).map(path => {
|
||||
return Promise.all((nanomatch(routeList, include, { matchBase: true })).map(path => {
|
||||
return new Promise((resolve, reject) => {
|
||||
// Grab all assets using hexo router
|
||||
let assetPath = route.get(path)
|
||||
|
|
Loading…
Reference in New Issue