@@ -206,14 +206,10 @@ func (h *handler) ServeIndex(w http.ResponseWriter, req *http.Request) error {
// Find some popular packages to display.
h.s.PackageIssuesMu.RLock()
pis := h.s.PackageIssues
h.s.PackageIssuesMu.RUnlock()
type pkg struct {
Path string
Open int
}
var popular []pkg
for _, p := range h.s.Packages {
popular = append(popular, pkg{
Path: p,
Open: len(pis[p].Open),
@@ -221,36 +217,46 @@ func (h *handler) ServeIndex(w http.ResponseWriter, req *http.Request) error {
}
sort.SliceStable(popular, func(i, j int) bool { return popular[i].Open > popular[j].Open })
popular = popular[:15]
// Render the table.
_, err = io.WriteString(w, `<table class="table table-sm">
err = renderTable(w, popular)
if err != nil {
return err
}
_, err = io.WriteString(w, htmlPart3)
return err
}
type pkg struct {
Path string
Open int
}
func renderTable(w io.Writer, pkgs []pkg) error {
_, err := io.WriteString(w, `<table class="table table-sm">
<thead>
<tr>
<th>Path</th>
<th>Open Issues</th>
</tr>
</thead>
<tbody>`)
if err != nil {
return err
}
for _, p := range popular {
for _, p := range pkgs {
err := html.Render(w, htmlg.TR(
htmlg.TD(htmlg.A(p.Path, "/"+p.Path)),
htmlg.TD(htmlg.Text(fmt.Sprint(p.Open))),
))
if err != nil {
return err
}
}
_, err = io.WriteString(w, `</tbody></table>`)
if err != nil {
return err
}
_, err = io.WriteString(w, htmlPart3)
return err
}
// ServeIssues serves a list of issues for the package with import path pkg.
func (h *handler) ServeIssues(w http.ResponseWriter, req *http.Request, pkg string) error {