Compare commits

..

No commits in common. "bbb48f49e2c569527e4aab17da4b8402468c6003" and "7c684af8c3ffb149db841f2b71c3fd6b374a801e" have entirely different histories.

2 changed files with 8 additions and 29 deletions

View file

@ -47,7 +47,7 @@ archives:
{{- if eq .Arch "amd64" }}x86_64{{- else if eq .Arch "arm64" }}aarch64{{- else }}{{ .Arch }}{{ end }}_{{ .Version }} {{- if eq .Arch "amd64" }}x86_64{{- else if eq .Arch "arm64" }}aarch64{{- else }}{{ .Arch }}{{ end }}_{{ .Version }}
format_overrides: format_overrides:
- goos: windows - goos: windows
formats: ['zip'] format: zip
dockers: dockers:
- image_templates: - image_templates:

View file

@ -1,9 +1,9 @@
package admin package admin
import ( import (
"embed"
"html/template" "html/template"
"net/http" "net/http"
"path/filepath"
"strconv" "strconv"
"strings" "strings"
@ -14,12 +14,12 @@ import (
"github.com/gorilla/sessions" "github.com/gorilla/sessions"
) )
//go:embed templates/*.html
var templateFS embed.FS
const ( const (
// Session store key // Session store key
sessionKey = "butterrobot-session" sessionKey = "butterrobot-session"
// Template directory
templateDir = "./internal/admin/templates"
) )
// FlashMessage represents a flash message // FlashMessage represents a flash message
@ -63,17 +63,9 @@ func New(cfg *config.Config, database *db.Database) *Admin {
"contains": strings.Contains, "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 // Create a custom template with functions
baseTemplate, err := template.New("_base.html").Funcs(funcMap).Parse(string(baseContent)) baseTemplate := template.New("_base.html").Funcs(funcMap)
if err != nil { baseTemplate = template.Must(baseTemplate.ParseFiles(filepath.Join(templateDir, "_base.html")))
panic(err)
}
// Parse and register all templates // Parse and register all templates
templateFiles := []string{ templateFiles := []string{
@ -86,24 +78,11 @@ func New(cfg *config.Config, database *db.Database) *Admin {
} }
for _, tf := range templateFiles { for _, tf := range templateFiles {
// Read template content from embedded filesystem
content, err := templateFS.ReadFile("templates/" + tf)
if err != nil {
panic(err)
}
// Create a clone of the base template // Create a clone of the base template
t, err := baseTemplate.Clone() t, err := template.Must(baseTemplate.Clone()).ParseFiles(filepath.Join(templateDir, tf))
if err != nil { if err != nil {
panic(err) panic(err)
} }
// Parse the template content
t, err = t.Parse(string(content))
if err != nil {
panic(err)
}
templates[tf] = t templates[tf] = t
} }