From f5b4b4324832fa109623269a56924cb17948d92c Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Wed, 29 Jun 2016 10:45:15 +0100 Subject: [PATCH] update config --- setup.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/setup.go b/setup.go index b6f43708..f29b9447 100644 --- a/setup.go +++ b/setup.go @@ -5,16 +5,20 @@ import ( "log" "net/http" "os" + "path/filepath" "strings" "github.com/hacdias/caddy-filemanager" "github.com/hacdias/caddy-filemanager/config" + "github.com/hacdias/caddy-filemanager/directory" + "github.com/hacdias/caddy-filemanager/frontmatter" "github.com/hacdias/caddy-hugo/installer" "github.com/hacdias/caddy-hugo/utils/commands" "github.com/mholt/caddy" "github.com/mholt/caddy/caddyhttp/httpserver" ) +// AssetsURL is the base url for the assets const AssetsURL = "/_hugointernal" func init() { @@ -30,19 +34,24 @@ func setup(c *caddy.Controller) error { cnf := httpserver.GetConfig(c) conf, _ := parse(c, cnf.Root) + format := "config.toml" + // Checks if there is an Hugo website in the path that is provided. // If not, a new website will be created. create := true if _, err := os.Stat(conf.Root + "config.yaml"); err == nil { + format = "yaml" create = false } if _, err := os.Stat(conf.Root + "config.json"); err == nil { + format = "json" create = false } if _, err := os.Stat(conf.Root + "config.toml"); err == nil { + format = "toml" create = false } @@ -53,6 +62,24 @@ func setup(c *caddy.Controller) error { } } + // Get Default FrontMatter + bytes, err := ioutil.ReadFile(filepath.Clean(conf.Root + "/config." + format)) + + if err != nil { + log.Panic(err) + } + + bytes = directory.AppendFrontMatterRune(bytes, format) + f, err := frontmatter.Unmarshal(bytes) + + if err != nil { + log.Panic(err) + } + + if val, ok := f.(map[string]interface{})["metaDataFormat"]; ok { + format = val.(string) + } + // Generates the Hugo website for the first time the plugin is activated. go RunHugo(conf, true) @@ -66,6 +93,7 @@ func setup(c *caddy.Controller) error { config.Config{ HugoEnabled: true, PathScope: conf.Root, + FrontMatter: format, Root: http.Dir(conf.Root), BaseURL: conf.BaseURL, StyleSheet: conf.Styles,