1
0
Fork 0
forked from goffee/core
core/templates.go
2024-09-27 02:27:24 -05:00

36 lines
863 B
Go

// Copyright (c) 2024 Zeni Kim <zenik@smarteching.com>
// Use of this source code is governed by MIT-style
// license that can be found in the LICENSE file.
package core
import (
"embed"
"html/template"
"io/fs"
"strings"
)
var tmpl *template.Template = nil
func NewTemplates(components embed.FS, templates embed.FS) {
// templates
var paths []string
fs.WalkDir(components, ".", func(path string, d fs.DirEntry, err error) error {
if strings.Contains(d.Name(), ".html") {
paths = append(paths, path)
}
return nil
})
var pathst []string
fs.WalkDir(templates, ".", func(patht string, d fs.DirEntry, err error) error {
if strings.Contains(d.Name(), ".html") {
pathst = append(pathst, patht)
}
return nil
})
tmpla := template.Must(template.ParseFS(components, paths...))
tmpl = template.Must(tmpla.ParseFS(templates, pathst...))
}