core/templates.go

37 lines
863 B
Go
Raw Normal View History

2024-09-27 03:27:24 -04:00
// 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...))
}