Files
filebrowser/hugo.go
T

44 lines
923 B
Go
Raw Normal View History

2015-09-12 09:52:41 +01:00
package hugo
import (
"net/http"
2015-09-12 18:58:10 +01:00
"strings"
2015-09-12 09:52:41 +01:00
2015-09-12 11:33:39 +01:00
"github.com/spf13/hugo/commands"
2015-09-12 09:52:41 +01:00
"github.com/mholt/caddy/config/setup"
"github.com/mholt/caddy/middleware"
)
2015-09-12 13:05:31 +01:00
// Setup function
2015-09-12 09:52:41 +01:00
func Setup(c *setup.Controller) (middleware.Middleware, error) {
2015-09-12 13:05:31 +01:00
commands.Execute()
2015-09-12 11:33:39 +01:00
2015-09-12 09:52:41 +01:00
return func(next middleware.Handler) middleware.Handler {
2015-09-12 18:58:10 +01:00
return &handler{Next: next}
2015-09-12 09:52:41 +01:00
}, nil
}
2015-09-12 14:08:48 +01:00
type handler struct{ Next middleware.Handler }
2015-09-12 09:52:41 +01:00
func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
2015-09-12 13:05:31 +01:00
if middleware.Path(r.URL.Path).Matches("/admin") {
2015-09-12 18:58:10 +01:00
if middleware.Path(r.URL.Path).Matches("/admin/new") {
w.Write([]byte("New"))
} else if middleware.Path(r.URL.Path).Matches("/admin/edit") {
var fileName string
fileName = strings.Replace(r.URL.Path, "/admin/edit", "", 1)
w.Write([]byte("Edit " + fileName))
} else {
w.Write([]byte("Admin"))
}
return 200, nil
2015-09-12 13:05:31 +01:00
}
2015-09-12 14:16:15 +01:00
return h.Next.ServeHTTP(w, r)
2015-09-12 13:05:31 +01:00
}