2015-09-27 05:02:49 +08:00
|
|
|
package browse
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"text/template"
|
|
|
|
|
2015-10-18 22:10:32 +08:00
|
|
|
"github.com/hacdias/caddy-hugo/config"
|
|
|
|
"github.com/hacdias/caddy-hugo/utils"
|
2015-09-27 05:02:49 +08:00
|
|
|
"github.com/mholt/caddy/middleware"
|
|
|
|
"github.com/mholt/caddy/middleware/browse"
|
|
|
|
)
|
|
|
|
|
|
|
|
// GET handles the GET method on browse page
|
|
|
|
func GET(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error) {
|
|
|
|
functions := template.FuncMap{
|
|
|
|
"CanBeEdited": utils.CanBeEdited,
|
|
|
|
"Defined": utils.Defined,
|
|
|
|
}
|
|
|
|
|
|
|
|
tpl, err := utils.GetTemplate(r, functions, "browse")
|
|
|
|
|
|
|
|
if err != nil {
|
2015-09-27 05:19:22 +08:00
|
|
|
return http.StatusInternalServerError, err
|
2015-09-27 05:02:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
b := browse.Browse{
|
|
|
|
Next: middleware.HandlerFunc(func(w http.ResponseWriter, r *http.Request) (int, error) {
|
|
|
|
return 404, nil
|
|
|
|
}),
|
2015-10-01 05:03:28 +08:00
|
|
|
Root: c.Path,
|
2015-09-27 05:02:49 +08:00
|
|
|
Configs: []browse.Config{
|
|
|
|
{
|
|
|
|
PathScope: "/",
|
|
|
|
Variables: c,
|
|
|
|
Template: tpl,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
IgnoreIndexes: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
return b.ServeHTTP(w, r)
|
|
|
|
}
|