diff options
author | Noah Loomans <noah@noahloomans.com> | 2019-12-21 20:44:44 +0100 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-12-22 18:24:05 -0500 |
commit | ec47d0b3842147a156216ed7b2630600bec73371 (patch) | |
tree | ae96cd34979ad071e8512f5e8c19ca789bd78629 | |
parent | 6d79d2e3759afd8c7e27b5f758e7f1e387134c40 (diff) |
allow custom date formats
This adds a new datef function instead of changing date function in an
effort to keep backwards compatibility.
datef is intentionally used in the example to make it clear to the user
that it is possible to set a custom date format.
-rw-r--r-- | in.html | 2 | ||||
-rw-r--r-- | openring.go | 3 |
2 files changed, 4 insertions, 1 deletions
@@ -10,7 +10,7 @@ <small class="source"> via <a href="{{.SourceLink}}">{{.SourceTitle}}</a> </small> - <small class="date">{{.Date | date}}</small> + <small class="date">{{.Date | datef "January 2, 2006"}}</small> </div> {{end}} </section> diff --git a/openring.go b/openring.go index cbaba1f..4f74631 100644 --- a/openring.go +++ b/openring.go @@ -76,6 +76,9 @@ func main() { "date": func(t time.Time) string { return t.Format("January 2, 2006") }, + "datef": func(fmt string, t time.Time) string { + return t.Format(fmt) + }, }). Parse(string(input)) if err != nil { |