mirror of https://github.com/mickael-menu/zk
Rename the `{{date}}` helper to `{{format-date}}` (#274)
parent
142b636342
commit
15d4cfc921
File diff suppressed because one or more lines are too long
Before Width: | Height: | Size: 40 KiB After Width: | Height: | Size: 40 KiB |
File diff suppressed because one or more lines are too long
Before Width: | Height: | Size: 166 KiB After Width: | Height: | Size: 167 KiB |
@ -1,23 +0,0 @@
|
|||||||
package helpers
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/aymerick/raymond"
|
|
||||||
"github.com/mickael-menu/zk/internal/util"
|
|
||||||
dateutil "github.com/mickael-menu/zk/internal/util/date"
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
)
|
|
||||||
|
|
||||||
// RegisterGetDate registers the {{getdate}} template helper to use the `naturaldate` package to generate time.Time based on language strings.
|
|
||||||
// This can be used in combination with the `date` helper to generate dates in the user's language.
|
|
||||||
// {{date (get-date "last week") "timestamp"}}
|
|
||||||
func RegisterGetDate(logger util.Logger) {
|
|
||||||
raymond.RegisterHelper("get-date", func(natural string) time.Time {
|
|
||||||
date, err := dateutil.TimeFromNatural(natural)
|
|
||||||
if err != nil {
|
|
||||||
logger.Err(errors.Wrap(err, "the {{get-date}} template helper failed to parse the date"))
|
|
||||||
}
|
|
||||||
return date
|
|
||||||
})
|
|
||||||
}
|
|
Loading…
Reference in New Issue