diff options
author | Brian Picciano <mediocregopher@gmail.com> | 2024-05-18 16:45:28 +0200 |
---|---|---|
committer | Brian Picciano <mediocregopher@gmail.com> | 2024-05-18 16:45:28 +0200 |
commit | ffa26298c95451639a6e01db6692d02d50b3d518 (patch) | |
tree | 346c5aef72e60a3c2b47e9713aea7c723c116bc1 /src | |
parent | 93a8843e2e3391459fd333aef9e5c7617608c2b3 (diff) |
Remove most custom template functions from html templating
Diffstat (limited to 'src')
-rw-r--r-- | src/http/tpl.go | 18 | ||||
-rw-r--r-- | src/http/tpl/base.html | 5 | ||||
-rw-r--r-- | src/http/tpl/gemini-cta.html | 2 | ||||
-rw-r--r-- | src/http/tpl/post.html | 2 | ||||
-rw-r--r-- | src/render/methods.go | 4 |
5 files changed, 10 insertions, 21 deletions
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 @@ <head> <title>{{ .Title }}</title> - <style>{{ StaticInlineCSS "new.css" }}</style> - <style>{{ StaticInlineCSS "mediocre.css" }}</style> - + <link rel="stylesheet" type="text/css" href="{{ StaticURL "new.css" }}" /> + <link rel="stylesheet" type="text/css" href="{{ StaticURL "mediocre.css" }}" /> <link rel="apple-touch-icon" sizes="180x180" href="{{ StaticURL "favicon/apple-touch-icon.png" }}"> <link rel="icon" type="image/png" sizes="32x32" href="{{ StaticURL "favicon/favicon-32x32.png" }}"> <link rel="icon" type="image/png" sizes="16x16" href="{{ StaticURL "favicon/favicon-16x16.png" }}"> 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 @@ <p> This site can also be accessed via the gemini protocol: - <a href="{{ BlogGeminiURL "/" | SafeURL }}"> + <a href="{{ BlogGeminiURL "/" | .URLIsSafe }}"> {{ BlogGeminiURL "/" }} </a> </p> 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 }} <p><em> - Published {{ DateTimeFormat $post.PublishedAt }} + Published {{ $post.PublishedAt.Format "2006-01-02" }} </em></p> {{- 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) +} |