allow overriding css with local.css. from qbit@bsd.network
Ted Unangst tedu@tedunangst.com
Fri, 12 Apr 2019 13:12:18 -0400
3 files changed,
19 insertions(+),
7 deletions(-)
M
honk.go
→
honk.go
@@ -116,7 +116,8 @@ }
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 @@ "views/login.html",
"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 @@ getters.HandleFunc("/h/{name:[[:alnum:]]+}", viewhonker)
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)
M
util.go
→
util.go
@@ -49,15 +49,19 @@ "golang.org/x/crypto/bcrypt"
_ "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, _ := ioutil.ReadFile("views/style.css") + data, err := ioutil.ReadFile(file) + if err != nil { + return "" + } hasher := sha512.New() hasher.Write(data) + return fmt.Sprintf("?v=%.8x", hasher.Sum(nil)) }
M
views/header.html
→
views/header.html
@@ -3,6 +3,9 @@ <html>
<head> <title>honk</title> <link href="/style.css{{ .StyleParam }}" rel="stylesheet"> +{{ if .LocalStyleParam }} +<link href="/local.css{{ .LocalStyleParam }}" rel="stylesheet"> +{{ end }} <link href="/icon.png" rel="icon"> </head> <body>