aboutsummaryrefslogtreecommitdiffstats
path: root/main.go
blob: a3ee11cbac51feba81a859052e3481f5b64f5d23 (plain) (blame)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
snkt is a static site generator for simple blog-like sites with a focus on simplicity and efficiency.
*/
package main

import (
	"flag"
	"adammathes.com/snkt/config"
	"adammathes.com/snkt/render"
	"adammathes.com/snkt/site"
	"adammathes.com/snkt/web"
	"adammathes.com/snkt/vlog"
	"fmt"
)

func main() {

	var configFile, init_dir string
	var build, preview, version, verbose, help bool
	
	flag.StringVar(&configFile, "c", "config.yml", "`configuration` file")
	flag.StringVar(&init_dir, "init", "", "initialize new site at `directory`")
	flag.BoolVar(&build, "b", false, "build site")
	flag.BoolVar(&preview, "p", false, "preview site with local HTTP server")
	flag.BoolVar(&version, "v", false, "print version number")
	flag.BoolVar(&help, "h", false, "help")
	flag.BoolVar(&verbose, "verbose", false, "log actions during build")
	flag.Parse()

	if !help && !build && !preview && !version && init_dir=="" {
		flag.Usage()
		return
	}
	if(init_dir != "") {
		fmt.Printf("initializing new site in %s\n", init_dir)
		site.Init(init_dir)
		return
	}
	if(version) {
		fmt.Printf("0.1 alpha\n")
		return
	}
	if(help) {
		fmt.Printf("in case of emergency, break computer \n")
		return
	}
	config.Init(configFile)
	if(verbose) {
		config.Config.Verbose = true
	}

	render.Init()
	if build {
		vlog.Printf("building site...\n")
		var s site.Site
		vlog.Printf("reading posts...\n")
		s.Read()
		vlog.Printf("writing posts and archives...\n")
		s.Write()
	}

	if preview {
		fmt.Printf("spawning preview at [%s] of [%s]\n",
			config.Config.PreviewDir, config.Config.PreviewServer)
		web.Serve(config.Config.PreviewServer, config.Config.PreviewDir)
	}
}