mirror of
https://git.sr.ht/~adnano/kiln
synced 2024-10-30 01:13:08 +00:00
config: Create default configuration before parsing
This commit is contained in:
parent
713c1336fb
commit
c966e9f815
32
config.go
32
config.go
|
@ -35,31 +35,31 @@ func (t Task) Format(p *Page) (string, []byte) {
|
||||||
return t.postProcess.Format(p)
|
return t.postProcess.Format(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadConfig loads the configuration from the provided path.
|
// DefaultConfig returns the default configuration.
|
||||||
func LoadConfig(path string) (*Config, error) {
|
func DefaultConfig() *Config {
|
||||||
c := new(Config)
|
c := new(Config)
|
||||||
c.Feeds = make(map[string]string)
|
c.Feeds = make(map[string]string)
|
||||||
c.Tasks = make(map[string]*Task)
|
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{
|
c.Tasks["gemini"] = &Task{
|
||||||
Input: ".gmi",
|
Input: ".gmi",
|
||||||
Output: ".gmi",
|
Output: ".gmi",
|
||||||
Template: ".gmi",
|
Template: ".gmi",
|
||||||
Destination: "public",
|
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 {
|
for _, task := range c.Tasks {
|
||||||
|
|
Loading…
Reference in a new issue