diff --git a/frontend/frontend.go b/frontend/frontend.go index 8ea3a13..2f67754 100644 --- a/frontend/frontend.go +++ b/frontend/frontend.go @@ -3,7 +3,10 @@ package frontend import ( "embed" "html/template" + "io" "io/fs" + + "github.com/sirupsen/logrus" ) var ( @@ -14,11 +17,21 @@ var ( //go:embed *.html templatesFS embed.FS Templates *template.Template + + funcs = template.FuncMap{ + "static": staticFn, + "staticCSS": func(filename string) (template.CSS, error) { + data, err := staticFn(filename) + return template.CSS(data), err + }, + } ) func init() { + t := template.New("").Funcs(funcs) + var err error - Templates, err = template.ParseFS(templatesFS, "*") + Templates, err = t.ParseFS(templatesFS, "*") if err != nil { panic(err) } @@ -28,3 +41,23 @@ func init() { panic(err) } } + +func staticFn(filename string) (string, error) { + f, err := Static.Open(filename) + if err != nil { + return "", err + } + defer f.Close() + + data, err := io.ReadAll(f) + if err != nil { + return "", err + } + + logrus.WithFields(logrus.Fields{ + "filename": filename, + "data": string(data), + }).Debug("reading static file for template") + + return string(data), nil +} diff --git a/frontend/index.html b/frontend/index.html index 96a08e0..f44f800 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -5,7 +5,7 @@