From ffa26298c95451639a6e01db6692d02d50b3d518 Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Sat, 18 May 2024 16:45:28 +0200 Subject: Remove most custom template functions from html templating --- src/http/tpl.go | 18 ++---------------- src/http/tpl/base.html | 5 ++--- src/http/tpl/gemini-cta.html | 2 +- src/http/tpl/post.html | 2 +- src/render/methods.go | 4 ++++ 5 files changed, 10 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/http/tpl.go b/src/http/tpl.go index afd4c8e..2711259 100644 --- a/src/http/tpl.go +++ b/src/http/tpl.go @@ -12,7 +12,6 @@ import ( "net/url" "path/filepath" "strings" - "time" "dev.mediocregopher.com/mediocre-blog.git/src/http/apiutil" "dev.mediocregopher.com/mediocre-blog.git/src/post" @@ -93,27 +92,14 @@ func (a *api) draftsURL(abs bool) string { func (a *api) tplFuncs() template.FuncMap { return template.FuncMap{ - "StaticInlineCSS": func(path string) (template.CSS, error) { - path = filepath.Join("static", path) - b, err := staticFS.ReadFile(path) - return template.CSS(b), err - }, - "DraftURL": func(id string) string { - return a.draftPostURL(id, false) - }, - "DateTimeFormat": func(t time.Time) string { - return t.Format("2006-01-02") - }, - "SafeURL": func(u string) template.URL { - return template.URL(u) - }, + "DraftURL": func(id string) string { return a.draftPostURL(id, false) }, } } func (a *api) emptyTpl() *template.Template { tpl := template.New("") tpl = tpl.Funcs(a.tplFuncs()) - tpl = tpl.Funcs(template.FuncMap(a.postPreprocessFuncs().ToFuncMap())) + tpl = tpl.Funcs(a.postPreprocessFuncs().ToFuncMap()) return tpl } diff --git a/src/http/tpl/base.html b/src/http/tpl/base.html index 7e7a4a9..47644f7 100644 --- a/src/http/tpl/base.html +++ b/src/http/tpl/base.html @@ -3,9 +3,8 @@ {{ .Title }} - - - + + diff --git a/src/http/tpl/gemini-cta.html b/src/http/tpl/gemini-cta.html index 06e3a22..89b8e8b 100644 --- a/src/http/tpl/gemini-cta.html +++ b/src/http/tpl/gemini-cta.html @@ -2,7 +2,7 @@

This site can also be accessed via the gemini protocol: - + {{ BlogGeminiURL "/" }}

diff --git a/src/http/tpl/post.html b/src/http/tpl/post.html index 0cf3622..46a24fc 100644 --- a/src/http/tpl/post.html +++ b/src/http/tpl/post.html @@ -16,7 +16,7 @@ {{ .PostHTMLBody $post }}

- Published {{ DateTimeFormat $post.PublishedAt }} + Published {{ $post.PublishedAt.Format "2006-01-02" }}

{{- if $post.Series }} diff --git a/src/render/methods.go b/src/render/methods.go index 5b2c0b1..9b5a41e 100644 --- a/src/render/methods.go +++ b/src/render/methods.go @@ -263,3 +263,7 @@ func (m *Methods) GetPath() (string, error) { } func (m *Methods) Add(a, b int) int { return a + b } + +func (m *Methods) URLIsSafe(s string) template.URL { + return template.URL(s) +} -- cgit v1.2.3