diff --git a/handler/utils.go b/handler/util.go similarity index 82% rename from handler/utils.go rename to handler/util.go index f473588..6819376 100644 --- a/handler/utils.go +++ b/handler/util.go @@ -2,8 +2,10 @@ package handler import ( "crypto/rand" + "net/http" "strings" + "github.com/a-h/templ" "github.com/alecthomas/chroma/v2/formatters/html" "github.com/alecthomas/chroma/v2/lexers" "github.com/alecthomas/chroma/v2/styles" @@ -56,3 +58,10 @@ func highlight(content, ext, theme string) (string, error) { } return buf.String(), nil } + +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) + } +}