all repos — vite @ a741d82fd6191ccfbf8e9a480f8def8f170831da

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

Pre- and post-build actions
Anirudh Oppiliappan x@icyphox.sh
Fri, 30 Oct 2020 17:50:05 +0530
commit

a741d82fd6191ccfbf8e9a480f8def8f170831da

parent

c5d0a5c35c59e57f460bcaa1f6263e4e3253871f

2 files changed, 20 insertions(+), 3 deletions(-)

jump to
M build.gobuild.go

@@ -4,11 +4,24 @@ import (

"github.com/cross-cpm/go-shutil" "io/ioutil" "os" + "os/exec" "path/filepath" "strings" "text/template" ) +var cfg = parseConfig() + +func execute(cmds []string) { + for _, cmd := range cmds { + _, err := exec.Command(cmd).Output() + printMsg("executing:", cmd) + if err != nil { + printErr(err) + } + } +} + func processTemplate(tmplPath string) *template.Template { tmplFile := filepath.Join("templates", tmplPath) tmpl, err := template.ParseFiles(tmplFile)

@@ -42,13 +55,12 @@ }

os.MkdirAll(buildPath, 0755) - cfg := parseConfig() fm.Body = string(bodyHtml) // combine config and matter structs combined := struct { Cfg Config - Fm Matter + Fm Matter }{cfg, fm} htmlFile, err := os.Create(filepath.Join(buildPath, "index.html"))

@@ -69,6 +81,8 @@ htmlFile.Close()

} func viteBuild() { + printMsg("executing pre-build actions") + execute(cfg.Prebuild) err := filepath.Walk("./pages", func(path string, info os.FileInfo, err error) error { if err != nil { printErr(err)

@@ -103,4 +117,7 @@ _, err = shutil.CopyTree("static", filepath.Join("build", "static"), nil)

if err != nil { printErr(err) } + printMsg("build complete") + printMsg("executing post-build actions...") + execute(cfg.Postbuild) }
M markdown.gomarkdown.go

@@ -24,6 +24,6 @@ }),

), ), ), - bf.WithExtensions(bfExts), + bf.WithExtensions(bfExts), ) }