diff --git a/honk.go b/honk.go index ccf9019..24a727c 100644 --- a/honk.go +++ b/honk.go @@ -116,7 +116,8 @@ func keymatch(keyname string, actor string) bool { func getInfo(r *http.Request) map[string]interface{} { templinfo := make(map[string]interface{}) - templinfo["StyleParam"] = getstyleparam() + templinfo["StyleParam"] = getstyleparam("views/style.css") + templinfo["LocalStyleParam"] = getstyleparam("views/local.css") templinfo["ServerName"] = serverName templinfo["IconName"] = iconName templinfo["UserInfo"] = GetUserInfo(r) @@ -1123,7 +1124,10 @@ func serve() { "views/header.html", ) if !debug { - savedstyleparam = getstyleparam() + s := "views/style.css" + savedstyleparams[s] = getstyleparam(s) + s = "views/local.css" + savedstyleparams[s] = getstyleparam(s) } mux := mux.NewRouter() @@ -1145,6 +1149,7 @@ func serve() { getters.HandleFunc("/.well-known/webfinger", fingerlicker) getters.HandleFunc("/style.css", servecss) + getters.HandleFunc("/local.css", servecss) getters.HandleFunc("/login", servehtml) posters.HandleFunc("/dologin", dologin) getters.HandleFunc("/logout", dologout) diff --git a/util.go b/util.go index a25de4f..1d27585 100644 --- a/util.go +++ b/util.go @@ -49,15 +49,19 @@ import ( _ "humungus.tedunangst.com/r/go-sqlite3" ) -var savedstyleparam string +var savedstyleparams = make(map[string]string) -func getstyleparam() string { - if savedstyleparam != "" { - return savedstyleparam +func getstyleparam(file string) string { + if p, ok := savedstyleparams[file]; ok { + return p + } + data, err := ioutil.ReadFile(file) + if err != nil { + return "" } - data, _ := ioutil.ReadFile("views/style.css") hasher := sha512.New() hasher.Write(data) + return fmt.Sprintf("?v=%.8x", hasher.Sum(nil)) } diff --git a/views/header.html b/views/header.html index 46575fe..2139919 100644 --- a/views/header.html +++ b/views/header.html @@ -3,6 +3,9 @@ honk +{{ if .LocalStyleParam }} + +{{ end }}