~evanj/evanjon.es

8eff12b574616cbf2fff20b4ca6fd4eb789199fc — Evan M Jones 1 year, 4 months ago 97a7b8e
Fix(cache+tmpl): Small tweaks to cache and tmpl.

When cached items are corrupted delete cached item.

Create template helper functions before parsing templates themselves.
5 files changed, 15 insertions(+), 11 deletions(-)

M go.mod
M go.sum
M internal/s/cms/cms.go
M internal/s/tmpl/tmpl.go
M vendor/modules.txt
M go.mod => go.mod +1 -1
@@ 3,7 3,7 @@ module git.sr.ht/~evanj/evanjon.es
go 1.14

require (
	git.sr.ht/~evanj/embed v0.0.0-20200525225021-2cde7dae7bfa // indirect
	git.sr.ht/~evanj/embed v0.0.0-20200702023953-8a902e4e7e94 // indirect
	github.com/gorilla/feeds v1.1.1
	github.com/tdewolff/minify/v2 v2.7.3
)

M go.sum => go.sum +2 -0
@@ 1,5 1,7 @@
git.sr.ht/~evanj/embed v0.0.0-20200525225021-2cde7dae7bfa h1:gpQ2a3/AYs0o1F/kg2V2GIUIS8pPkvoSlJPZCbF9Mvw=
git.sr.ht/~evanj/embed v0.0.0-20200525225021-2cde7dae7bfa/go.mod h1:o3sadZPJeN9scjfsbpsABLF2nNr6qUqMMkGLfCCsILc=
git.sr.ht/~evanj/embed v0.0.0-20200702023953-8a902e4e7e94 h1:uvmXsjtUvWzL3n3ghDejB3r6HV1Bl/EaDPmqs/F3cyA=
git.sr.ht/~evanj/embed v0.0.0-20200702023953-8a902e4e7e94/go.mod h1:o3sadZPJeN9scjfsbpsABLF2nNr6qUqMMkGLfCCsILc=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/cheekybits/is v0.0.0-20150225183255-68e9c0620927/go.mod h1:h/aW8ynjgkuj+NQRlZcDbAbM1ORAbXjXX77sX7T289U=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=

M internal/s/cms/cms.go => internal/s/cms/cms.go +2 -0
@@ 58,6 58,7 @@ func (cached *CachedCMS) Find(ctx context.Context, typeID int, field, query stri
		if ok {
			return content, nil
		}
		cached.cache.Delete(key)
		return nil, ErrBadCache
	}



@@ 79,6 80,7 @@ func (cached *CachedCMS) List(ctx context.Context, typeID int, order, field stri
		if ok {
			return content, nil
		}
		cached.cache.Delete(key)
		return nil, ErrBadCache
	}


M internal/s/tmpl/tmpl.go => internal/s/tmpl/tmpl.go +9 -9
@@ 15,7 15,14 @@ import (
//go:generate embed -pattern */* -id tmpls

var (
	all      = template.New("cms")
	all = template.New("cms").
		Funcs(template.FuncMap(map[string]interface{}{
			"html": func(val string) template.HTML { return template.HTML(val) },
			"date": func(val string) (string, error) {
				date, err := time.Parse("2006-01-02", val)
				return date.Format("Jan 2, 2006"), err
			},
		}))
	minifier = minify.New()
	once     sync.Once
)


@@ 46,14 53,7 @@ func MustParse(name string) *template.Template {
				panic(err.Error())
			}

			all = template.Must(all.New(key).Parse(val)).
				Funcs(template.FuncMap(map[string]interface{}{
					"html": func(val string) template.HTML { return template.HTML(val) },
					"date": func(val string) (string, error) {
						date, err := time.Parse("2006-01-02", val)
						return date.Format("Jan 2, 2006"), err
					},
				}))
			all = template.Must(all.New(key).Parse(val))
		}
	})


M vendor/modules.txt => vendor/modules.txt +1 -1
@@ 1,4 1,4 @@
# git.sr.ht/~evanj/embed v0.0.0-20200525225021-2cde7dae7bfa
# git.sr.ht/~evanj/embed v0.0.0-20200702023953-8a902e4e7e94
## explicit
# github.com/gorilla/feeds v1.1.1
## explicit