github.com/Azareal/Gosora@v0.0.0-20210729070923-553e66b59003/common/templates/minifiers.go (about) 1 package tmpl 2 3 import ( 4 "strconv" 5 "strings" 6 ) 7 8 // TODO: Write unit tests for this 9 func Minify(data string) string { 10 data = strings.Replace(data, "\t", "", -1) 11 data = strings.Replace(data, "\v", "", -1) 12 data = strings.Replace(data, "\n", "", -1) 13 data = strings.Replace(data, "\r", "", -1) 14 data = strings.Replace(data, " ", " ", -1) 15 return data 16 } 17 18 // TODO: Strip comments 19 // TODO: Handle CSS nested in <style> tags? 20 // TODO: Write unit tests for this 21 func minifyHTML(data string) string { 22 return Minify(data) 23 } 24 25 // TODO: Have static files use this 26 // TODO: Strip comments 27 // TODO: Convert the rgb()s to hex codes? 28 // TODO: Write unit tests for this 29 func minifyCSS(data string) string { 30 return Minify(data) 31 } 32 33 // TODO: Convert this to three character hex strings whenever possible? 34 // TODO: Write unit tests for this 35 // nolint 36 func rgbToHexstr(red, green, blue int) string { 37 return strconv.FormatInt(int64(red), 16) + strconv.FormatInt(int64(green), 16) + strconv.FormatInt(int64(blue), 16) 38 } 39 40 /* 41 // TODO: Write unit tests for this 42 func hexstrToRgb(hexstr string) (red, blue, green int, err error) { 43 // Strip the # at the start 44 if hexstr[0] == '#' { 45 hexstr = strings.TrimPrefix(hexstr,"#") 46 } 47 if len(hexstr) != 3 && len(hexstr) != 6 { 48 return 0, 0, 0, errors.New("Hex colour codes may only be three or six characters long") 49 } 50 51 if len(hexstr) == 3 { 52 hexstr = hexstr[0] + hexstr[0] + hexstr[1] + hexstr[1] + hexstr[2] + hexstr[2] 53 } 54 }*/