all repos — vite @ c720289599cf73858c8150484d1b3fdafcaa5595

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

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
 30
 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)
}