From 132882c37c6c7531377065dc0cef508a82d2363b Mon Sep 17 00:00:00 2001 From: Timur Ismagilov Date: Sat, 7 Sep 2024 23:01:48 +0300 Subject: [PATCH] Migrate viewutil --- web/newtmpl/newtmpl.go | 5 +++-- web/viewutil/meta.go | 5 +++-- web/viewutil/viewutil.go | 6 +++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/web/newtmpl/newtmpl.go b/web/newtmpl/newtmpl.go index b0184c5..d2bf77f 100644 --- a/web/newtmpl/newtmpl.go +++ b/web/newtmpl/newtmpl.go @@ -3,11 +3,12 @@ package newtmpl import ( "embed" "fmt" + "html/template" + "strings" + "github.com/bouncepaw/mycorrhiza/internal/cfg" "github.com/bouncepaw/mycorrhiza/util" "github.com/bouncepaw/mycorrhiza/web/viewutil" - "html/template" - "strings" ) //go:embed *.html diff --git a/web/viewutil/meta.go b/web/viewutil/meta.go index d47dc02..4b8ab2d 100644 --- a/web/viewutil/meta.go +++ b/web/viewutil/meta.go @@ -1,11 +1,12 @@ package viewutil import ( - "github.com/bouncepaw/mycorrhiza/internal/user" - "github.com/bouncepaw/mycorrhiza/l18n" "html/template" "io" "net/http" + + "github.com/bouncepaw/mycorrhiza/internal/user" + "github.com/bouncepaw/mycorrhiza/l18n" ) // Meta is a bundle of common stuffs used by views, templates. diff --git a/web/viewutil/viewutil.go b/web/viewutil/viewutil.go index f49de2d..80fb2f8 100644 --- a/web/viewutil/viewutil.go +++ b/web/viewutil/viewutil.go @@ -6,7 +6,7 @@ import ( "fmt" "github.com/bouncepaw/mycorrhiza/internal/cfg" "io/fs" - "log" + "log/slog" "strings" "text/template" // TODO: save the world @@ -125,7 +125,7 @@ func Base(meta Meta, title, body string, bodyAttributes map[string]string, headE BodyAttributes: bodyAttributes, }) if err != nil { - log.Println(err) + slog.Info("Failed to execute the legacy Base template; proceeding anyway", "err", err) } return w.String() } @@ -149,7 +149,7 @@ func ExecutePage(meta Meta, chain Chain, data interface { }) { data.withBaseValues(meta, HeaderLinks, cfg.CommonScripts) if err := chain.Get(meta).ExecuteTemplate(meta.W, "page", data); err != nil { - log.Println(err) + slog.Info("Failed to execute page; proceeding anyway", "err", err) } }