dynamically walks through view files in embedFS

Signed-off-by: Michael <michael.lindman@gmail.com>
This commit is contained in:
Michael 2021-04-17 23:17:17 +01:00
parent adf8750c31
commit 5769397142
1 changed files with 14 additions and 4 deletions

View File

@ -38,18 +38,28 @@ func Load(opts *Options) (*template.Template, error) {
}
func readFiles(basePath string, opts *Options) (*template.Template, error) {
var tpl *template.Template
var err error
var (
tpl *template.Template
err error
files []string
)
if !opts.DynamicReload {
if err := fs.WalkDir(opts.Fsys, basePath, func(path string, d fs.DirEntry, err error) error {
if !d.IsDir() {
files = append(files, path)
}
return nil
}); err != nil {
return nil, err
}
tpl, err = template.New(opts.BaseDir).
Funcs(FuncMap()).
Funcs(opts.FuncMap).
ParseFS(opts.Fsys, basePath+"/*.html", basePath+"/*/*.html", basePath+"/*/*/*.html")
ParseFS(opts.Fsys, files...)
if err != nil {
return nil, err
}
} else {
var files []string
if err := filepath.Walk(basePath, func(path string, info os.FileInfo, err error) error {
if !info.IsDir() {
files = append(files, path)