1
0
mirror of https://git.sr.ht/~adnano/kiln synced 2024-11-23 17:12:18 +01:00

config: Create default configuration before parsing

This commit is contained in:
adnano 2021-03-20 23:57:16 -04:00
parent 713c1336fb
commit c966e9f815

@ -35,33 +35,33 @@ func (t Task) Format(p *Page) (string, []byte) {
return t.postProcess.Format(p)
}
// LoadConfig loads the configuration from the provided path.
func LoadConfig(path string) (*Config, error) {
// DefaultConfig returns the default configuration.
func DefaultConfig() *Config {
c := new(Config)
c.Feeds = make(map[string]string)
c.Tasks = make(map[string]*Task)
c.Tasks["gemini"] = &Task{
Input: ".gmi",
Output: ".gmi",
Template: ".gmi",
Destination: "public",
}
return c
}
// LoadConfig loads the configuration from the provided path.
func LoadConfig(path string) (*Config, error) {
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
c := DefaultConfig()
if _, err := toml.DecodeReader(f, c); err != nil {
return nil, err
}
// Add default task
// The toml library overwrites the map, so add default values after parsing
if _, ok := c.Tasks["gemini"]; !ok {
c.Tasks["gemini"] = &Task{
Input: ".gmi",
Output: ".gmi",
Template: ".gmi",
Destination: "public",
}
}
for _, task := range c.Tasks {
switch task.PostProcess {
case "":