-
Notifications
You must be signed in to change notification settings - Fork 4
/
site.go
34 lines (31 loc) · 908 Bytes
/
site.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Package controller - Content managed by Project Forge, see [projectforge.md] for details.
package controller
import (
"net/http"
"strings"
"projectforge.dev/projectforge/app"
"projectforge.dev/projectforge/app/controller/cutil"
"projectforge.dev/projectforge/app/site"
"projectforge.dev/projectforge/app/util"
"projectforge.dev/projectforge/views/verror"
)
func Site(w http.ResponseWriter, r *http.Request) {
path := util.StringSplitAndTrim(r.URL.Path, "/")
action := "site"
if len(path) > 0 {
action += "." + strings.Join(path, ".")
}
ActSite(action, w, r, func(as *app.State, ps *cutil.PageState) (string, error) {
redir, page, bc, err := site.Handle(path, as, ps)
if err != nil {
return "", err
}
if _, ok := page.(*verror.NotFound); ok {
w.WriteHeader(http.StatusNotFound)
}
if redir != "" {
return redir, nil
}
return Render(w, r, as, page, ps, bc...)
})
}