This commit is contained in:
xing 2022-11-04 12:22:56 +08:00
parent d953133607
commit 57d220078c

View File

@ -2,10 +2,12 @@ package templates
import ( import (
"embed" "embed"
"fmt"
"github.com/gin-gonic/gin/render" "github.com/gin-gonic/gin/render"
"html/template" "html/template"
"io/fs" "io/fs"
"path/filepath" "path/filepath"
"strings"
) )
//go:embed twentyfifteen //go:embed twentyfifteen
@ -21,13 +23,15 @@ func NewFsTemplate(funcMap template.FuncMap) *FsTemplate {
} }
func (t *FsTemplate) SetTemplate() *FsTemplate { func (t *FsTemplate) SetTemplate() *FsTemplate {
mainTemplates, err := fs.Glob(TemplateFs, `twentyfifteen/*[^layout]/*.gohtml`) mainTemplates, err := fs.Glob(TemplateFs, `*/*[^layout]/*.gohtml`)
if err != nil { if err != nil {
panic(err) panic(err)
} }
for _, include := range mainTemplates { for _, include := range mainTemplates {
name := filepath.Base(include) name := filepath.Base(include)
t.Templates[include] = template.Must(template.New(name).Funcs(t.FuncMap).ParseFS(TemplateFs, include, "twentyfifteen/layout/*.gohtml")) c := strings.Split(include, "/")
base := c[0]
t.Templates[include] = template.Must(template.New(name).Funcs(t.FuncMap).ParseFS(TemplateFs, include, fmt.Sprintf("%s/layout/*.gohtml", base)))
} }
return t return t
} }