diff options
-rw-r--r-- | frontend/assets.go | 17 | ||||
-rw-r--r-- | internal/server/mux.go | 8 |
2 files changed, 20 insertions, 5 deletions
diff --git a/frontend/assets.go b/frontend/assets.go index a6a5e79..286d505 100644 --- a/frontend/assets.go +++ b/frontend/assets.go @@ -10,7 +10,7 @@ import ( "github.com/pkg/errors" ) -var Assets = AssetCollection{ +var Assets = &AssetCollection{ Scripts: make(map[string]Asset), Stylesheets: make(map[string]Asset), } @@ -83,13 +83,22 @@ func hashStyles() error { return nil } -func init() { - err := hashScripts() +func Rehash() (err error) { + err = hashScripts() if err != nil { - panic(err) + return err } err = hashStyles() if err != nil { + return err + } + + return nil +} + +func init() { + err := Rehash() + if err != nil { panic(err) } } diff --git a/internal/server/mux.go b/internal/server/mux.go index 87e878a..2837dc0 100644 --- a/internal/server/mux.go +++ b/internal/server/mux.go @@ -43,7 +43,7 @@ type TemplateData struct { ExtraHeadHTML template.HTML Code int Message string - Assets frontend.AssetCollection + Assets *frontend.AssetCollection } type ResultData struct { @@ -282,6 +282,12 @@ func NewMux( } go fw.Start(func(filename string) { slog.Debug(fmt.Sprintf("got filename %s", filename)) + if match, _ := path.Match("frontend/static/*", filename); match { + err := frontend.Rehash() + if err != nil { + slog.Error("failed to re-hash frontend assets", "error", err) + } + } if path.Ext(filename) == ".gotmpl" { templates, err = loadTemplates() if err != nil { |