Add Write helper to template
Anirudh Oppiliappan x@icyphox.sh
Wed, 24 Jul 2024 09:21:03 +0300
3 files changed,
11 insertions(+),
18 deletions(-)
M
formats/markdown/markdown.go
→
formats/markdown/markdown.go
@@ -66,15 +66,7 @@ if err := tmpl.Load(tmplDir); err != nil {
return err } - w, err := os.Create(dest) - if err != nil { - return err - } - - if err = tmpl.ExecuteTemplate(w, metaTemplate, data); err != nil { - return err - } - return nil + return tmpl.Write(dest, metaTemplate, data) } // extract takes the source markdown page, extracts the frontmatter
M
formats/yaml/yaml.go
→
formats/yaml/yaml.go
@@ -51,15 +51,7 @@ if err := tmpl.Load(tmplDir); err != nil {
return err } - w, err := os.Create(dest) - if err != nil { - return err - } - - if err = tmpl.ExecuteTemplate(w, metaTemplate, data); err != nil { - return err - } - return nil + return tmpl.Write(dest, metaTemplate, data) } func (y *YAML) Render(dest string, data interface{}) error {
M
template/template.go
→
template/template.go
@@ -57,3 +57,12 @@ return err
} return nil } + +func (t *Tmpl) Write(dest string, name string, data interface{}) error { + w, err := os.Create(dest) + if err != nil { + return err + } + + return t.ExecuteTemplate(w, name, data) +}