1{% import "git.gabrielgio.me/cerrado/pkg/u" %}
2{% import "github.com/go-git/go-git/v5/plumbing/object" %}
3
4{% code type GitItemTreePage struct {
5 Path []string
6 Tree *object.Tree
7}
8%}
9
10{% code const (
11 Folder = "tree"
12 Blob = "blob"
13 Root = ""
14)
15%}
16
17{% code func url(name, mode, ref, filename string, path []string) string {
18 return u.NewPathing().
19 AddPath(name).
20 AddPath(mode).
21 AddPath(ref).
22 AddPaths(path).
23 AddPath(filename).
24 Done()
25}
26%}
27
28{% func (g *GitItemTreePage) Nav(name, ref string) %}{%= GitItemNav(name, ref, Tree) %}{% endfunc %}
29
30{% func (g *GitItemTreePage) GitContent(name, ref string) %}
31<div class="pathing">
32 {% stripspace %}
33 {% if len(g.Path) != 0 %}
34 <a href="{%s url(name, Folder, ref, Root, []string{}) %}">root/</a>
35 {% for i, e := range g.Path[:len(g.Path)-1] %}
36 <a href="{%s url(name, Folder, ref, Root, g.Path[:1+i]) %}">{%s e %}/</a>
37 {% endfor %}
38 <a>{%s u.LastOrZero(g.Path) %}</a>
39 {% else %}
40 <a>root/</a>
41 {% endif %}
42 {% endstripspace %}
43</div>
44<div class="row">
45 <div class="col-md-12">
46 <div class="tree-list">
47 {% if len(g.Path) != 0 %}
48 <div class="mode"><a href="{%s url(name, Folder, ref, g.Path[len(g.Path)-1], g.Path[:len(g.Path)-1]) %}">..</a></div>
49 <div class="name tree"></div>
50 <div class="commit"></div>
51 <div class="date"></div>
52 <div class="size"></div>
53 {% endif %}
54 {% for _, e := range g.Tree.Entries %}
55 <div class="mode">{%s Ignore(e.Mode.ToOSFileMode()).String() %}</div>
56 {% if e.Mode.IsFile() %}
57 <div class="name blob"><a href="{%s url(name, Blob, ref, e.Name, g.Path) %}">{%s e.Name %}</a></div>
58 {% else %}
59 <div class="name tree"><a href="{%s url(name, Folder, ref, e.Name, g.Path) %}">{%s e.Name %}</a></div>
60 {% endif %}
61 <div class="commit"></div>
62 <div class="date"></div>
63 <div class="size">{%dl Ignore(g.Tree.Size(e.Name))%} KiB</div>
64 {% endfor %}
65 </div>
66 </div>
67</div>
68{% endfunc %}