From 3426b668fecf04c3c6b307925ae4e15ed4843072 Mon Sep 17 00:00:00 2001 From: "Felipe M." Date: Mon, 21 Apr 2025 15:09:54 +0200 Subject: [PATCH 1/2] ci: fix deprecated attribute in goreleaser --- .goreleaser.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index 68d1f62..c89e189 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -47,7 +47,7 @@ archives: {{- if eq .Arch "amd64" }}x86_64{{- else if eq .Arch "arm64" }}aarch64{{- else }}{{ .Arch }}{{ end }}_{{ .Version }} format_overrides: - goos: windows - format: zip + formats: ['zip'] dockers: - image_templates: From bbb48f49e2c569527e4aab17da4b8402468c6003 Mon Sep 17 00:00:00 2001 From: "Felipe M." Date: Mon, 21 Apr 2025 15:10:08 +0200 Subject: [PATCH 2/2] fix: embed templates directly --- internal/admin/admin.go | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/internal/admin/admin.go b/internal/admin/admin.go index 715c5e1..d590995 100644 --- a/internal/admin/admin.go +++ b/internal/admin/admin.go @@ -1,9 +1,9 @@ package admin import ( + "embed" "html/template" "net/http" - "path/filepath" "strconv" "strings" @@ -14,12 +14,12 @@ import ( "github.com/gorilla/sessions" ) +//go:embed templates/*.html +var templateFS embed.FS + const ( // Session store key sessionKey = "butterrobot-session" - - // Template directory - templateDir = "./internal/admin/templates" ) // FlashMessage represents a flash message @@ -63,9 +63,17 @@ func New(cfg *config.Config, database *db.Database) *Admin { "contains": strings.Contains, } + // Read base template from embedded filesystem + baseContent, err := templateFS.ReadFile("templates/_base.html") + if err != nil { + panic(err) + } + // Create a custom template with functions - baseTemplate := template.New("_base.html").Funcs(funcMap) - baseTemplate = template.Must(baseTemplate.ParseFiles(filepath.Join(templateDir, "_base.html"))) + baseTemplate, err := template.New("_base.html").Funcs(funcMap).Parse(string(baseContent)) + if err != nil { + panic(err) + } // Parse and register all templates templateFiles := []string{ @@ -78,11 +86,24 @@ func New(cfg *config.Config, database *db.Database) *Admin { } for _, tf := range templateFiles { - // Create a clone of the base template - t, err := template.Must(baseTemplate.Clone()).ParseFiles(filepath.Join(templateDir, tf)) + // Read template content from embedded filesystem + content, err := templateFS.ReadFile("templates/" + tf) if err != nil { panic(err) } + + // Create a clone of the base template + t, err := baseTemplate.Clone() + if err != nil { + panic(err) + } + + // Parse the template content + t, err = t.Parse(string(content)) + if err != nil { + panic(err) + } + templates[tf] = t }