-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
66 lines (53 loc) · 1.35 KB
/
config.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
package main
import (
"io/ioutil"
"log"
"path/filepath"
"github.com/BurntSushi/toml"
)
type config struct {
Url string
OutputExtension string `toml:"output_extension"`
LinksBeginWithSlash bool `toml:"links_begin_with_slash"`
Rss rssConfig
Posts postsConfig
Static staticConfig
Build buildConfig
}
type staticConfig struct {
Copy []map[string]string
}
type buildConfig struct {
RemoveBuildDir bool `toml:"remove_build_dir"`
CopyStaticDirs bool `toml:"copy_static_dirs"`
}
type rssConfig struct {
GenerateRss bool `toml:"generate_rss"`
Title string
Description string
AuthorName string `toml:"author_name"`
AuthorEmail string `toml:"author_email"`
}
type postsConfig struct {
Slug string `toml:slug`
Title string `toml:title`
Description string `toml:description`
Keywords []string `toml:keywords`
}
func readConfig(project string) *config {
configPath := filepath.Join(project, "scipio.toml")
f, err := ioutil.ReadFile(configPath)
if err != nil {
log.Fatal("Config file scipio.toml does not exist ", err)
}
conf := &config{}
// Defaults
conf.Build.RemoveBuildDir = true
conf.Build.CopyStaticDirs = true
conf.OutputExtension = ".html"
conf.LinksBeginWithSlash = false
if _, err := toml.Decode(string(f), conf); err != nil {
log.Fatal("Failed to read the config file! ", err)
}
return conf
}