dynamically walks through view files in embedFS
Signed-off-by: Michael <michael.lindman@gmail.com>
This commit is contained in:
parent
adf8750c31
commit
5769397142
|
@ -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)
|
||||
|
|
Reference in New Issue