2023-01-18 15:02:59 +00:00
|
|
|
package theme
|
2023-01-17 15:18:31 +00:00
|
|
|
|
|
|
|
import (
|
2023-04-15 16:57:50 +00:00
|
|
|
"github.com/fthvgb1/wp-go/internal/pkg/models"
|
2023-01-18 15:02:59 +00:00
|
|
|
"github.com/fthvgb1/wp-go/internal/wpconfig"
|
2023-01-17 15:18:31 +00:00
|
|
|
"html/template"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2023-01-21 06:49:24 +00:00
|
|
|
var comFn = template.FuncMap{
|
2023-01-17 15:18:31 +00:00
|
|
|
"unescaped": func(s string) any {
|
|
|
|
return template.HTML(s)
|
|
|
|
},
|
|
|
|
"dateCh": func(t time.Time) any {
|
|
|
|
return t.Format("2006年 01月 02日")
|
|
|
|
},
|
2023-03-06 15:43:58 +00:00
|
|
|
"timeFormat": func(t time.Time, format string) any {
|
|
|
|
return t.Format(format)
|
|
|
|
},
|
2023-01-17 15:18:31 +00:00
|
|
|
"getOption": func(k string) string {
|
2023-02-20 17:07:32 +00:00
|
|
|
return wpconfig.GetOption(k)
|
2023-01-17 15:18:31 +00:00
|
|
|
},
|
2023-01-19 06:12:59 +00:00
|
|
|
"getLang": wpconfig.GetLang,
|
2023-04-15 16:57:50 +00:00
|
|
|
"postsFn": postsFn,
|
|
|
|
"exec": func(fn func() string) string {
|
|
|
|
return fn()
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func postsFn(fn func(models.Posts) string, a models.Posts) string {
|
|
|
|
return fn(a)
|
2023-01-17 15:18:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func FuncMap() template.FuncMap {
|
2023-01-21 06:49:24 +00:00
|
|
|
return comFn
|
2023-01-17 15:18:31 +00:00
|
|
|
}
|
|
|
|
|
2023-01-26 17:03:41 +00:00
|
|
|
func addTemplateFunc(fnName string, fn any) {
|
2023-01-21 06:49:24 +00:00
|
|
|
if _, ok := comFn[fnName]; ok {
|
2023-01-18 15:02:59 +00:00
|
|
|
panic("exists same name func")
|
2023-01-17 15:18:31 +00:00
|
|
|
}
|
2023-01-21 06:49:24 +00:00
|
|
|
comFn[fnName] = fn
|
2023-01-17 15:18:31 +00:00
|
|
|
}
|