Merge pull request #48 from hacdias/dev

Update Master
pull/60/head
Henrique Dias 2016-02-20 10:55:08 +00:00
commit a9ba42c3d0
6 changed files with 14 additions and 23 deletions

View File

@ -28,7 +28,6 @@ func DELETE(w http.ResponseWriter, r *http.Request, c *config.Config) (int, erro
// Check for errors
if err != nil {
w.Write([]byte(err.Error()))
return 500, err
}
} else {

View File

@ -63,7 +63,6 @@ func POST(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error)
if _, err := os.Stat(archetype + ".markdown"); err == nil {
err = utils.CopyFile(archetype+".markdown", filename)
if err != nil {
w.Write([]byte(err.Error()))
return http.StatusInternalServerError, err
}
@ -77,7 +76,6 @@ func POST(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error)
if _, err := os.Stat(archetype + ".md"); err == nil {
err = utils.CopyFile(archetype+".md", filename)
if err != nil {
w.Write([]byte(err.Error()))
return http.StatusInternalServerError, err
}
@ -90,7 +88,6 @@ func POST(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error)
wf, err := os.Create(filename)
if err != nil {
w.Write([]byte(err.Error()))
return http.StatusInternalServerError, err
}
@ -106,7 +103,6 @@ func upload(w http.ResponseWriter, r *http.Request, c *config.Config) (int, erro
// Parse the multipart form in the request
err := r.ParseMultipartForm(100000)
if err != nil {
w.Write([]byte(err.Error()))
return http.StatusInternalServerError, err
}
@ -117,20 +113,17 @@ func upload(w http.ResponseWriter, r *http.Request, c *config.Config) (int, erro
// Open the first file
var infile multipart.File
if infile, err = hdr.Open(); nil != err {
w.Write([]byte(err.Error()))
return http.StatusInternalServerError, err
}
// Create the file
var outfile *os.File
if outfile, err = os.Create(c.Path + r.URL.Path + hdr.Filename); nil != err {
w.Write([]byte(err.Error()))
return http.StatusInternalServerError, err
}
// Copy the file content
if _, err = io.Copy(outfile, infile); nil != err {
w.Write([]byte(err.Error()))
return http.StatusInternalServerError, err
}

View File

@ -42,21 +42,19 @@ func ParseHugo(c *setup.Controller) (*Config, error) {
conf.Styles = strings.TrimPrefix(conf.Styles, "/")
// Add a beginning slash to make a
conf.Styles = "/" + conf.Styles
case "args":
if !c.NextArg() {
return nil, c.ArgErr()
default:
key := "--" + c.Val()
value := "true"
if c.NextArg() {
value = c.Val()
}
// Get the arguments and split the array
args := strings.Split(c.Val(), " ")
for index, element := range args {
args[index] = strings.Replace(element, "\"", "", -1)
}
conf.Args = args
conf.Args = append(conf.Args, key, value)
}
}
}
conf.Args = append([]string{"--source", conf.Path}, conf.Args...)
return conf, nil
}

View File

@ -34,7 +34,6 @@ func POST(w http.ResponseWriter, r *http.Request, c *config.Config, filename str
case "frontmatter-only":
f, code, err := parseFrontMatterOnlyFile(rawFile, filename)
if err != nil {
w.Write([]byte(err.Error()))
return code, err
}
@ -48,7 +47,6 @@ func POST(w http.ResponseWriter, r *http.Request, c *config.Config, filename str
case "complete":
f, code, err := parseCompleteFile(r, c, rawFile, filename)
if err != nil {
w.Write([]byte(err.Error()))
return code, err
}
@ -61,7 +59,6 @@ func POST(w http.ResponseWriter, r *http.Request, c *config.Config, filename str
err := ioutil.WriteFile(filename, file, 0666)
if err != nil {
w.Write([]byte(err.Error()))
return http.StatusInternalServerError, err
}

View File

@ -7,6 +7,7 @@
package hugo
import (
"log"
"mime"
"net/http"
"os"
@ -141,6 +142,10 @@ func (h CaddyHugo) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error
utils.Run(h.Config)
}
if err != nil {
log.Panic(err)
}
return code, err
}

View File

@ -170,10 +170,9 @@ func Run(c *config.Config) {
commands.MainSite = nil
viper.Reset()
c.Args = append([]string{"--source", c.Path}, c.Args...)
commands.HugoCmd.ParseFlags(c.Args)
if err := commands.HugoCmd.RunE(nil, nil); err != nil {
log.Print(err)
log.Panic(err)
}
}