Some optimizations. Improve font loading and embed global.css directly
This commit is contained in:
@@ -15,6 +15,7 @@ import (
|
||||
type TemplateData struct {
|
||||
Authenticated bool
|
||||
Username string
|
||||
UserStyle template.CSS
|
||||
APIEndpoint template.URL
|
||||
PixelAPI *pixelapi.PixelAPI
|
||||
|
||||
@@ -27,6 +28,7 @@ func (wc *WebController) newTemplateData(w http.ResponseWriter, r *http.Request)
|
||||
var t = &TemplateData{
|
||||
Authenticated: false,
|
||||
Username: "",
|
||||
UserStyle: userStyle(r),
|
||||
APIEndpoint: template.URL(wc.conf.APIURLExternal),
|
||||
URLQuery: r.URL.Query(),
|
||||
}
|
||||
|
@@ -2,15 +2,11 @@ package webcontroller
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/julienschmidt/httprouter"
|
||||
)
|
||||
|
||||
func (wc *WebController) globalCSSHandler(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||
w.Header().Add("Content-Type", "text/css; charset=utf-8")
|
||||
|
||||
func userStyle(r *http.Request) (style template.CSS) {
|
||||
var selectedStyle PixeldrainStyleSheet
|
||||
|
||||
if cookie, err := r.Cookie("style"); err != nil {
|
||||
@@ -32,7 +28,7 @@ func (wc *WebController) globalCSSHandler(w http.ResponseWriter, r *http.Request
|
||||
// var highlightColor = "843384"
|
||||
// var highlightColorDark = "672867"
|
||||
|
||||
var response = fmt.Sprintf(
|
||||
return template.CSS(fmt.Sprintf(
|
||||
`:root {
|
||||
--text_color: %s;
|
||||
--input_color: %s;
|
||||
@@ -57,8 +53,7 @@ func (wc *WebController) globalCSSHandler(w http.ResponseWriter, r *http.Request
|
||||
--shadow_color: %s;
|
||||
--shadow_spread: %s;
|
||||
--shadow_intensity: %s;
|
||||
}
|
||||
`,
|
||||
}`,
|
||||
selectedStyle.TextColor.CSSString(),
|
||||
selectedStyle.InputColor.CSSString(),
|
||||
selectedStyle.InputColor.Add(0, 0, -.1).CSSString(),
|
||||
@@ -80,9 +75,7 @@ func (wc *WebController) globalCSSHandler(w http.ResponseWriter, r *http.Request
|
||||
selectedStyle.ShadowColor.CSSString(),
|
||||
fmt.Sprintf("%dpx", selectedStyle.ShadowSpread),
|
||||
fmt.Sprintf("%dpx", selectedStyle.ShadowIntensity),
|
||||
)
|
||||
|
||||
strings.NewReader(response).WriteTo(w)
|
||||
))
|
||||
}
|
||||
|
||||
type PixeldrainStyleSheet struct {
|
@@ -44,7 +44,6 @@ func New(r *httprouter.Router, prefix string, conf *conf.PixelWebConfig) *WebCon
|
||||
// General navigation
|
||||
r.GET(p+"/" /* */, wc.serveTemplate("home", false))
|
||||
r.GET(p+"/favicon.ico" /* */, wc.serveFile("/favicon.ico"))
|
||||
r.GET(p+"/global.css" /* */, wc.globalCSSHandler)
|
||||
r.GET(p+"/api" /* */, wc.serveTemplate("apidoc", false))
|
||||
r.GET(p+"/history" /* */, wc.serveTemplate("history_cookies", false))
|
||||
r.GET(p+"/u/:id" /* */, wc.serveFileViewer)
|
||||
|
Reference in New Issue
Block a user