💾 Archived View for lists.flounder.online › patches › threads › 20210330220930.3273-1-johann@qwertqw… captured on 2022-04-28 at 19:24:10. Gemini links have been rewritten to link to archived content
-=-=-=-=-=-=-
From: johann@qwertqwefsday.eu
Date: Wed, 31 Mar 2021 00:09:29 +0200
Message-Id: 20210330220930.3273-1-johann@qwertqwefsday.eu
To: <~aw/patches@lists.sr.ht>
Cc: "Johann150" <johann@qwertqwefsday.eu>
--------------------------------------
The commit a shorthand name of a ref points to may change thus
rendering a line link out of date. This can be fixed by instead
using the commit oid.
---
src/main.rs | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/src/main.rs b/src/main.rs
index 7122a64..18a4ec3 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -428,12 +428,21 @@ async fn repo_file(req: Request<()>) -> tide::Result {
LinesWithEndings::from(file_string)
.for_each(|line| highlighter.parse_html_for_line_which_includes_newline(line));
+ // use oid so it is a permalink
+ let prefix = format!(
+ "/{}/tree/{}/item/{}",
+ req.param("repo_name").unwrap(),
+ commit.id(),
+ path.display()
+ );
+
let mut output = String::from("<pre>\n");
for (n, line) in highlighter.finalize().lines().enumerate() {
output.push_str(&format!(
- "<a href='#L{0}' id='L{0}' class='line'>{0}</a>{1}\n",
+ "<a href='{1}#L{0}' id='L{0}' class='line'>{0}</a>{2}\n",
n + 1,
- line
+ prefix,
+ line,
));
}
output.push_str("</pre>\n");
--
2.30.1.windows.1