Merge pull request #9 from weyusi/file-ext

feat: allow custom file extension for compressions
This commit is contained in:
weyusi 2019-04-23 16:44:48 +09:30 committed by GitHub
commit a219775d6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 13 deletions

View File

@ -37,7 +37,7 @@ neat_html:
- **enable** - Enable the plugin. Defaults to `true`. - **enable** - Enable the plugin. Defaults to `true`.
- **logger** - Verbose output. Defaults to `false`. - **logger** - Verbose output. Defaults to `false`.
- **exclude** - Exclude files. Support [wildcard](https://github.com/micromatch/nanomatch#features) glob pattern. - **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`. - 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`. - `*source.js` also works, but it also excludes `resource.js`.
- Test glob pattern on the web using [Globtester](http://www.globtester.com/). - 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 ``` yaml
neat_gzip: neat_gzip:
enable: true enable: true
include:
- '*.html'
- '*.css'
- '*.js'
- '*.txt'
- '*.ttf'
- '*.atom'
- '*.stl'
- '*.xml'
- '*.svg'
- '*.eot'
- '*.json'
``` ```
- **enable** - Enable the plugin. Defaults to `true`. - **enable** - Enable the plugin. Defaults to `true`.
- **logger** - Verbose output. Defaults to `false`. - **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 ``` yaml
neat_brotli: neat_brotli:
enable: true enable: true
include:
- '*.html'
- '*.css'
- '*.js'
- '*.txt'
- '*.ttf'
- '*.atom'
- '*.stl'
- '*.xml'
- '*.svg'
- '*.eot'
- '*.json'
``` ```
- **enable** - Enable the plugin. Defaults to `true`. - **enable** - Enable the plugin. Defaults to `true`.
- **logger** - Verbose output. Defaults to `false`. - **logger** - Verbose output. Defaults to `false`.
- **include** - Include files. Support wildcard pattern.
## HTTP Compression ## 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. 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.

View File

@ -33,16 +33,18 @@ if (hexo.config.neat_enable === true) {
compress: {} compress: {}
}, hexo.config.neat_js) }, hexo.config.neat_js)
// html, css, js compression // gzip compression
hexo.config.neat_gzip = Object.assign({ hexo.config.neat_gzip = Object.assign({
enable: true, enable: true,
logger: false logger: false,
include: ['*.html','*.css','*.js','*.txt','*.ttf','*.atom','*.stl','*.xml','*.svg','*.eot','*.json']
}, hexo.config.neat_gzip) }, hexo.config.neat_gzip)
// html, css, js compression // brotli compression
hexo.config.neat_brotli = Object.assign({ hexo.config.neat_brotli = Object.assign({
enable: true, enable: true,
logger: false logger: false,
include: ['*.html','*.css','*.js','*.txt','*.ttf','*.atom','*.stl','*.xml','*.svg','*.eot','*.json']
}, hexo.config.neat_brotli) }, hexo.config.neat_brotli)
const filter = require('./lib/filter') const filter = require('./lib/filter')

View File

@ -94,11 +94,9 @@ function logicGzip () {
let route = hexo.route let route = hexo.route
let routeList = route.list() let routeList = route.list()
let include = options.include
return Promise.all(routeList.filter(path => (path.endsWith('.html') || path.endsWith('.js') || path.endsWith('.css') return Promise.all((nanomatch(routeList, include, { matchBase: true })).map(path => {
|| 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 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) let assetPath = route.get(path)
@ -137,11 +135,9 @@ function logicBrotli () {
let route = hexo.route let route = hexo.route
let routeList = route.list() let routeList = route.list()
let include = options.include
return Promise.all(routeList.filter(path => (path.endsWith('.html') || path.endsWith('.js') || path.endsWith('.css') return Promise.all((nanomatch(routeList, include, { matchBase: true })).map(path => {
|| 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 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) let assetPath = route.get(path)