mirror of
https://git.sr.ht/~adnano/kiln
synced 2024-10-30 09:23:09 +00:00
f6b2772c73
This reverts commit bf4ad9816e
.
55 lines
1.1 KiB
Go
55 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"text/template"
|
|
|
|
"github.com/pelletier/go-toml"
|
|
)
|
|
|
|
// Config contains site configuration.
|
|
type Config struct {
|
|
Title string `toml:"title"` // site title
|
|
URLs []string `toml:"urls"` // site URLs
|
|
Feeds map[string]string `toml:"feeds"` // site feeds
|
|
Templates *Templates `toml:"-"` // site templates
|
|
}
|
|
|
|
// LoadConfig loads the configuration from the provided path.
|
|
func LoadConfig(path string) (*Config, error) {
|
|
c := new(Config)
|
|
f, err := os.Open(path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer f.Close()
|
|
|
|
if err := toml.NewDecoder(f).Decode(c); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return c, nil
|
|
}
|
|
|
|
// LoadTemplates loads templates from the provided path.
|
|
func (c *Config) LoadTemplates(path string) error {
|
|
// Site contains site metadata passed to templates
|
|
type Site struct {
|
|
Title string
|
|
URLs []string
|
|
}
|
|
|
|
// Load templates
|
|
c.Templates = NewTemplates()
|
|
c.Templates.Funcs(template.FuncMap{
|
|
"site": func() Site {
|
|
return Site{
|
|
Title: c.Title,
|
|
URLs: c.URLs,
|
|
}
|
|
},
|
|
})
|
|
c.Templates.LoadDefault()
|
|
return c.Templates.Load(path)
|
|
}
|