all repos — searchix @ 149cbe7681607eb48f47df14c7a39e6f289fb7b6

Search engine for NixOS, nix-darwin, home-manager and NUR users

refactor(templates): render partials with less hackiness

Alan Pearce
commit

149cbe7681607eb48f47df14c7a39e6f289fb7b6

parent

5624cf8f6427064dd17de40acd1d3fdfe8332e96

1 file changed, 8 insertions(+), 5 deletions(-)

changed files
M internal/server/templates.gointernal/server/templates.go
@@ -47,7 +47,10 @@ return input
}, } -func loadTemplate(layoutFile string, filename string) (*template.Template, error) { +func loadTemplate( + layoutFile string, + filenames ...string, +) (*template.Template, error) { tpl := template.New("index.gotmpl") tpl.Funcs(templateFuncs)
@@ -56,8 +59,8 @@ if err != nil {
return nil, errors.WithMessage(err, "could not parse layout template") } - if filename != "" { - _, err = tpl.ParseFS(frontend.Files, filename) + if len(filenames) > 0 { + _, err = tpl.ParseFS(frontend.Files, filenames...) if err != nil { return nil, errors.WithMessage(err, "could not parse template") }
@@ -72,7 +75,7 @@ templates := make(TemplateCollection, 0)
layoutFile := path.Join(templateDir, "index.gotmpl") - index, err := loadTemplate(layoutFile, "") + index, err := loadTemplate(layoutFile) if err != nil { return nil, err }
@@ -84,7 +87,7 @@ if err != nil {
return nil, errors.WithMessage(err, "could not glob block templates") } for _, fullname := range templatePaths { - tpl, err := loadTemplate(layoutFile, glob) + tpl, err := loadTemplate(layoutFile, glob, fullname) if err != nil { return nil, err }