an updated and hopefully faster version of the ST Toolbox
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

55 lines
938 B

package root
import (
"embed"
"html/template"
"io/fs"
"log"
"path/filepath"
)
//go:embed templates
var webTemplateFS embed.FS
var WebTemplates *template.Template
// InitializeWebTemplates parses all HTML templates in the embedded filesystem
func InitializeWebTemplates() error {
var err error
WebTemplates, err = parseWebTemplates()
return err
}
func parseWebTemplates() (*template.Template, error) {
tmpl := template.New("")
err := fs.WalkDir(webTemplateFS, "templates", func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if d.IsDir() {
return nil
}
if filepath.Ext(path) != ".html" {
return nil
}
log.Printf("Parsing template: %s", path)
content, err := webTemplateFS.ReadFile(path)
if err != nil {
return err
}
_, err = tmpl.New(filepath.Base(path)).Parse(string(content))
return err
})
if err != nil {
return nil, err
}
return tmpl, nil
}