From 93dc58253bd28c980eb4086b47bd5f35f35283f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20P=C3=A9rez?= Date: Wed, 28 Aug 2024 20:49:45 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20:sparkles:=20b=C3=BAsqueda=20de=20todas?= =?UTF-8?q?=20las=20p=C3=A1ginas=20y=20fragmentos=20en=20todos=20los=20niv?= =?UTF-8?q?eles=20de=20profundidad?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- render.go | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/render.go b/render.go index a43a44b..9fb9416 100644 --- a/render.go +++ b/render.go @@ -3,7 +3,6 @@ package gorender import ( "bytes" "errors" - "fmt" "html/template" "io/fs" "log/slog" @@ -130,27 +129,41 @@ func (re *Render) Template(w http.ResponseWriter, r *http.Request, tmpl string, return nil } -func (re *Render) createTemplateCache() (TemplateCache, error) { - myCache := TemplateCache{} +func findHTMLFiles(root string) ([]string, error) { + var files []string - pagesTemplates, err := filepath.Glob(fmt.Sprintf("%s/*.html", re.PageTemplatesPath)) - if err != nil { - return myCache, err - } - - files := []string{} - filepath.WalkDir(re.TemplatesPath, func(path string, file fs.DirEntry, err error) error { + err := filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error { if err != nil { return err } - if !file.IsDir() { - slog.Info("file found", "path", path) + + if !d.IsDir() && filepath.Ext(path) == ".html" { files = append(files, path) } 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 { slog.Info("function found", "function", function) }