-
Notifications
You must be signed in to change notification settings - Fork 0
/
handle.go
66 lines (59 loc) · 2.31 KB
/
handle.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Content managed by Project Forge, see [projectforge.md] for details.
package site
import (
"fmt"
"github.com/valyala/fasthttp"
"admini.dev/admini/app"
"admini.dev/admini/app/controller/cutil"
"admini.dev/admini/app/site/download"
"admini.dev/admini/app/util"
"admini.dev/admini/doc"
"admini.dev/admini/views/layout"
"admini.dev/admini/views/vsite"
)
func Handle(path []string, rc *fasthttp.RequestCtx, as *app.State, ps *cutil.PageState) (string, layout.Page, []string, error) {
if len(path) == 0 {
ps.Data = siteData("Welcome to the marketing site!")
return "", &vsite.Index{}, path, nil
}
var page layout.Page
var err error
switch path[0] {
case util.AppKey:
msg := "\n " +
"<meta name=\"go-import\" content=\"admini.dev/admini git %s\">\n " +
"<meta name=\"go-source\" content=\"admini.dev/admini %s %s/tree/master{/dir} %s/blob/master{/dir}/{file}#L{line}\">"
ps.HeaderContent = fmt.Sprintf(msg, util.AppSource, util.AppSource, util.AppSource, util.AppSource)
return "", &vsite.GoSource{}, path, nil
case keyDownload:
dls := download.GetLinks(as.BuildInfo.Version)
ps.Data = util.ValueMap{"base": "https://admini.dev/admini/releases/download/v" + as.BuildInfo.Version, "links": dls}
page = &vsite.Download{Links: dls}
case keyInstall:
page, err = mdTemplate("Installation", "This static page contains installation instructions", "installation.md", ps)
case keyContrib:
page, err = mdTemplate("Contributing", "This static page describes how to build "+util.AppName, "contributing.md", ps)
case keyTech:
page, err = mdTemplate("Technology", "This static page describes the technology used in "+util.AppName, "technology.md", ps)
default:
page, err = mdTemplate("Documentation", "Documentation for "+util.AppName, path[0]+".md", ps)
}
return "", page, path, err
}
func siteData(result string, kvs ...string) util.ValueMap {
ret := util.ValueMap{"app": util.AppName, "url": util.AppURL, "result": result}
for i := 0; i < len(kvs); i += 2 {
ret[kvs[i]] = kvs[i+1]
}
return ret
}
func mdTemplate(title string, description string, path string, ps *cutil.PageState) (layout.Page, error) {
ps.Data = siteData(title, "description", description)
ps.Title = title
html, err := doc.HTML(path)
if err != nil {
return nil, err
}
page := &vsite.MarkdownPage{Title: title, HTML: html}
return page, nil
}