feat: ✨ búsqueda de todas las páginas y fragmentos en todos los niveles de profundidad
This commit is contained in:
parent
be1dc3ceff
commit
93dc58253b
37
render.go
37
render.go
@ -3,7 +3,6 @@ package gorender
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"html/template"
|
"html/template"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
@ -130,27 +129,41 @@ func (re *Render) Template(w http.ResponseWriter, r *http.Request, tmpl string,
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (re *Render) createTemplateCache() (TemplateCache, error) {
|
func findHTMLFiles(root string) ([]string, error) {
|
||||||
myCache := TemplateCache{}
|
var files []string
|
||||||
|
|
||||||
pagesTemplates, err := filepath.Glob(fmt.Sprintf("%s/*.html", re.PageTemplatesPath))
|
err := filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error {
|
||||||
if err != nil {
|
|
||||||
return myCache, err
|
|
||||||
}
|
|
||||||
|
|
||||||
files := []string{}
|
|
||||||
filepath.WalkDir(re.TemplatesPath, func(path string, file fs.DirEntry, err error) error {
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if !file.IsDir() {
|
|
||||||
slog.Info("file found", "path", path)
|
if !d.IsDir() && filepath.Ext(path) == ".html" {
|
||||||
files = append(files, path)
|
files = append(files, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return files, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (re *Render) createTemplateCache() (TemplateCache, error) {
|
||||||
|
myCache := TemplateCache{}
|
||||||
|
|
||||||
|
pagesTemplates, err := findHTMLFiles(re.PageTemplatesPath)
|
||||||
|
if err != nil {
|
||||||
|
return myCache, err
|
||||||
|
}
|
||||||
|
|
||||||
|
files, err := findHTMLFiles(re.TemplatesPath)
|
||||||
|
if err != nil {
|
||||||
|
return myCache, err
|
||||||
|
}
|
||||||
|
|
||||||
for function := range re.Functions {
|
for function := range re.Functions {
|
||||||
slog.Info("function found", "function", function)
|
slog.Info("function found", "function", function)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user