From 914f4b8a74050e37c1bfeac7220aa9ab36e19180 Mon Sep 17 00:00:00 2001 From: csehviktor Date: Fri, 1 Aug 2025 20:50:13 +0200 Subject: [PATCH] implement dynamic theming --- handler/http.go | 15 ++++++--------- main.go | 1 + 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/handler/http.go b/handler/http.go index 225fad5..11b612d 100644 --- a/handler/http.go +++ b/handler/http.go @@ -5,7 +5,6 @@ import ( "net/http" "strings" - "github.com/a-h/templ" "github.com/csehviktor/pastebin/store" "github.com/csehviktor/pastebin/view" ) @@ -60,7 +59,12 @@ func (h *HttpHandler) HandleGet(w http.ResponseWriter, r *http.Request) { return } - highlighted, err := highlight(content, ext, "catppuccin-macchiato") + theme := r.PathValue("theme") + if theme == "" { + theme = "catppuccin-macchiato" + } + + highlighted, err := highlight(content, ext, theme) if err != nil { internal("could not highlight content", err, w, r) return @@ -72,10 +76,3 @@ func (h *HttpHandler) HandleGet(w http.ResponseWriter, r *http.Request) { func (h *HttpHandler) HandleHome(w http.ResponseWriter, r *http.Request) { render(view.BinEditorPage(), w, r) } - -func render(component templ.Component, w http.ResponseWriter, r *http.Request) { - err := component.Render(r.Context(), w) - if err != nil { - internal("could not render template", err, w, r) - } -} diff --git a/main.go b/main.go index 2af7ca9..1e3b6f3 100644 --- a/main.go +++ b/main.go @@ -21,6 +21,7 @@ func main() { mux.HandleFunc("GET /", httpHandler.HandleHome) mux.HandleFunc("POST /", httpHandler.HandleSet) mux.HandleFunc("GET /{id}", httpHandler.HandleGet) + mux.HandleFunc("GET /{id}/{theme}", httpHandler.HandleGet) slog.Info("starting http server on", "addr", addr) err := http.ListenAndServe(addr, mux)