Improved icon loading

This commit is contained in:
Eduard Urbach 2017-06-16 18:19:32 +02:00
parent 3b62457861
commit 7211264c5f

View File

@ -5,14 +5,24 @@ import (
"strings"
)
var svgIcons = make(map[string]string)
func init() {
files, _ := ioutil.ReadDir("images/icons/svg/")
for _, file := range files {
name := strings.Replace(file.Name(), ".svg", "", 1)
data, _ := ioutil.ReadFile("images/icons/svg/" + name + ".svg")
svgIcons[name] = strings.Replace(string(data), "<svg ", "<svg class='icon' ", 1)
}
}
// Icon ...
func Icon(name string) string {
data, _ := ioutil.ReadFile("images/icons/svg/" + name + ".svg")
return strings.Replace(string(data), "<svg ", "<svg class='icon' ", 1)
return svgIcons[name]
}
// RawIcon ...
func RawIcon(name string) string {
data, _ := ioutil.ReadFile("images/icons/svg/" + name + ".svg")
return strings.Replace(string(data), "<svg ", "<svg class='raw-icon' ", 1)
return strings.Replace(svgIcons[name], "class='icon'", "class='raw-icon'", 1)
}