Skip to content

Commit 6b9c3e6

Browse files
committed
Truncate commit lengths and add direct link to GitHub
1 parent fff763a commit 6b9c3e6

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/gh_range_diff.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,10 @@ fn process_old_new(
210210
// Create the HTML buffer with a very rough approximation for the capacity
211211
let mut html: String = String::with_capacity(800 + old.files.len() * 100);
212212

213-
// Compute the bookmarklet for the current host
214-
let bookmarklet = bookmarklet(&host);
213+
let a_oldbase = a_github_commit(owner, repo, oldbase);
214+
let a_oldhead = a_github_commit(owner, repo, oldhead);
215+
let a_newbase = a_github_commit(owner, repo, newbase);
216+
let a_newhead = a_github_commit(owner, repo, newhead);
215217

216218
// Write HTML header, style, ...
217219
writeln!(
@@ -222,7 +224,7 @@ fn process_old_new(
222224
<meta charset="UTF-8">
223225
<meta name="viewport" content="width=device-width, initial-scale=1.0">
224226
<link rel="icon" sizes="32x32" type="image/png" href="https://rust-lang.org/static/images/favicon-32x32.png">
225-
<title>range-diff of {oldbase}...{oldhead} {newbase}...{newhead}</title>
227+
<title>range-diff of {oldbase}..{oldhead} {newbase}..{newhead}</title>
226228
<style>
227229
body {{
228230
font: 14px SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace;
@@ -235,6 +237,10 @@ fn process_old_new(
235237
overflow-wrap: break-word;
236238
white-space: normal;
237239
}}
240+
.commit {{
241+
text-decoration: none;
242+
color: unset;
243+
}}
238244
.diff-content {{
239245
overflow-x: auto;
240246
}}
@@ -322,7 +328,7 @@ fn process_old_new(
322328
</style>
323329
</head>
324330
<body>
325-
<h3>range-diff of {oldbase}<wbr>...{oldhead} {newbase}<wbr>...{newhead}</h3>
331+
<h3>range-diff of {a_oldbase}..{a_oldhead} {a_newbase}..{a_newhead} in {owner}/{repo}</h3>
326332
<p>Legend: {REMOVED_BLOCK_SIGN}&nbsp;before | {ADDED_BLOCK_SIGN}&nbsp;after</p>
327333
"#
328334
)?;
@@ -619,3 +625,10 @@ impl<'a> imara_diff::TokenSource for SplitWordBoundaries<'a> {
619625
(self.0.len() as f32 / 4.7f32) as u32
620626
}
621627
}
628+
629+
fn a_github_commit(owner: &str, repo: &str, ref_: &str) -> String {
630+
format!(
631+
r#"<a href="https://github.com/{owner}/{repo}/commit/{ref_}" class="commit">{}</a>"#,
632+
&ref_[..=6]
633+
)
634+
}

0 commit comments

Comments
 (0)