-
Notifications
You must be signed in to change notification settings - Fork 0
/
client-list-devcards.go
48 lines (39 loc) · 1.07 KB
/
client-list-devcards.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
package server
import (
"bytes"
"context"
"fmt"
"net/url"
"path/filepath"
"github.com/igorhub/devcard"
)
func pkgId(info devcard.DevcardInfo) string {
return filepath.Base(filepath.Dir(info.ImportPath)) + "-" + filepath.Base(info.ImportPath)
}
func (c *client) initListDevcards(unregisterFn func()) {
c.unregisterFn = unregisterFn
var jump string
if q, _ := url.Parse(c.url); q != nil {
jump = q.Query().Get("jump")
}
c.updateFn = func(_ context.Context, ch chan<- []byte) {
b := new(bytes.Buffer)
cardsInfo := c.project.DevcardsInfo()
for i, info := range cardsInfo {
newSection := i == 0 || info.ImportPath != cardsInfo[i-1].ImportPath
if newSection {
id := pkgId(info)
fmt.Fprintf(b, "\n<h4 id=\"%s\">%s <span class=\"import-path\">%s</span></h4>\n", id, info.Package, info.ImportPath)
}
link := "/dc/" + c.project.Name + "/" + info.Name
fmt.Fprintf(b, "* [%s](%s)\n", info.Caption(), link)
}
html := MdToHTML(b.String())
ch <- msgAppendCell("list", html)
if jump != "" {
ch <- msgJump(jump)
jump = ""
}
close(ch)
}
}