package templates import ( "strings" "go.alanpearce.eu/elgit/config" "go.alanpearce.eu/elgit/git" g "go.alanpearce.eu/gomponents" c "go.alanpearce.eu/gomponents/components" . "go.alanpearce.eu/gomponents/html" ) type PageData struct { Meta config.Meta DisplayName string Name string Ref string Readme string Description string Path string Parent string Files any Diff []git.Diff Stat git.Stat Commit *git.Commit Commits []*git.Commit LineCount []int Content string Branches any Log bool Servername string Gomod bool } func RenderHead(data PageData) []g.Node { var title string metaTitle := data.Meta.Title if data.Parent != "" { title = metaTitle + " — " + data.Name + " (" + data.Ref + "): " + data.Parent + "/" } else if data.Path != "" { title = metaTitle + " — " + data.Name + " (" + data.Ref + "): " + data.Path } else if data.Files != nil { title = metaTitle + " — " + data.Name + " (" + data.Ref + ")" } else if data.Commit != nil { title = metaTitle + " — " + data.Name + ": " + data.Commit.This } else if data.Branches != nil { title = metaTitle + " — " + data.Name + ": refs" } else if data.Commits != nil { if data.Log { title = metaTitle + " — " + data.Name + ": log" } else { title = metaTitle + " — " + data.Name } } else { title = metaTitle } return []g.Node{ Link(Rel("stylesheet"), Href("/static/style.css"), Type("text/css")), Link(Rel("icon"), Type("image/png"), g.Attr("sizes", "32x32"), Href("/static/elgit.png")), TitleEl(g.Text(title)), g.If(data.Servername != "" && data.Gomod, Meta( Name("go-import"), Content(data.Servername+"/"+data.Name+" git https://"+data.Servername+"/"+data.Name), ), ), } } func RenderNav(data PageData) g.Node { var items []g.Node if data.Name != "" { items = append(items, Li(A(Href(joinPaths(data.Name)), g.Text("summary")))) items = append(items, Li(A(Href(joinPaths(data.Name, "refs", "")), g.Text("refs")))) if data.Ref != "" { items = append(items, Li(A(Href(joinPaths(data.Name, "tree", data.Ref, "")), g.Text("tree")))) items = append(items, Li(A(Href(joinPaths(data.Name, "log", data.Ref)), g.Text("log")))) } } return Nav(Ul(items...)) } func RepoHeader(data PageData) g.Node { return Header( H2( A( Href("/"), g.Text("all repos"), ), g.Text(" — "), g.Text(data.DisplayName), g.Text(" "), g.If(data.Ref != "", Span(Class("ref"), g.Textf("@ %s", data.Ref))), ), H3(Class("desc"), g.Text(data.Description)), ) } func Page(data PageData, body []g.Node) g.Node { return c.HTML5(c.HTML5Props{ Language: "en", Head: RenderHead(data), Body: body, }) } func joinPaths(paths ...string) string { return "/" + strings.Join(paths, "/") }