From 57d220078c7fbb96d87242cdb20f91f297ace08c Mon Sep 17 00:00:00 2001 From: xing Date: Fri, 4 Nov 2022 12:22:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/templatefs.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/templates/templatefs.go b/templates/templatefs.go index e607ee2..599128a 100644 --- a/templates/templatefs.go +++ b/templates/templatefs.go @@ -2,10 +2,12 @@ package templates import ( "embed" + "fmt" "github.com/gin-gonic/gin/render" "html/template" "io/fs" "path/filepath" + "strings" ) //go:embed twentyfifteen @@ -21,13 +23,15 @@ func NewFsTemplate(funcMap template.FuncMap) *FsTemplate { } func (t *FsTemplate) SetTemplate() *FsTemplate { - mainTemplates, err := fs.Glob(TemplateFs, `twentyfifteen/*[^layout]/*.gohtml`) + mainTemplates, err := fs.Glob(TemplateFs, `*/*[^layout]/*.gohtml`) if err != nil { panic(err) } for _, include := range mainTemplates { 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 }