filebrowser/config/config.go

69 lines
1.3 KiB
Go
Raw Normal View History

2015-09-20 16:15:21 +08:00
package config
import (
"strings"
"github.com/mholt/caddy/config/setup"
)
// Config is the add-on configuration set on Caddyfile
type Config struct {
2015-10-01 05:03:28 +08:00
Public string
Content string
Path string
2015-09-28 03:33:36 +08:00
Styles string
2015-09-27 20:20:05 +08:00
Command string
2015-10-01 05:03:28 +08:00
Hugo bool
2015-09-20 16:15:21 +08:00
}
2015-09-27 20:20:05 +08:00
// ParseCMS parses the configuration file
func ParseCMS(c *setup.Controller) (*Config, error) {
2015-10-01 05:03:28 +08:00
conf := &Config{
Public: strings.Replace(c.Root, "./", "", -1),
Content: "content",
Hugo: true,
Path: "./",
}
2015-09-20 16:15:21 +08:00
for c.Next() {
2015-10-01 05:03:28 +08:00
args := c.RemainingArgs()
switch len(args) {
case 1:
conf.Path = args[0]
conf.Path = strings.TrimSuffix(conf.Path, "/")
conf.Path += "/"
}
2015-09-20 16:15:21 +08:00
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-28 02:49:58 +08:00
case "content":
if !c.NextArg() {
return nil, c.ArgErr()
}
conf.Content = c.Val()
2015-09-27 20:20:05 +08:00
case "command":
if !c.NextArg() {
return nil, c.ArgErr()
}
conf.Command = c.Val()
2015-10-01 05:03:28 +08:00
if conf.Command != "" && !strings.HasPrefix(conf.Command, "-") {
conf.Hugo = false
2015-09-21 05:00:25 +08:00
}
2015-09-20 16:15:21 +08:00
}
}
}
return conf, nil
}