2015-09-18 15:49:53 +00:00
|
|
|
package editor
|
|
|
|
|
|
|
|
import (
|
2015-10-16 19:03:59 +00:00
|
|
|
"errors"
|
2015-09-18 15:49:53 +00:00
|
|
|
"net/http"
|
|
|
|
"strings"
|
|
|
|
|
2015-10-18 14:10:32 +00:00
|
|
|
"github.com/hacdias/caddy-hugo/config"
|
2015-09-18 15:49:53 +00:00
|
|
|
)
|
|
|
|
|
2016-03-12 09:25:15 +00:00
|
|
|
var (
|
|
|
|
filename string
|
|
|
|
conf *config.Config
|
|
|
|
)
|
|
|
|
|
2015-09-20 08:15:21 +00:00
|
|
|
// ServeHTTP serves the editor page
|
|
|
|
func ServeHTTP(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error) {
|
2016-03-12 09:25:15 +00:00
|
|
|
conf = c
|
2016-06-07 17:15:55 +00:00
|
|
|
filename = strings.Replace(r.URL.Path, c.Admin+"/edit/", "", 1)
|
2015-09-30 21:03:28 +00:00
|
|
|
filename = c.Path + filename
|
2015-09-18 15:49:53 +00:00
|
|
|
|
2015-09-26 21:02:49 +00:00
|
|
|
switch r.Method {
|
|
|
|
case "POST":
|
2016-03-12 09:25:15 +00:00
|
|
|
return POST(w, r)
|
2015-09-26 21:02:49 +00:00
|
|
|
case "GET":
|
2016-03-12 09:25:15 +00:00
|
|
|
return GET(w, r)
|
2015-09-19 13:25:35 +00:00
|
|
|
default:
|
2016-03-06 14:23:37 +00:00
|
|
|
return http.StatusMethodNotAllowed, errors.New("Invalid method.")
|
2015-09-19 13:25:35 +00:00
|
|
|
}
|
2015-09-19 13:47:59 +00:00
|
|
|
}
|