-
Notifications
You must be signed in to change notification settings - Fork 4
/
docs.go
37 lines (32 loc) · 1.13 KB
/
docs.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
35
36
37
// Content managed by Project Forge, see [projectforge.md] for details.
package clib
import (
"github.com/pkg/errors"
"github.com/valyala/fasthttp"
"projectforge.dev/projectforge/app"
"projectforge.dev/projectforge/app/controller"
"projectforge.dev/projectforge/app/controller/cutil"
"projectforge.dev/projectforge/app/util"
"projectforge.dev/projectforge/doc"
"projectforge.dev/projectforge/views/vdoc"
)
func Docs(rc *fasthttp.RequestCtx) {
controller.Act("docs", rc, func(as *app.State, ps *cutil.PageState) (string, error) {
pth, _ := cutil.RCRequiredString(rc, "path", false)
if pth == "" {
return "", errors.New("invalid path")
}
split := util.StringSplitAndTrim(pth, "/")
bc := []string{"docs"}
bc = append(bc, split...)
title, x, err := doc.HTML("doc:"+pth, pth+".md", func(s string) (string, string, error) {
return cutil.FormatCleanMarkup(s, "file")
})
if err != nil {
return "", errors.Wrapf(err, "unable to load documentation from [%s]", pth)
}
ps.Title = title
ps.Data, _ = doc.Content(pth + ".md")
return controller.Render(rc, as, &vdoc.MarkdownPage{Title: pth, HTML: x}, ps, bc...)
})
}