2015-09-12 19:02:26 +00:00
|
|
|
package edit
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
2015-09-13 11:14:18 +00:00
|
|
|
|
|
|
|
"github.com/hacdias/caddy-hugo/page"
|
2015-09-12 19:02:26 +00:00
|
|
|
)
|
|
|
|
|
2015-09-13 11:28:26 +00:00
|
|
|
type info struct {
|
|
|
|
File string
|
2015-09-12 19:02:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Execute sth
|
|
|
|
func Execute(w http.ResponseWriter, r *http.Request, file string) (int, error) {
|
|
|
|
if r.Method == "POST" {
|
|
|
|
// it's saving the post
|
|
|
|
} else {
|
|
|
|
if _, err := os.Stat(file); os.IsNotExist(err) {
|
|
|
|
return 404, nil
|
|
|
|
}
|
|
|
|
|
2015-09-13 11:14:18 +00:00
|
|
|
file, err := ioutil.ReadFile(file)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return 500, err
|
|
|
|
}
|
|
|
|
|
2015-09-13 11:28:26 +00:00
|
|
|
inf := new(info)
|
|
|
|
inf.File = string(file)
|
2015-09-12 21:18:29 +00:00
|
|
|
|
2015-09-13 11:28:26 +00:00
|
|
|
page := new(page.Page)
|
2015-09-13 11:14:18 +00:00
|
|
|
page.Title = "Edit"
|
2015-09-13 11:28:26 +00:00
|
|
|
page.Body = inf
|
2015-09-13 11:14:18 +00:00
|
|
|
return page.Render("edit", w)
|
2015-09-12 19:02:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 200, nil
|
|
|
|
}
|