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