From a0eb47ef5f26aca6705f7f9f5f5b718b4de826b2 Mon Sep 17 00:00:00 2001 From: zPlus Date: Sat, 30 Jul 2022 20:46:42 +0200 Subject: [PATCH] Add support for reading "description" files in .git folders. Read .git/description files and display it in the web UI. --- documentation/users | 4 ++++ static/css/clif.css | 12 ++++++++++++ templates/explore.html | 21 ++++++++++++++------- templates/repository/readme.html | 5 +++++ web.py | 20 ++++++++++++++++++-- 5 files changed, 53 insertions(+), 9 deletions(-) diff --git a/documentation/users b/documentation/users index 93db852..45aa89a 100644 --- a/documentation/users +++ b/documentation/users @@ -30,6 +30,10 @@ as long as the user has write permission. git clone git@example.org:repository git push git@example.org:repository master +# Set repository description + + ssh git@example.org desc "" + # Pushing to a repository git push git@example.org:repository.git diff --git a/static/css/clif.css b/static/css/clif.css index cf4bc31..f5d98e5 100644 --- a/static/css/clif.css +++ b/static/css/clif.css @@ -61,6 +61,18 @@ pre { margin: 2rem 0 5rem 0; } +/* List of repos in explore page */ +.repositories_list > div { + display: grid; + grid-template-columns: 1fr 3fr; + grid-column-gap: 1rem; + padding: .2rem; +} + +.repositories_list > div:hover { + background-color: #e3ecfa; +} + .repository { display: flex; width: 100%; diff --git a/templates/explore.html b/templates/explore.html index 751dd60..ad06a6a 100644 --- a/templates/explore.html +++ b/templates/explore.html @@ -10,16 +10,23 @@
+
{% for repository in repositories %}
- {% if repository.endswith('.mlist.git') %} - L   - {{ repository[:-4] }} - {% else %} - R   - {{ repository }} - {% endif %} +
+ {% if repository['path'].endswith('.mlist.git') %} + L   + {{ repository['path'][:-4] }} + {% else %} + R   + {{ repository['path'] }} + {% endif %} +
+
+ {{ repository['description'] }} +
{% endfor %} +
{% endblock %} diff --git a/templates/repository/readme.html b/templates/repository/readme.html index 18367eb..e064189 100644 --- a/templates/repository/readme.html +++ b/templates/repository/readme.html @@ -13,6 +13,11 @@ {% endif %}
+ {% if description|length > 0 %} + {{ description }} +

+ {% endif %} + Anon. clone
https://{{ instance_domain }}/{{ repository }} diff --git a/web.py b/web.py index 86d3073..20b89f9 100644 --- a/web.py +++ b/web.py @@ -76,9 +76,18 @@ def list_repositories(): if repository.lower() == 'gitolite-admin.git': continue - repositories.append(repository) + try: + with open(os.path.join(path, 'description')) as f: + description = f.read() + except: + description = '' + + repositories.append({ + 'path': repository, + 'description': description + }) - repositories.sort() + repositories.sort(key = lambda d: d['path']) return repositories def parse_thread_tags(data): @@ -241,10 +250,17 @@ def readme(repository): repo_size = sum(f.stat().st_size for f in pathlib.Path(path).glob("**/*")) + try: + with open(os.path.join(path, 'description')) as f: + description = f.read() + except: + description = '' + return template('repository/readme.html', readme=readme, repository=repository, repository_size=human_size(repo_size), + description=description, head_ref=HEAD) @bottle.get('/.git/refs', name='refs')