commit
a9ba42c3d0
|
@ -28,7 +28,6 @@ func DELETE(w http.ResponseWriter, r *http.Request, c *config.Config) (int, erro
|
||||||
|
|
||||||
// Check for errors
|
// Check for errors
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.Write([]byte(err.Error()))
|
|
||||||
return 500, err
|
return 500, err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -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 {
|
if _, err := os.Stat(archetype + ".markdown"); err == nil {
|
||||||
err = utils.CopyFile(archetype+".markdown", filename)
|
err = utils.CopyFile(archetype+".markdown", filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.Write([]byte(err.Error()))
|
|
||||||
return http.StatusInternalServerError, err
|
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 {
|
if _, err := os.Stat(archetype + ".md"); err == nil {
|
||||||
err = utils.CopyFile(archetype+".md", filename)
|
err = utils.CopyFile(archetype+".md", filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.Write([]byte(err.Error()))
|
|
||||||
return http.StatusInternalServerError, err
|
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)
|
wf, err := os.Create(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.Write([]byte(err.Error()))
|
|
||||||
return http.StatusInternalServerError, err
|
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
|
// Parse the multipart form in the request
|
||||||
err := r.ParseMultipartForm(100000)
|
err := r.ParseMultipartForm(100000)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.Write([]byte(err.Error()))
|
|
||||||
return http.StatusInternalServerError, err
|
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
|
// Open the first file
|
||||||
var infile multipart.File
|
var infile multipart.File
|
||||||
if infile, err = hdr.Open(); nil != err {
|
if infile, err = hdr.Open(); nil != err {
|
||||||
w.Write([]byte(err.Error()))
|
|
||||||
return http.StatusInternalServerError, err
|
return http.StatusInternalServerError, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the file
|
// Create the file
|
||||||
var outfile *os.File
|
var outfile *os.File
|
||||||
if outfile, err = os.Create(c.Path + r.URL.Path + hdr.Filename); nil != err {
|
if outfile, err = os.Create(c.Path + r.URL.Path + hdr.Filename); nil != err {
|
||||||
w.Write([]byte(err.Error()))
|
|
||||||
return http.StatusInternalServerError, err
|
return http.StatusInternalServerError, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy the file content
|
// Copy the file content
|
||||||
if _, err = io.Copy(outfile, infile); nil != err {
|
if _, err = io.Copy(outfile, infile); nil != err {
|
||||||
w.Write([]byte(err.Error()))
|
|
||||||
return http.StatusInternalServerError, err
|
return http.StatusInternalServerError, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,21 +42,19 @@ func ParseHugo(c *setup.Controller) (*Config, error) {
|
||||||
conf.Styles = strings.TrimPrefix(conf.Styles, "/")
|
conf.Styles = strings.TrimPrefix(conf.Styles, "/")
|
||||||
// Add a beginning slash to make a
|
// Add a beginning slash to make a
|
||||||
conf.Styles = "/" + conf.Styles
|
conf.Styles = "/" + conf.Styles
|
||||||
case "args":
|
default:
|
||||||
if !c.NextArg() {
|
key := "--" + c.Val()
|
||||||
return nil, c.ArgErr()
|
value := "true"
|
||||||
|
|
||||||
|
if c.NextArg() {
|
||||||
|
value = c.Val()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the arguments and split the array
|
conf.Args = append(conf.Args, key, value)
|
||||||
args := strings.Split(c.Val(), " ")
|
|
||||||
for index, element := range args {
|
|
||||||
args[index] = strings.Replace(element, "\"", "", -1)
|
|
||||||
}
|
|
||||||
|
|
||||||
conf.Args = args
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
conf.Args = append([]string{"--source", conf.Path}, conf.Args...)
|
||||||
return conf, nil
|
return conf, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,6 @@ func POST(w http.ResponseWriter, r *http.Request, c *config.Config, filename str
|
||||||
case "frontmatter-only":
|
case "frontmatter-only":
|
||||||
f, code, err := parseFrontMatterOnlyFile(rawFile, filename)
|
f, code, err := parseFrontMatterOnlyFile(rawFile, filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.Write([]byte(err.Error()))
|
|
||||||
return code, err
|
return code, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +47,6 @@ func POST(w http.ResponseWriter, r *http.Request, c *config.Config, filename str
|
||||||
case "complete":
|
case "complete":
|
||||||
f, code, err := parseCompleteFile(r, c, rawFile, filename)
|
f, code, err := parseCompleteFile(r, c, rawFile, filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.Write([]byte(err.Error()))
|
|
||||||
return code, err
|
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)
|
err := ioutil.WriteFile(filename, file, 0666)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.Write([]byte(err.Error()))
|
|
||||||
return http.StatusInternalServerError, err
|
return http.StatusInternalServerError, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
5
hugo.go
5
hugo.go
|
@ -7,6 +7,7 @@
|
||||||
package hugo
|
package hugo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log"
|
||||||
"mime"
|
"mime"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
@ -141,6 +142,10 @@ func (h CaddyHugo) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error
|
||||||
utils.Run(h.Config)
|
utils.Run(h.Config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
return code, err
|
return code, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -170,10 +170,9 @@ func Run(c *config.Config) {
|
||||||
|
|
||||||
commands.MainSite = nil
|
commands.MainSite = nil
|
||||||
viper.Reset()
|
viper.Reset()
|
||||||
c.Args = append([]string{"--source", c.Path}, c.Args...)
|
|
||||||
commands.HugoCmd.ParseFlags(c.Args)
|
commands.HugoCmd.ParseFlags(c.Args)
|
||||||
if err := commands.HugoCmd.RunE(nil, nil); err != nil {
|
if err := commands.HugoCmd.RunE(nil, nil); err != nil {
|
||||||
log.Print(err)
|
log.Panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue