all repos — vite @ 54a85a9389fb5a2b778631f0822a5f783a231d5d

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

Create new command
Anirudh Oppiliappan x@icyphox.sh
Fri, 30 Oct 2020 21:39:23 +0530
commit

54a85a9389fb5a2b778631f0822a5f783a231d5d

parent

ddc00185b9902d70c044b9dd09eabd2dc30ca6e0

2 files changed, 33 insertions(+), 2 deletions(-)

jump to
M main.gomain.go

@@ -31,8 +31,8 @@ viteInit(initPath)

case "build": viteBuild() case "new": - // newPath := args[2] - // viteNew(newPath) + newPath := args[2] + viteNew(newPath) } }
A new.go

@@ -0,0 +1,31 @@

+package main + +import ( + "fmt" + "io/ioutil" + "os" + "path/filepath" + "strings" + "time" +) + +func viteNew(path string) { + _, file := filepath.Split(path) + url := strings.TrimSuffix(file, filepath.Ext(file)) + + content := fmt.Sprintf(`--- +template: +url: %s +title: +subtitle: +date: %s +---`, url, time.Now().Format("01-02-2006")) + + _, err := os.Create(path) + if err != nil { + printErr(err) + return + } + ioutil.WriteFile(path, []byte(content), 0644) + printMsg("created:", path) +}