/
config.go
48 lines (41 loc) · 1.1 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
package audiovisio
import (
"bytes"
"html/template"
"io/ioutil"
"gopkg.in/yaml.v2"
)
type Config struct {
Title string `yaml:"title"`
CSSInclude string `yaml:"css"`
JSInclude string `yaml:"js"`
HeaderContent template.HTML `yaml:"header"`
FooterContent template.HTML `yaml:"footer"`
ButtonStartTitle string `yaml:"button-start-title"`
PauseBeforeAudio int `yaml:"pause-before-audio"`
PauseAfterAudio int `yaml:"pause-after-audio"`
Leader Slide `yaml:"leader"`
Slides []Slide `yaml:"slides"`
Trailer Slide `yaml:"trailer"`
}
func (c *Config) postLoad() {
// propagate the pauses
changed := []Slide{}
for _, each := range c.Slides {
changed = append(changed, each.withPauses(c.PauseBeforeAudio, c.PauseAfterAudio))
}
c.Slides = changed
if len(c.ButtonStartTitle) == 0 {
c.ButtonStartTitle = "Start"
}
}
func LoadConfig(cfg string) *Config {
data, err := ioutil.ReadFile(cfg)
check(err)
dec := yaml.NewDecoder(bytes.NewReader(data))
config := new(Config)
err = dec.Decode(config)
check(err)
config.postLoad()
return config
}