-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcms.go
71 lines (64 loc) · 1.98 KB
/
cms.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package cms
import (
"regexp"
"strings"
"github.com/syncfuture/go/shttp"
"github.com/tdewolff/minify/v2"
"github.com/tdewolff/minify/v2/css"
"github.com/tdewolff/minify/v2/html"
"github.com/tdewolff/minify/v2/js"
"github.com/tdewolff/minify/v2/json"
"github.com/tdewolff/minify/v2/svg"
"github.com/tdewolff/minify/v2/xml"
)
type ICMS interface {
// GetContent 获取内容
// key: 内容键,一般为路径
// arg[0]: 渲染使用的页面参数数据
// arg[1]: bool 是否使用缓存
// arg[2]: bool 输出html是否压缩
GetContent(key string, args ...interface{}) string
// GetContent 获取内容
// key: 内容键,一般为路径
// arg[0]: 渲染使用的页面参数数据
// arg[1]: bool 是否使用缓存
// arg[2]: bool 输出html是否压缩
Render(key string, args ...interface{}) (string, error)
}
var (
// _paramPool = sync.Pool{
// New: func() interface{} {
// return make(jet.VarMap)
// },
// }
// _bufferPool = spool.NewSyncBufferPool(1024)
_minifier = minify.New()
)
func init() {
_minifier.AddFunc(shttp.CTYPE_CSS, css.Minify)
_minifier.Add(shttp.CTYPE_HTML, &html.Minifier{
KeepComments: false,
KeepConditionalComments: false,
KeepDefaultAttrVals: false,
KeepDocumentTags: false,
KeepEndTags: false,
KeepQuotes: true,
KeepWhitespace: false,
})
_minifier.AddFunc("image/svg+xml", svg.Minify)
_minifier.AddFuncRegexp(regexp.MustCompile("^(application|text)/(x-)?(java|ecma)script$"), js.Minify)
_minifier.AddFuncRegexp(regexp.MustCompile("[/+]json$"), json.Minify)
_minifier.AddFuncRegexp(regexp.MustCompile("[/+]xml$"), xml.Minify)
}
func GetContentType(path string) string {
if strings.HasSuffix(path, ".css") {
return shttp.CTYPE_CSS
} else if strings.HasSuffix(path, ".js") {
return shttp.CTYPE_JS
} else if strings.HasSuffix(path, ".xml") {
return shttp.CTYPE_XML
} else if strings.HasSuffix(path, ".json") {
return shttp.CTYPE_JSON
}
return shttp.CTYPE_HTML
}