From b78354aee2f0fef8552896d75e106c915365d3ef Mon Sep 17 00:00:00 2001 From: Derek Stevens Date: Wed, 1 Feb 2023 23:01:36 -0700 Subject: tree: directories first, add size column, fix .. Signed-off-by: Derek Stevens --- git/tree.go | 10 ++++++---- routes/routes.go | 1 + static/style.css | 7 +++++-- templates/tree.html | 25 +++++++++++++++++-------- 4 files changed, 29 insertions(+), 14 deletions(-) diff --git a/git/tree.go b/git/tree.go index 0ef1f2f..88ad1c1 100644 --- a/git/tree.go +++ b/git/tree.go @@ -19,7 +19,7 @@ func (g *GitRepo) FileTree(path string) ([]NiceTree, error) { } if path == "" { - files = makeNiceTree(tree.Entries) + files = makeNiceTree(tree) } else { o, err := tree.FindEntry(path) if err != nil { @@ -32,7 +32,7 @@ func (g *GitRepo) FileTree(path string) ([]NiceTree, error) { return nil, err } - files = makeNiceTree(subtree.Entries) + files = makeNiceTree(subtree) } } @@ -48,15 +48,17 @@ type NiceTree struct { 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, }) } diff --git a/routes/routes.go b/routes/routes.go index 4d99ab0..143bb2b 100644 --- a/routes/routes.go +++ b/routes/routes.go @@ -254,6 +254,7 @@ func (d *deps) Log(w http.ResponseWriter, r *http.Request) { 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) diff --git a/static/style.css b/static/style.css index 23e2f75..e012306 100644 --- a/static/style.css +++ b/static/style.css @@ -125,7 +125,7 @@ a:hover { .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,9 +145,12 @@ a:hover { white-space: pre-wrap; } -.mode { +.mode, .size { font-family: var(--mono-font); } +.size { + text-align: right; +} .readme pre { white-space: pre-wrap; diff --git a/templates/tree.html b/templates/tree.html index 2880714..496dceb 100644 --- a/templates/tree.html +++ b/templates/tree.html @@ -18,26 +18,35 @@
{{ if $parent }}
-
..
+
+
..
{{ end }} {{ range .files }} + {{ if not .IsFile }}
{{ .Mode }}
+
{{ .Size }}
- {{ if .IsFile }} - {{ if $parent }} - {{ .Name }} - {{ else }} - {{ .Name }} - {{ end }} - {{ else }} {{ if $parent }} {{ .Name }}/ {{ else }} {{ .Name }}/ {{ end }} +
{{ end }} + {{ end }} + {{ range .files }} + {{ if .IsFile }} +
{{ .Mode }}
+
{{ .Size }}
+
+ {{ if $parent }} + {{ .Name }} + {{ else }} + {{ .Name }} + {{ end }}
{{ end }} + {{ end }}
-- 
cgit