Create new command
Anirudh Oppiliappan x@icyphox.sh
Fri, 30 Oct 2020 21:39:23 +0530
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) +}