2015-09-12 08:52:41 +00:00
|
|
|
package hugo
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2015-09-12 10:33:39 +00:00
|
|
|
"github.com/spf13/hugo/commands"
|
|
|
|
|
2015-09-12 08:52:41 +00:00
|
|
|
"github.com/mholt/caddy/config/setup"
|
|
|
|
"github.com/mholt/caddy/middleware"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Setup(c *setup.Controller) (middleware.Middleware, error) {
|
2015-09-12 10:33:39 +00:00
|
|
|
for c.Next() {
|
|
|
|
commands.Execute()
|
|
|
|
}
|
|
|
|
|
2015-09-12 08:52:41 +00:00
|
|
|
return func(next middleware.Handler) middleware.Handler {
|
|
|
|
return &handler{}
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type handler struct{}
|
|
|
|
|
|
|
|
func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
|
2015-09-12 10:33:39 +00:00
|
|
|
http.ServeFile(w, r, "public"+r.URL.Path)
|
2015-09-12 08:52:41 +00:00
|
|
|
return 200, nil
|
|
|
|
}
|