-
Notifications
You must be signed in to change notification settings - Fork 5
/
css.go
38 lines (32 loc) · 1.06 KB
/
css.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
/* For license and copyright information please see LEGAL file in repository */
package www
import (
"bytes"
"../minify"
"../protocol"
)
// mixCSSToHTML add given CSS file to end of HTML file and returns new html file.
func mixCSSToHTML(html, css []byte) (mixedData []byte) {
mixedData = make([]byte, len(html), len(html)+len(css)+len("\n<style></style>"))
copy(mixedData, html)
mixedData = append(mixedData, "\n<style>"...)
mixedData = append(mixedData, css...)
mixedData = append(mixedData, "</style>"...)
return
}
// mixCSSToJS add given CSS file to specific part of JS file and returns new js file.
func mixCSSToJS(js, css []byte) (mixedData []byte, err protocol.Error) {
css, err = minify.CSS.MinifyBytes(css)
if err != nil {
return
}
var funcLoc = bytes.Index(js, []byte("CSS: '"))
if funcLoc < 0 {
var minifiedCSS = append([]byte(`CSS = '`), css...)
mixedData = bytes.Replace(js, []byte(`CSS = '`), minifiedCSS, 1)
} else {
var minifiedCSS = append([]byte(`CSS: '`), css...)
mixedData = bytes.Replace(js, []byte(`CSS: '`), minifiedCSS, 1)
}
return
}