config: Create default configuration before parsing

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

View file

@ -35,31 +35,31 @@ 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)
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
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",
}
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
}
for _, task := range c.Tasks {