From dcfbea6521008e85a7822db6b26e84dd0d31b92c Mon Sep 17 00:00:00 2001 From: Luka Hietala Date: Sat, 22 Nov 2025 19:14:23 +0200 Subject: [PATCH] add size filters and improve the cute surprise on --- app.py | 13 +++++++++++++ git/tree.py | 4 ++++ static/styles.css | 28 ++++++++++++++++++++++++++++ templates/blame.html | 4 +++- templates/blob.html | 4 +++- templates/tree.html | 15 +++++++++++++-- 6 files changed, 64 insertions(+), 4 deletions(-) diff --git a/app.py b/app.py index 7d9d190..43885ba 100644 --- a/app.py +++ b/app.py @@ -73,8 +73,21 @@ def age_filter(value): else: return "just now" +def size_filter(value): + if value is None: + return '' + if value < 1024: + return f"{value} B" + elif value < 1024 * 1024: + return f"{value / 1024:.1f} KB" + elif value < 1024 * 1024 * 1024: + return f"{value / (1024 * 1024):.1f} MB" + else: + return f"{value / (1024 * 1024 * 1024):.1f} GB" + app.jinja_env.filters['datetime'] = datetime_filter app.jinja_env.filters['age'] = age_filter +app.jinja_env.filters['size'] = size_filter @app.route("/") def index(): diff --git a/git/tree.py b/git/tree.py index 46f6522..259c31d 100644 --- a/git/tree.py +++ b/git/tree.py @@ -40,4 +40,8 @@ def get_tree_items(repo_path, ref="HEAD", tree_path=""): 'path': entry.name if not tree_path else f"{tree_path}/{entry.name}" } items.append(item) + + # dirs first, then files, both alphabetically + items.sort(key=lambda x: (0 if x['type'] == 'tree' else 1, x['name'].lower())) + return items \ No newline at end of file diff --git a/static/styles.css b/static/styles.css index 90526f3..36fd90a 100644 --- a/static/styles.css +++ b/static/styles.css @@ -61,6 +61,11 @@ table { width: 100%; } +.tree-table { + width: auto; + max-width: 100%; +} + th, td { border: 1px solid lightgray; padding: 4px 8px; @@ -126,5 +131,28 @@ table.commits-table .message-col { overflow-x: auto; } +.breadcrumbs { + margin-bottom: 1em; + font-size: 14px; +} + +.breadcrumbs a { + color: grey; +} + +.tree-table td:first-child { + white-space: normal; + word-break: break-all; +} + +.blob-content { + margin: 0 -1em; +} + +.blob-content pre { + white-space: pre-wrap; + overflow-x: auto; +} + diff --git a/templates/blame.html b/templates/blame.html index 240f195..75d6f7d 100644 --- a/templates/blame.html +++ b/templates/blame.html @@ -5,7 +5,8 @@

Blame: {{ path }}

Loading blame information, this may take a while for large files...
-