all repos — legit @ b78354aee2f0fef8552896d75e106c915365d3ef

web frontend for git, written in go

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

Signed-off-by: Derek Stevens <nilix@nilfm.cc>
Derek Stevens nilix@nilfm.cc
Wed, 01 Feb 2023 23:01:36 -0700
commit

b78354aee2f0fef8552896d75e106c915365d3ef

parent

ee800624f58b26204c1f846a524ccef5a1b4e386

4 files changed, 29 insertions(+), 14 deletions(-)

jump to
M git/tree.gogit/tree.go

@@ -19,7 +19,7 @@ return nil, fmt.Errorf("file tree: %w", err)

} if path == "" { - files = makeNiceTree(tree.Entries) + files = makeNiceTree(tree) } else { o, err := tree.FindEntry(path) if err != nil {

@@ -32,7 +32,7 @@ if err != nil {

return nil, err } - files = makeNiceTree(subtree.Entries) + files = makeNiceTree(subtree) } }

@@ -48,15 +48,17 @@ IsFile bool

IsSubtree bool } -func makeNiceTree(es []object.TreeEntry) []NiceTree { +func makeNiceTree(t *object.Tree) []NiceTree { nts := []NiceTree{} - for _, e := range es { + for _, e := range t.Entries { mode, _ := e.Mode.ToOSFileMode() + sz, _ := t.Size(e.Name) nts = append(nts, NiceTree{ Name: e.Name, Mode: mode.String(), IsFile: e.Mode.IsFile(), + Size: sz, }) }
M routes/routes.goroutes/routes.go

@@ -254,6 +254,7 @@ data["meta"] = d.c.Meta

data["name"] = name data["ref"] = ref data["desc"] = getDescription(path) + data["dotdot"] = filepath.Dir(path) if err := t.ExecuteTemplate(w, "log", data); err != nil { log.Println(err)
M static/style.cssstatic/style.css

@@ -125,7 +125,7 @@ }

.tree { display: grid; - grid-template-columns: 8em minmax(0, 1fr); + grid-template-columns: 10ch auto 1fr; grid-row-gap: 0.5em; grid-column-gap: 1em; min-width: 0;

@@ -145,8 +145,11 @@ .log pre {

white-space: pre-wrap; } -.mode { +.mode, .size { font-family: var(--mono-font); +} +.size { + text-align: right; } .readme pre {
M templates/tree.htmltemplates/tree.html

@@ -18,25 +18,34 @@

<div class="tree"> {{ if $parent }} <div></div> - <div><a href="../">..</a></div> + <div></div> + <div><a href="/{{ $repo }}/tree/{{ $ref }}/{{ .dotdot }}">..</a></div> {{ end }} {{ range .files }} + {{ if not .IsFile }} <div class="mode">{{ .Mode }}</div> + <div class="size">{{ .Size }}</div> <div> + {{ if $parent }} + <a href="/{{ $repo }}/tree/{{ $ref }}/{{ $parent }}/{{ .Name }}">{{ .Name }}/</a> + {{ else }} + <a href="/{{ $repo }}/tree/{{ $ref }}/{{ .Name }}">{{ .Name }}/</a> + {{ end }} + </div> + {{ 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 }} - {{ else }} - {{ if $parent }} - <a href="/{{ $repo }}/tree/{{ $ref }}/{{ $parent }}/{{ .Name }}">{{ .Name }}/</a> - {{ else }} - <a href="/{{ $repo }}/tree/{{ $ref }}/{{ .Name }}">{{ .Name }}/</a> - {{ end }} + </div> {{ end }} - </div> {{ end }} </div> <article>