From 158904f480e558ca00f680e7c577bb6329605eff Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Sun, 5 May 2024 18:05:30 +0200 Subject: refactor: only reload templates when such files are updated --- internal/server/server.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'internal/server/server.go') diff --git a/internal/server/server.go b/internal/server/server.go index aa37674..02b39a0 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -203,10 +203,13 @@ func New(runtimeConfig *Config) (*Server, error) { if err != nil { return nil, errors.WithMessage(err, "could not add directory to file watcher") } - go fw.Start(func() { - templates, err = loadTemplates() - if err != nil { - slog.Error(fmt.Sprintf("could not reload templates: %v", err)) + go fw.Start(func(filename string) { + slog.Debug(fmt.Sprintf("got filename %s", filename)) + if path.Ext(filename) == ".gotmpl" { + templates, err = loadTemplates() + if err != nil { + slog.Error(fmt.Sprintf("could not reload templates: %v", err)) + } } liveReload.Reload() }) -- cgit 1.4.1