remove panicks and fix setup

This commit is contained in:
Henrique Dias 2016-07-02 23:29:47 +01:00
parent fd24071850
commit acfda6b4b7
2 changed files with 24 additions and 21 deletions

View File

@ -133,7 +133,7 @@ func RunHugo(c *Config, force bool) {
} }
if err := commands.Run(c.Hugo, c.Args, c.Root); err != nil { if err := commands.Run(c.Hugo, c.Args, c.Root); err != nil {
log.Panic(err) log.Println(err)
} }
} }

View File

@ -1,6 +1,7 @@
package hugo package hugo
import ( import (
"fmt"
"io/ioutil" "io/ioutil"
"log" "log"
"net/http" "net/http"
@ -59,7 +60,7 @@ func setup(c *caddy.Controller) error {
if create { if create {
err := commands.Run(conf.Hugo, []string{"new", "site", conf.Root, "--force"}, ".") err := commands.Run(conf.Hugo, []string{"new", "site", conf.Root, "--force"}, ".")
if err != nil { if err != nil {
log.Panic(err) log.Fatal(err)
} }
} }
@ -67,16 +68,16 @@ func setup(c *caddy.Controller) error {
bytes, err := ioutil.ReadFile(filepath.Clean(conf.Root + "/config." + format)) bytes, err := ioutil.ReadFile(filepath.Clean(conf.Root + "/config." + format))
if err != nil { if err != nil {
log.Panic(err) log.Println(err)
} fmt.Printf("Can't get the default frontmatter from the configuration. %s will be used.\n", format)
} else {
bytes = directory.AppendFrontMatterRune(bytes, format) bytes = directory.AppendFrontMatterRune(bytes, format)
f, err := frontmatter.Unmarshal(bytes) f, err := frontmatter.Unmarshal(bytes)
if err != nil { if err != nil {
log.Panic(err) log.Println(err)
} fmt.Printf("Can't get the default frontmatter from the configuration. %s will be used.\n", format)
} else {
kind := reflect.TypeOf(f) kind := reflect.TypeOf(f)
if kind == reflect.TypeOf(map[interface{}]interface{}{}) { if kind == reflect.TypeOf(map[interface{}]interface{}{}) {
@ -89,6 +90,8 @@ func setup(c *caddy.Controller) error {
format = val.(string) format = val.(string)
} }
} }
}
}
// Generates the Hugo website for the first time the plugin is activated. // Generates the Hugo website for the first time the plugin is activated.
go RunHugo(conf, true) go RunHugo(conf, true)