optimize code

This commit is contained in:
xing 2024-01-24 00:25:37 +08:00
parent 20ea36c727
commit 802c7c7dcc
2 changed files with 2 additions and 6 deletions

View File

@ -26,7 +26,6 @@ func BuildTemplate() *multipTemplate.MultipleFsTemplate {
}
} else {
multiple = multipTemplate.NewFsTemplates(TemplateFs, templates)
multiple.FuncMap = FuncMap()
commonTemplate(multiple)
}
@ -53,10 +52,11 @@ func commonTemplate(t *multipTemplate.MultipleFsTemplate) {
if err != nil {
panic(err)
}
funMap := FuncMap()
for _, main := range m {
file := filepath.Base(main)
dir := strings.Split(main, "/")[0]
templ := template.Must(template.New(file).Funcs(t.FuncMap).ParseFS(t.Fs, main, filepath.Join(dir, "layout/*.gohtml"), "wp/template.gohtml"))
templ := template.Must(template.New(file).Funcs(funMap).ParseFS(t.Fs, main, filepath.Join(dir, "layout/*.gohtml"), "wp/template.gohtml"))
t.SetTemplate(main, templ)
}
}

View File

@ -10,7 +10,6 @@ import (
type MultipleFileTemplate struct {
Template maps
FuncMap template.FuncMap
}
type MultipleFsTemplate struct {
MultipleFileTemplate
@ -52,14 +51,12 @@ func (t *MultipleFsTemplate) AppendTemplate(name string, templates ...string) *M
func NewFileTemplates(m maps) *MultipleFileTemplate {
return &MultipleFileTemplate{
Template: m,
FuncMap: make(template.FuncMap),
}
}
func NewFsTemplate(f embed.FS) *MultipleFsTemplate {
return &MultipleFsTemplate{
MultipleFileTemplate: MultipleFileTemplate{
Template: TemplateMaps(make(map[string]*template.Template)),
FuncMap: make(template.FuncMap),
},
Fs: f,
}
@ -68,7 +65,6 @@ func NewFsTemplates(f embed.FS, m maps) *MultipleFsTemplate {
return &MultipleFsTemplate{
MultipleFileTemplate: MultipleFileTemplate{
Template: m,
FuncMap: make(template.FuncMap),
},
Fs: f,
}