update config
parent
3dd946d0ca
commit
f5b4b43248
28
setup.go
28
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,
|
||||
|
|
Loading…
Reference in New Issue