mirror of
https://codeberg.org/video-prize-ranch/rimgo.git
synced 2026-01-28 01:21:16 +00:00
refactor api package comments
* use encoding/json for comment parsing * refactor by moving loop code to an UnmarshalJSON * use a preallocated array and indices to maintain order while using goroutines again, this was removed a while ago * use new struct in comment.hbs and contextComment.hbs * rewriteUrl partial to reduce rimgo-specific code in api * move RenderError into pages package to avoid import cycle between render and utils
This commit is contained in:
@@ -1,10 +1,19 @@
|
||||
package render
|
||||
|
||||
import "github.com/mailgun/raymond/v2"
|
||||
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,
|
||||
"noteq": noteq,
|
||||
"ifNonZeroTime": ifNonZeroTime,
|
||||
"relTime": relTime,
|
||||
"rewriteUrl": rewriteUrl,
|
||||
}
|
||||
raymond.RegisterHelpers(funcmap)
|
||||
}
|
||||
@@ -15,3 +24,19 @@ func noteq(a, b any, options *raymond.Options) any {
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user