💾 Archived View for lists.flounder.online › patches › threads › 20210314225537.23237-6-johann@qwertq… captured on 2022-07-16 at 16:25:54. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2022-04-28)
-=-=-=-=-=-=-
From: johann@qwertqwefsday.eu
Date: Sun, 14 Mar 2021 23:55:37 +0100
Message-Id: 20210314225537.23237-6-johann@qwertqwefsday.eu
To: <~aw/patches@lists.sr.ht>
In-Reply-To: 20210314225537.23237-1-johann@qwertqwefsday.eu
Cc: "Johann150" <johann@qwertqwefsday.eu>
--------------------------------------
From: Johann150 <johann@qwertqwefsday.eu>
workdir is only correct for repositories that have one. Bare repositories
do not have a workdir and so we have to use the directory name instead.
---
src/main.rs | 13 +++++++++++++
templates/index.html | 3 +--
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/src/main.rs b/src/main.rs
index cd2f327..6ad1499 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -246,7 +246,10 @@ async fn repo_commit(req: Request<()>) -> tide::Result {
};
Ok(tmpl.into())
}
+
mod filters {
+ use super::*;
+
pub fn format_datetime(time: &git2::Time, format: &str) -> ::askama::Result<String> {
use chrono::{FixedOffset, TimeZone};
let offset = FixedOffset::west(time.offset_minutes() * 60);
@@ -282,6 +285,16 @@ mod filters {
output[i] = 0x2d; // -
return Ok(std::str::from_utf8(&output).unwrap().to_owned());
}
+
+ pub fn repo_name(repo: &Repository) -> askama::Result<&str> {
+ repo.workdir()
+ // use the path for bare repositories
+ .unwrap_or_else(|| repo.path())
+ .file_name()
+ .unwrap()
+ .to_str()
+ .ok_or(askama::Error::Fmt(std::fmt::Error))
+ }
}
#[async_std::main]
diff --git a/templates/index.html b/templates/index.html
index ac28f6e..8f5a106 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -6,9 +6,8 @@
<div style=>
<table>
{% for repo in repos %}
- {% let name = repo.workdir().unwrap().file_name().unwrap().to_str().unwrap() %}
<tr>
- <td class="repo-link"><a href="{{name}}">{{ name }}</a></td>
+ <td class="repo-link"><a href="{{repo|repo_name|urlencode_strict}}">{{repo|repo_name}}</a></td>
<td class="repo-description">a cool repository</td>
<td class="repo-last-updated">updated 2021-02-01</td>
</tr>
--
2.20.1
From: alex@alexwennerberg.com
Date: Sun, 14 Mar 2021 20:04:48 -0700
Message-Id: C9XLBEZE5PF8.S9HJYF0ORFVU@debian-alex
To: "Johann Galle" <johann@qwertqwefsday.eu>, <~aw/patches@lists.sr.ht>
In-Reply-To: 20210314225537.23237-6-johann@qwertqwefsday.eu
--------------------------------------
Thanks for all these patches! Much appreciated, this is very helpful!
Let me know if you have any other feedback or questions.
All the best,
Alex