From 3079673dc444be4a54bdba4eeb715d2cc0d7d817 Mon Sep 17 00:00:00 2001 From: Janne Koschinski <janne@kuschku.de> Date: Mon, 30 Apr 2018 03:22:20 +0200 Subject: [PATCH] Added icon handling Signed-off-by: Janne Koschinski <janne@kuschku.de> --- main.go | 2 +- page_index.go | 12 ++++++++++++ templates/_navigation.html | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 7a7d133..4976acf 100644 --- a/main.go +++ b/main.go @@ -32,7 +32,7 @@ func main() { http.Handle("/a/", http.StripPrefix("/a/", pageAlbumDetail(pageContext))) http.Handle("/me/images/", pageImageList(pageContext)) - http.Handle("/assets/", http.StripPrefix("/assets/", http.FileServer(http.Dir("assets")))) + http.Handle("/assets/", http.StripPrefix("/assets/", pageContext.AssetServer)) http.Handle("/", pageIndex(pageContext)) http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) { diff --git a/page_index.go b/page_index.go index 8ec8040..a2dced3 100644 --- a/page_index.go +++ b/page_index.go @@ -18,6 +18,18 @@ func pageIndex(ctx PageContext) http.Handler { }); err != nil { panic(err) } + } else if r.URL.Path == "/favicon.ico" { + w.Header().Set("Vary", "Accept-Encoding") + w.Header().Set("Cache-Control", "public, max-age=31536000") + ctx.AssetServer.ServeHTTP(w, r) + } else if r.URL.Path == "/favicon.png" { + w.Header().Set("Vary", "Accept-Encoding") + w.Header().Set("Cache-Control", "public, max-age=31536000") + ctx.AssetServer.ServeHTTP(w, r) + } else if r.URL.Path == "/favicon.svg" { + w.Header().Set("Vary", "Accept-Encoding") + w.Header().Set("Cache-Control", "public, max-age=31536000") + ctx.AssetServer.ServeHTTP(w, r) } else { w.Header().Set("Vary", "Accept-Encoding") w.Header().Set("Cache-Control", "public, max-age=31536000") diff --git a/templates/_navigation.html b/templates/_navigation.html index ca8b030..bca2fc8 100644 --- a/templates/_navigation.html +++ b/templates/_navigation.html @@ -1,7 +1,7 @@ {{define "navigation"}} <nav> <ul> - <li class="title"><a href="/">ik8r</a></li> + <li class="title"><a href="/"><img src="/assets/images/logo.svg"></a></li> {{if .HasRole "imghost:user" }} <li><a href="/upload">Upload</a></li> {{end}} -- GitLab