From 1c3040ee79dd4b96a0412e67c2ea6fb6854ba9ab Mon Sep 17 00:00:00 2001 From: aziis98 Date: Fri, 21 Aug 2020 03:42:54 +0200 Subject: [PATCH 01/16] template_renderer.go: Migliorato ciclo di sviluppo --- utils/template_renderer.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/utils/template_renderer.go b/utils/template_renderer.go index bf16f0e..6c82d14 100644 --- a/utils/template_renderer.go +++ b/utils/template_renderer.go @@ -8,8 +8,15 @@ import ( "github.com/labstack/echo/v4" ) +var isDevMode bool + +func init() { + isDevMode = os.Getenv("MODE") == "development" +} + // TemplateRenderer holds cached templates for rendering type TemplateRenderer struct { + baseFile string baseTemplate *template.Template templateMap map[string]*template.Template } @@ -17,6 +24,7 @@ type TemplateRenderer struct { // NewTemplateRenderer constructs a template renderer with a base file func NewTemplateRenderer(baseFile string) *TemplateRenderer { return &TemplateRenderer{ + baseFile: baseFile, baseTemplate: template.Must(template.ParseFiles("./views/" + baseFile)), templateMap: make(map[string]*template.Template), } @@ -24,9 +32,16 @@ func NewTemplateRenderer(baseFile string) *TemplateRenderer { // Render the template func (t *TemplateRenderer) Render(w io.Writer, name string, data interface{}, c echo.Context) error { + tmpl := t.templateMap[name] - if os.Getenv("MODE") == "development" || tmpl == nil { - tmpl = template.Must(t.baseTemplate.Clone()) + if isDevMode || tmpl == nil { + + if isDevMode { + tmpl = template.Must(template.ParseFiles("./views/" + t.baseFile)) + } else { + tmpl = template.Must(t.baseTemplate.Clone()) + } + tmpl.ParseFiles("./views/" + name) t.templateMap[name] = tmpl } From 935278357b5e72b3939f794fbc4353933f23bac0 Mon Sep 17 00:00:00 2001 From: aziis98 Date: Fri, 21 Aug 2020 03:39:32 +0200 Subject: [PATCH 02/16] base.html: Aggiunto CDN per KaTeX --- views/base.html | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/views/base.html b/views/base.html index 163e8e6..3909ea1 100644 --- a/views/base.html +++ b/views/base.html @@ -7,9 +7,29 @@ {{ template "title" . }} - - + + + + + + @@ -26,13 +46,15 @@ Notizie +
+ {{if .User}}