From 005c83b4c12f76d36dd4c3762d1f66d6f3f37bfa Mon Sep 17 00:00:00 2001 From: Luka Hietala Date: Sat, 22 Nov 2025 19:52:44 +0200 Subject: [PATCH] view readme on repos --- app.py | 11 ++++++++++- static/styles.css | 10 ++++++++++ templates/repo.html | 28 ++++++++++++++++------------ 3 files changed, 36 insertions(+), 13 deletions(-) diff --git a/app.py b/app.py index 43885ba..c6504f0 100644 --- a/app.py +++ b/app.py @@ -104,7 +104,16 @@ def repo_detail(repo_name): abort(400, "Invalid ref") commits = get_commits(f"{repo_path}/{repo_name}", ref=ref, max_count=10) refs = get_refs(f"{repo_path}/{repo_name}") - return render_template("repo.html", repo_name=repo_name, refs=refs, commits=commits) + readme = None + for filename in ['README.md', 'README']: + try: + readme_blob = get_blob(f"{repo_path}/{repo_name}", ref, filename) + if readme_blob: + readme = readme_blob['content'] + break + except: + pass + return render_template("repo.html", repo_name=repo_name, refs=refs, commits=commits, readme=readme) @app.route("//commits") def repo_commits(repo_name): diff --git a/static/styles.css b/static/styles.css index 36fd90a..311cd91 100644 --- a/static/styles.css +++ b/static/styles.css @@ -154,5 +154,15 @@ table.commits-table .message-col { overflow-x: auto; } +.readme-box { + border: 1px solid lightgray; + padding: 1em; + margin: 0.5em 0; + background-color: #f9f9f9; + border-radius: 4px; + white-space: pre-wrap; + overflow-x: auto; +} + diff --git a/templates/repo.html b/templates/repo.html index 4bfa6c0..6b4a0f7 100644 --- a/templates/repo.html +++ b/templates/repo.html @@ -1,7 +1,7 @@ {% extends "base.html" %} {% block content %} -

Repository: {{ repo_name }}

+

{{ repo_name }}

Latest commits

@@ -15,18 +15,22 @@ {% for commit in commits %} - - - - - - - + + + + + + + {% endfor %}
{{ 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 }} -
{{ 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 }} +
+{% if readme %} +

README

+
{{ readme }}
+{% endif %} {% endblock %} \ No newline at end of file -- 2.47.3