all repos — vite @ 45310dfe7ecd7b5407640287e4e7069a53cf7100

a fast (this time, actually) and minimal static site generator

Add Write helper to template
Anirudh Oppiliappan x@icyphox.sh
Wed, 24 Jul 2024 09:21:03 +0300
commit

45310dfe7ecd7b5407640287e4e7069a53cf7100

parent

c6535b7c59b827e8ff6b172a8779996ef7ee32be

3 files changed, 11 insertions(+), 18 deletions(-)

jump to
M formats/markdown/markdown.goformats/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.goformats/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.gotemplate/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) +}