44 lines
892 B
Go
44 lines
892 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"path/filepath"
|
||
|
"text/template"
|
||
|
)
|
||
|
|
||
|
type templateData struct {
|
||
|
}
|
||
|
|
||
|
func newTemplateCache() (map[string]*template.Template, error) {
|
||
|
cache := map[string]*template.Template{}
|
||
|
|
||
|
pages, err := filepath.Glob("./ui/html/pages/*.tmpl.html")
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
for _, page := range pages {
|
||
|
name := filepath.Base(page)
|
||
|
|
||
|
ts, err := template.ParseFiles("./ui/html/base.tmpl.html")
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
// parse all partials into the template set
|
||
|
ts, err = ts.ParseGlob("./ui/html/partials/*.tmpl.html")
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
// parse the page template last
|
||
|
ts, err = ts.ParseFiles(page)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
cache[name] = ts
|
||
|
}
|
||
|
|
||
|
return cache, nil
|
||
|
}
|