all repos — vite @ cf68ef9a7f922eb4b2dc23e4bb0c2a64060414a0

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

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}