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