theme base system

This commit is contained in:
Zeni Kim 2024-09-27 02:27:24 -05:00
parent 1172e23c16
commit 465e88bf40
7 changed files with 74 additions and 51 deletions

36
templates.go Normal file
View file

@ -0,0 +1,36 @@
// 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...))
}