diff --git a/go.mod b/go.mod index 867c3e4..f110f6a 100644 --- a/go.mod +++ b/go.mod @@ -1,11 +1,12 @@ module github.com/matbur/image-text -go 1.21 +go 1.23 toolchain go1.23.0 require ( github.com/a-h/templ v0.2.793 + github.com/elliotchance/pie/v2 v2.9.1 github.com/go-chi/chi/v5 v5.1.0 github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 github.com/hashicorp/go-multierror v1.1.1 @@ -18,5 +19,6 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/hashicorp/errwrap v1.0.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect + golang.org/x/exp v0.0.0-20220321173239-a90fa8a75705 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 015e924..138591b 100644 --- a/go.sum +++ b/go.sum @@ -2,6 +2,8 @@ github.com/a-h/templ v0.2.793 h1:Io+/ocnfGWYO4VHdR0zBbf39PQlnzVCVVD+wEEs6/qY= github.com/a-h/templ v0.2.793/go.mod h1:lq48JXoUvuQrU0VThrK31yFwdRjTCnIE5bcPCM9IP1w= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/elliotchance/pie/v2 v2.9.1 h1:v7TdC6ZdNZJ1HACofpLXvGKHUk307AjY/bttwDPWKEQ= +github.com/elliotchance/pie/v2 v2.9.1/go.mod h1:18t0dgGFH006g4eVdDtWfgFZPQEgl10IoEO8YWEq3Og= github.com/go-chi/chi/v5 v5.1.0 h1:acVI1TYaD+hhedDJ3r54HyA6sExp3HfXq7QWEEY/xMw= github.com/go-chi/chi/v5 v5.1.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g= @@ -18,6 +20,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +golang.org/x/exp v0.0.0-20220321173239-a90fa8a75705 h1:ba9YlqfDGTTQ5aZ2fwOoQ1hf32QySyQkR6ODGDzHlnE= +golang.org/x/exp v0.0.0-20220321173239-a90fa8a75705/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE= golang.org/x/image v0.0.0-20191214001246-9130b4cfad52 h1:2fktqPPvDiVEEVT/vSTeoUPXfmRxRaGy6GU8jypvEn0= golang.org/x/image v0.0.0-20191214001246-9130b4cfad52/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/server/server.go b/server/server.go index 635b86a..a3b9087 100644 --- a/server/server.go +++ b/server/server.go @@ -9,6 +9,7 @@ import ( "time" "github.com/a-h/templ" + "github.com/elliotchance/pie/v2" "github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5/middleware" @@ -57,11 +58,13 @@ func handleMain(w http.ResponseWriter, r *http.Request) { u = u.JoinPath(size, bgColor, fgColor) params := templates.IndexPageParams{ - Text: text, - BgColor: bgColor, - FgColor: fgColor, - Size: size, - Image: u.String(), + Text: text, + BgColor: bgColor, + FgColor: fgColor, + Size: size, + Image: u.String(), + ColorOptions: pie.Keys(image.KnownColors()), + SizeOptions: pie.Keys(image.KnownSizes()), } templ.Handler(templates.IndexPage(params)).ServeHTTP(w, r) } @@ -100,6 +103,8 @@ func handlePost(w http.ResponseWriter, r *http.Request) { slog.Info("Image url", "url", u.String()) params.Image = u.String() + params.ColorOptions = pie.Keys(image.KnownColors()) + params.SizeOptions = pie.Keys(image.KnownSizes()) templ.Handler(templates.IndexPage(params)).ServeHTTP(w, r) } diff --git a/templates/templates.templ b/templates/templates.templ index 3eed139..6ca7d4f 100644 --- a/templates/templates.templ +++ b/templates/templates.templ @@ -66,68 +66,100 @@ type IndexPageParams struct { FgColor string `json:"fg_color"` Size string `json:"size"` Image string `json:"-"` + + ColorOptions []string `json:"-"` + SizeOptions []string `json:"-"` } templ IndexPage(params IndexPageParams) { @layout() {