-
Notifications
You must be signed in to change notification settings - Fork 0
/
handle.go
82 lines (76 loc) · 2.7 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Content managed by Project Forge, see [projectforge.md] for details.
package site
import (
"fmt"
"strings"
"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"
"admini.dev/admini/views/layout"
"admini.dev/admini/views/verror"
"admini.dev/admini/views/vsite"
)
func Handle(path []string, as *app.State, ps *cutil.PageState) (string, layout.Page, []string, error) {
ps.SearchPath = "-"
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 keyAbout:
ps.Title = "About " + util.AppName
ps.Data = util.AppName + " v" + as.BuildInfo.Version
page = &views.About{}
case keyDownload:
dls := download.GetLinks(as.BuildInfo.Version)
ps.Title = "Downloads"
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("This static page contains installation instructions", "installation.md", "code", ps)
case keyContrib:
page, err = mdTemplate("This static page describes how to build "+util.AppName, "contributing.md", "cog", ps)
case keyTech:
page, err = mdTemplate("This static page describes the technology used in "+util.AppName, "technology.md", "shield", ps)
default:
page, err = mdTemplate("Documentation for "+util.AppName, path[0]+".md", "", ps)
if err != nil {
page = &verror.NotFound{Path: "/" + strings.Join(path, "/")}
err = nil
}
}
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(description string, path string, icon string, ps *cutil.PageState) (layout.Page, error) {
if icon == "" {
icon = "cog"
}
title, html, err := doc.HTML(path, path, func(s string) (string, string, error) {
return cutil.FormatCleanMarkup(s, icon)
})
if err != nil {
return nil, err
}
ps.Data = siteData(title, "description", description)
ps.Title = title
page := &vsite.MarkdownPage{Title: title, HTML: html}
return page, nil
}