blogo/readConfig.go
readConfig.goRaw
1package main
2
3import (
4 "encoding/json"
5 "io/ioutil"
6)
7
8// Post is the struct for each post of the blog
9type Post struct {
10 Thumb string `json:"thumb"`
11 Md string `json:"md"`
12 MetaImg string `json:"metaimg"`
13 MetaDescr string `json:"metadescr"`
14 OutsideArticle string `json:"outsideArticle"`
15}
16
17// Config gets the config.json file into struct
18type Config struct {
19 Title string `json:"title"`
20 MetaImg string `json:"metaimg"`
21 MetaDescr string `json:"metadescr"`
22 RelativePath string `json:"relativePath"`
23 PostsDir string `json:"postsDir"`
24 AbsoluteUrl string `json:"absoluteUrl"`
25 IndexTemplate string `json:"indexTemplate"`
26 PostThumbTemplate string `json:"postThumbTemplate"`
27 Posts []Post `json:"posts"`
28 CopyRaw []string `json:"copyRaw"`
29 OutputDir string `json:"outputDir"`
30}
31
32var config Config
33
34func readConfig(path string) {
35 file, err := ioutil.ReadFile(path)
36 check(err)
37 content := string(file)
38 json.Unmarshal([]byte(content), &config)
39 if config.PostsDir != "" {
40 config.PostsDir += "/"
41 }
42 if config.OutputDir == "" {
43 config.OutputDir = defaultOutputDir
44 }
45}