new.go (view raw)
1package main
2
3import (
4 "fmt"
5 "io/ioutil"
6 "os"
7 "path/filepath"
8 "strings"
9 "time"
10)
11
12func viteNew(path string) {
13 _, file := filepath.Split(path)
14 url := strings.TrimSuffix(file, filepath.Ext(file))
15
16 content := fmt.Sprintf(`---
17template:
18url: %s
19title:
20subtitle:
21date: %s
22---`, url, time.Now().Format("01-02-2006"))
23
24 _, err := os.Create(path)
25 if err != nil {
26 printErr(err)
27 return
28 }
29 ioutil.WriteFile(path, []byte(content), 0644)
30 printMsg("created:", path)
31}