2015-09-20 08:15:21 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/mholt/caddy/config/setup"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Config is the add-on configuration set on Caddyfile
|
|
|
|
type Config struct {
|
|
|
|
Styles string
|
2015-09-20 21:00:25 +00:00
|
|
|
Flags []string
|
2015-09-20 08:15:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ParseHugo parses the configuration file
|
|
|
|
func ParseHugo(c *setup.Controller) (*Config, error) {
|
2015-09-20 09:33:23 +00:00
|
|
|
conf := &Config{
|
|
|
|
Styles: "",
|
|
|
|
}
|
2015-09-20 08:15:21 +00:00
|
|
|
|
|
|
|
for c.Next() {
|
|
|
|
for c.NextBlock() {
|
|
|
|
switch c.Val() {
|
|
|
|
case "styles":
|
|
|
|
if !c.NextArg() {
|
|
|
|
return nil, c.ArgErr()
|
|
|
|
}
|
|
|
|
conf.Styles = c.Val()
|
|
|
|
// Remove the beginning slash if it exists or not
|
|
|
|
conf.Styles = strings.TrimPrefix(conf.Styles, "/")
|
|
|
|
// Add a beginning slash to make a
|
|
|
|
conf.Styles = "/" + conf.Styles
|
2015-09-20 21:00:25 +00:00
|
|
|
case "flags":
|
|
|
|
conf.Flags = c.RemainingArgs()
|
|
|
|
if len(conf.Flags) == 0 {
|
|
|
|
return conf, c.ArgErr()
|
|
|
|
}
|
2015-09-20 08:15:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-20 21:00:25 +00:00
|
|
|
conf.parseFlags()
|
2015-09-20 08:15:21 +00:00
|
|
|
return conf, nil
|
|
|
|
}
|
2015-09-20 21:00:25 +00:00
|
|
|
|
|
|
|
func (c *Config) parseFlags() {
|
|
|
|
for index, element := range c.Flags {
|
|
|
|
c.Flags[index] = strings.Replace(element, "\"", "", -1)
|
|
|
|
}
|
|
|
|
}
|