Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
951 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
node_js: | ||
- "0.11" | ||
- "7" | ||
language: node_js | ||
script: "npm run test-travis" | ||
after_script: "npm install coveralls@2.10.0 && cat ./coverage/lcov.info | coveralls" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,14 @@ | ||
const minify = require('html-minifier').minify; | ||
|
||
var minify = require('html-minifier').minify | ||
|
||
module.exports = function (options) { | ||
options = options || {} | ||
return function* minifyHTML(next) { | ||
yield* next | ||
|
||
if (!this.response.is('html')) return | ||
var body = this.response.body | ||
if (!body) return | ||
// too lazy to handle streams | ||
if (typeof body.pipe === 'function') return | ||
if (Buffer.isBuffer(body)) body = body.toString('utf8') | ||
else if (typeof body === 'object') return // wtf programming | ||
this.response.body = minify(body, options) | ||
} | ||
} | ||
module.exports = (options = {}) => { | ||
return async (ctx, next) => { | ||
await next(); | ||
if (!ctx.response.is('html')) return; | ||
let { body } = ctx.response; | ||
if (!body) return; | ||
if (typeof body.pipe === 'function') return; | ||
if (Buffer.isBuffer(body)) body = body.toString('utf8'); | ||
else if (typeof body === 'object') return; | ||
ctx.response.body = await minify(body, options); | ||
}; | ||
}; |
Oops, something went wrong.