/
goss.go
68 lines (62 loc) · 1.49 KB
/
goss.go
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
68
package main
import (
"fmt"
"os"
"gopkg.in/yaml.v3"
"github.com/urfave/cli/v2"
"github.com/brothertoad/btu"
"github.com/brothertoad/goss/gossutil"
)
const configFlag = "config"
const logLevelFlag = "log-level"
var config gossConfig
var globalData map[string]interface{}
func main() {
app := &cli.App {
Name: "goss",
Usage: "a simple static site generator",
Flags: []cli.Flag {
&cli.StringFlag {
Name: configFlag,
Usage: "configuration file",
},
&cli.StringFlag {
Name: logLevelFlag,
Usage: "log level",
},
&cli.BoolFlag {
Name: "yaml",
Usage: "print global data in yaml format",
},
},
Action: gossMain,
}
app.Run(os.Args)
}
func gossMain(c *cli.Context) error {
if c.String(logLevelFlag) != "" {
btu.SetLogLevelByName(c.String(logLevelFlag))
}
initConfig(&config)
if c.String(configFlag) != "" {
loadConfig(&config, c.String(configFlag), true)
}
createOutputDir(config.OutputDir, config.Clean)
executeCommand(config.Pre)
globalData = gossutil.LoadGlobalData(config.DataDir)
if c.Bool("yaml") {
bytes, err := yaml.Marshal(globalData)
btu.CheckError(err)
fmt.Printf("%s\n", string(bytes[:]))
}
processPages(config.PageDir, config.OutputDir, globalData)
executeCommand(config.Post)
return nil
}
func createOutputDir(outputDir string, clean bool) {
if clean {
err := os.RemoveAll(outputDir)
btu.CheckError(err)
}
btu.CreateDir(outputDir)
}