2023-01-18 15:02:59 +00:00
|
|
|
package theme
|
2023-01-17 15:18:31 +00:00
|
|
|
|
|
|
|
import (
|
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"
|
|
|
|
)
|
|
|
|
|
|
|
|
var funcs = template.FuncMap{
|
|
|
|
"unescaped": func(s string) any {
|
|
|
|
return template.HTML(s)
|
|
|
|
},
|
|
|
|
"dateCh": func(t time.Time) any {
|
|
|
|
return t.Format("2006年 01月 02日")
|
|
|
|
},
|
|
|
|
"getOption": func(k string) string {
|
|
|
|
return wpconfig.Options.Value(k)
|
|
|
|
},
|
2023-01-19 06:12:59 +00:00
|
|
|
"getLang": wpconfig.GetLang,
|
2023-01-17 15:18:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func FuncMap() template.FuncMap {
|
|
|
|
return funcs
|
|
|
|
}
|
|
|
|
|
2023-01-18 15:02:59 +00:00
|
|
|
func AddTemplateFunc(fnName string, fn any) {
|
2023-01-17 15:18:31 +00:00
|
|
|
if _, ok := funcs[fnName]; ok {
|
2023-01-18 15:02:59 +00:00
|
|
|
panic("exists same name func")
|
2023-01-17 15:18:31 +00:00
|
|
|
}
|
|
|
|
funcs[fnName] = fn
|
|
|
|
}
|