mirror of
https://codeberg.org/video-prize-ranch/rimgo.git
synced 2026-01-28 09:31:13 +00:00
45 lines
915 B
Go
45 lines
915 B
Go
package render
|
|
|
|
import (
|
|
"time"
|
|
|
|
"codeberg.org/rimgo/rimgo/utils"
|
|
"github.com/dustin/go-humanize"
|
|
"github.com/mailgun/raymond/v2"
|
|
)
|
|
|
|
func (r *renderer) registerHelpers() {
|
|
funcmap := map[string]any{
|
|
"noteq": noteq,
|
|
"ifNonZeroTime": ifNonZeroTime,
|
|
"relTime": relTime,
|
|
"rewriteUrl": rewriteUrl,
|
|
"sanitizeDescription": sanitizeDescription,
|
|
"sanitizeComment": sanitizeComment,
|
|
}
|
|
raymond.RegisterHelpers(funcmap)
|
|
}
|
|
|
|
func noteq(a, b any, options *raymond.Options) any {
|
|
if raymond.Str(a) != raymond.Str(b) {
|
|
return options.Fn()
|
|
}
|
|
return ""
|
|
}
|
|
func ifNonZeroTime(v any, options *raymond.Options) any {
|
|
if v.(time.Time).IsZero() {
|
|
return ""
|
|
}
|
|
return options.Fn()
|
|
}
|
|
func relTime(date time.Time) string {
|
|
return humanize.Time(date)
|
|
}
|
|
func rewriteUrl(link string) string {
|
|
r, err := utils.RewriteUrl(link)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return r
|
|
}
|