From 3ca317e7affbe0187785b703a7b86001183939b5 Mon Sep 17 00:00:00 2001 From: Luka Hietala Date: Thu, 20 Nov 2025 19:45:53 +0200 Subject: [PATCH] add better table css and commits table spesific styles. also age filter for commits instead of datime --- app.py | 28 +++++++++++++++ static/styles.css | 77 ++++++++++++++++++++++++++++++++++++------ templates/commits.html | 34 +++++++++---------- templates/repo.html | 30 ++++++++-------- 4 files changed, 126 insertions(+), 43 deletions(-) diff --git a/app.py b/app.py index 6aad97f..b3b7c4b 100644 --- a/app.py +++ b/app.py @@ -36,7 +36,35 @@ def datetime_filter(value, format='%Y-%m-%d %H:%M:%S'): return dt.strftime(format) return value +# age filter to show relative time like "2 days ago" +def age_filter(value): + if isinstance(value, (int, float)): + dt = datetime.fromtimestamp(value) + elif isinstance(value, datetime): + dt = value + else: + return value + now = datetime.now() + diff = now - dt + if diff.days > 365: + years = diff.days // 365 + return f"{years} year{'s' if years != 1 else ''} ago" + elif diff.days > 30: + months = diff.days // 30 + return f"{months} month{'s' if months != 1 else ''} ago" + elif diff.days > 0: + return f"{diff.days} day{'s' if diff.days != 1 else ''} ago" + elif diff.seconds > 3600: + hours = diff.seconds // 3600 + return f"{hours} hour{'s' if hours != 1 else ''} ago" + elif diff.seconds > 60: + minutes = diff.seconds // 60 + return f"{minutes} minute{'s' if minutes != 1 else ''} ago" + else: + return "just now" + app.jinja_env.filters['datetime'] = datetime_filter +app.jinja_env.filters['age'] = age_filter @app.route("/") def index(): diff --git a/static/styles.css b/static/styles.css index 4a299fa..19d285c 100644 --- a/static/styles.css +++ b/static/styles.css @@ -36,17 +36,6 @@ nav a.active { font-weight: bold; } -table { - border-collapse: collapse; - width: 100%; -} - -th, td { - border: 1px solid lightgray; - padding: 2px 4px; - text-align: left; -} - pre { font-family: monospace; font-size: 10pt; @@ -67,3 +56,69 @@ h2 { margin: 1em 0 0.5em 0; } +table { + border-collapse: collapse; + width: 100%; +} + +th, td { + border: 1px solid lightgray; + padding: 4px 8px; + text-align: left; + white-space: nowrap; +} + +tbody tr:nth-child(even) { + background-color: #f9f9f9; +} + +/* commits table */ +table.commits-table { + width: 100%; + table-layout: fixed; +} + +table.commits-table td { + white-space: nowrap; +} + +table.commits-table th, table.commits-table td { + overflow: hidden; + text-overflow: ellipsis; +} + +table.commits-table .author-col { + width: 15%; +} + +table.commits-table .age-col { + width: 10%; +} + +table.commits-table .changes-col { + width: 10%; +} + +table.commits-table .commit-col { + width: 6%; +} + +table.commits-table .message-col { + width: 59%; + white-space: nowrap; +} + +.files-changed { + color: grey; +} + +.insertions { + color: green; +} + +.deletions { + color: red; +} + + + diff --git a/templates/commits.html b/templates/commits.html index 58fdbb5..77e11c5 100644 --- a/templates/commits.html +++ b/templates/commits.html @@ -2,29 +2,29 @@ {% block content %}

Commits for {{ repo_name }}

- +
- - - - - - - + + + + + {% for commit in commits %} - - - - - - - - - + + + + + + + {% endfor %}
CommitMessageAuthorDateFiles ChangedInsertionsDeletionsCommitMessageAuthorAgeChanges
{{ commit.id[:8] }}{{ commit.message }}{{ commit.author.name }}{{ commit.date | datetime }}{{ commit.diff_stats.files_changed }}{{ commit.diff_stats.insertions }}{{ commit.diff_stats.deletions }}
{{ commit.id[:8] }}{{ commit.message }}{{ commit.author.name }}{{ commit.date | age }} + {{ commit.diff_stats.files_changed }} file{% if commit.diff_stats.files_changed != 1 %}s{% endif %} + +{{ commit.diff_stats.insertions }} + -{{ commit.diff_stats.deletions }} +
diff --git a/templates/repo.html b/templates/repo.html index 7b96a18..4bfa6c0 100644 --- a/templates/repo.html +++ b/templates/repo.html @@ -3,28 +3,28 @@ {% block content %}

Repository: {{ repo_name }}

Latest commits

- +
- - - - - - - + + + + + {% for commit in commits %} - - - - - - - + + + + + {% endfor %} -- 2.47.3
CommitMessageAuthorDateFiles ChangedInsertionsDeletionsCommitMessageAuthorAgeChanges
{{ commit.id[:8] }}{{ commit.message }}{{ commit.author.name }}{{ commit.date | datetime }}{{ commit.diff_stats.files_changed }}{{ commit.diff_stats.insertions }}{{ commit.diff_stats.deletions }}{{ commit.id[:8] }}{{ commit.message }}{{ commit.author.name }}{{ commit.date | age }} + {{ commit.diff_stats.files_changed }} file{% if commit.diff_stats.files_changed != 1 %}s{% endif %} + +{{ commit.diff_stats.insertions }} + -{{ commit.diff_stats.deletions }} +