~adnano/kiln

746ba7c4a967d5db59c2a556060ef6cc43da1e65 — Adnan Maolood 29 days ago 4ca3833
config: Create default configuration before parsing
1 files changed, 13 insertions(+), 13 deletions(-)

M config.go
M config.go => config.go +13 -13
@@ 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 "":