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.
This commit is contained in:
parent
6d79d2e375
commit
ec47d0b384
2 changed files with 4 additions and 1 deletions
2
in.html
2
in.html
|
@ -10,7 +10,7 @@
|
||||||
<small class="source">
|
<small class="source">
|
||||||
via <a href="{{.SourceLink}}">{{.SourceTitle}}</a>
|
via <a href="{{.SourceLink}}">{{.SourceTitle}}</a>
|
||||||
</small>
|
</small>
|
||||||
<small class="date">{{.Date | date}}</small>
|
<small class="date">{{.Date | datef "January 2, 2006"}}</small>
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
</section>
|
</section>
|
||||||
|
|
|
@ -76,6 +76,9 @@ func main() {
|
||||||
"date": func(t time.Time) string {
|
"date": func(t time.Time) string {
|
||||||
return t.Format("January 2, 2006")
|
return t.Format("January 2, 2006")
|
||||||
},
|
},
|
||||||
|
"datef": func(fmt string, t time.Time) string {
|
||||||
|
return t.Format(fmt)
|
||||||
|
},
|
||||||
}).
|
}).
|
||||||
Parse(string(input))
|
Parse(string(input))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue