all repos — vite @ 50ebf6bea9b02cef812535292204a4a05fe084c5

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

commands/new.go (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
package commands

import (
	"fmt"
	"os"
	"path/filepath"
	"strings"
	"time"
)

func New(path string) error {
	_, file := filepath.Split(path)
	url := strings.TrimSuffix(file, filepath.Ext(file))

	content := fmt.Sprintf(`---
template:
slug: %s
title:
subtitle:
date: %s
---`, url, time.Now().Format("2006-01-02"))

	_, err := os.Create(path)
	if err != nil {
		return err
	}
	os.WriteFile(path, []byte(content), 0755)
	return nil
}