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
| package site
import ( "fmt" "strings"
"{{{ .Package }}}/app" "{{{ .Package }}}/app/controller/cutil" "{{{ .Package }}}/app/site/download" "{{{ .Package }}}/app/util" "{{{ .Package }}}/doc" "{{{ .Package }}}/views" "{{{ .Package }}}/views/layout" "{{{ .Package }}}/views/verror" "{{{ .Package }}}/views/vsite" )
func Handle(path []string, as *app.State, ps *cutil.PageState) (string, layout.Page, []string, error) { {{{ if .HasModule "search" }}}ps.SearchPath = "-" {{{ end }}}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=\"{{{ .Package }}} git %s\">\n " + "<meta name=\"go-source\" content=\"{{{ .Package }}} %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://{{{ .Package }}}/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 }
|