-
Notifications
You must be signed in to change notification settings - Fork 0
/
minify.go
55 lines (42 loc) · 1.69 KB
/
minify.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright (c) Jeevanandam M. (https://github.com/jeevatkm)
// aah-cb/minify source code and usage is governed by a MIT style
// license that can be found in the LICENSE file.
package minify
import (
"io"
"aahframework.org/aah.v0"
"github.com/tdewolff/minify"
"github.com/tdewolff/minify/html"
)
const htmlContentType = "text/html"
var m *minify.M
//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// Global methods
//___________________________________
// HTML method calls the minify library func to minify content. It reads data
// from reader and writes it to the given writer.
func HTML(contentType string, w io.Writer, r io.Reader) error {
return m.Minify(htmlContentType, w, r)
}
//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// Unexported methods
//___________________________________
// addingHTMLMinifer event func to initilize the minify instance and
// adding minifier into framework
func addingHTMLMinifer(e *aah.Event) {
m = minify.New()
cfg := aah.AppConfig()
m.Add(htmlContentType, &html.Minifier{
KeepConditionalComments: cfg.BoolDefault("render.minify.keep.conditional_comments", true),
KeepDocumentTags: cfg.BoolDefault("render.minify.keep.document_tags", true),
KeepWhitespace: cfg.BoolDefault("render.minify.keep.whitespace", true),
KeepDefaultAttrVals: cfg.BoolDefault("render.minify.keep.default_attr_vals", false),
KeepEndTags: cfg.BoolDefault("render.minify.keep.end_tags", false),
})
// set `HTML` minify func.
aah.SetMinifier(HTML)
}
func init() {
// register into aah framework
aah.OnInit(addingHTMLMinifer)
}