tree: directories first, add size column, fix ..

This commit is contained in:
Iris Lightshard 2023-02-01 23:01:36 -07:00
parent cd131c0629
commit 50093251b2
Signed by: Iris Lightshard
GPG key ID: 3B7FBC22144E6398
4 changed files with 30 additions and 15 deletions

View file

@ -19,7 +19,7 @@ func (g *GitRepo) FileTree(path string) ([]NiceTree, error) {
} }
if path == "" { if path == "" {
files = makeNiceTree(tree.Entries) files = makeNiceTree(tree)
} else { } else {
o, err := tree.FindEntry(path) o, err := tree.FindEntry(path)
if err != nil { if err != nil {
@ -32,7 +32,7 @@ func (g *GitRepo) FileTree(path string) ([]NiceTree, error) {
return nil, err return nil, err
} }
files = makeNiceTree(subtree.Entries) files = makeNiceTree(subtree)
} }
} }
@ -48,15 +48,17 @@ type NiceTree struct {
IsSubtree bool IsSubtree bool
} }
func makeNiceTree(es []object.TreeEntry) []NiceTree { func makeNiceTree(t *object.Tree) []NiceTree {
nts := []NiceTree{} nts := []NiceTree{}
for _, e := range es { for _, e := range t.Entries {
mode, _ := e.Mode.ToOSFileMode() mode, _ := e.Mode.ToOSFileMode()
sz, _ := t.Size(e.Name)
nts = append(nts, NiceTree{ nts = append(nts, NiceTree{
Name: e.Name, Name: e.Name,
Mode: mode.String(), Mode: mode.String(),
IsFile: e.Mode.IsFile(), IsFile: e.Mode.IsFile(),
Size: sz,
}) })
} }

View file

@ -256,6 +256,7 @@ func (d *deps) Log(w http.ResponseWriter, r *http.Request) {
data["name"] = name data["name"] = name
data["ref"] = ref data["ref"] = ref
data["desc"] = getDescription(path) data["desc"] = getDescription(path)
data["dotdot"] = filepath.Dir(path)
if err := t.ExecuteTemplate(w, "log", data); err != nil { if err := t.ExecuteTemplate(w, "log", data); err != nil {
log.Println(err) log.Println(err)

View file

@ -125,7 +125,7 @@ a:hover {
.tree { .tree {
display: grid; display: grid;
grid-template-columns: 8em minmax(0, 1fr); grid-template-columns: 10ch auto 1fr;
grid-row-gap: 0.5em; grid-row-gap: 0.5em;
grid-column-gap: 1em; grid-column-gap: 1em;
min-width: 0; min-width: 0;
@ -145,9 +145,12 @@ a:hover {
white-space: pre-wrap; white-space: pre-wrap;
} }
.mode { .mode, .size {
font-family: var(--mono-font); font-family: var(--mono-font);
} }
.size {
text-align: right;
}
.readme pre { .readme pre {
white-space: pre-wrap; white-space: pre-wrap;

View file

@ -18,26 +18,35 @@
<div class="tree"> <div class="tree">
{{ if $parent }} {{ if $parent }}
<div></div> <div></div>
<div><a href="../">..</a></div> <div></div>
<div><a href="/{{ $repo }}/tree/{{ $ref }}/{{ .dotdot }}">..</a></div>
{{ end }} {{ end }}
{{ range .files }} {{ range .files }}
{{ if not .IsFile }}
<div class="mode">{{ .Mode }}</div> <div class="mode">{{ .Mode }}</div>
<div class="size">{{ .Size }}</div>
<div> <div>
{{ if .IsFile }}
{{ if $parent }}
<a href="/{{ $repo }}/blob/{{ $ref }}/{{ $parent }}/{{ .Name }}">{{ .Name }}</a>
{{ else }}
<a href="/{{ $repo }}/blob/{{ $ref }}/{{ .Name }}">{{ .Name }}</a>
{{ end }}
{{ else }}
{{ if $parent }} {{ if $parent }}
<a href="/{{ $repo }}/tree/{{ $ref }}/{{ $parent }}/{{ .Name }}">{{ .Name }}/</a> <a href="/{{ $repo }}/tree/{{ $ref }}/{{ $parent }}/{{ .Name }}">{{ .Name }}/</a>
{{ else }} {{ else }}
<a href="/{{ $repo }}/tree/{{ $ref }}/{{ .Name }}">{{ .Name }}/</a> <a href="/{{ $repo }}/tree/{{ $ref }}/{{ .Name }}">{{ .Name }}/</a>
{{ end }} {{ end }}
{{ end }}
</div> </div>
{{ end }} {{ end }}
{{ end }}
{{ range .files }}
{{ if .IsFile }}
<div class="mode">{{ .Mode }}</div>
<div class="size">{{ .Size }}</div>
<div>
{{ if $parent }}
<a href="/{{ $repo }}/blob/{{ $ref }}/{{ $parent }}/{{ .Name }}">{{ .Name }}</a>
{{ else }}
<a href="/{{ $repo }}/blob/{{ $ref }}/{{ .Name }}">{{ .Name }}</a>
{{ end }}
</div>
{{ end }}
{{ end }}
</div> </div>
<article> <article>
<pre> <pre>