From fff763a12f4d02e634a912b01b8a8b05c5ad8a00 Mon Sep 17 00:00:00 2001 From: Urgau Date: Sat, 4 Oct 2025 11:40:56 +0200 Subject: [PATCH 1/3] Remove bookmarklet in our range-diff viewer --- src/gh_range_diff.rs | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/src/gh_range_diff.rs b/src/gh_range_diff.rs index 5a1453220..388074074 100644 --- a/src/gh_range_diff.rs +++ b/src/gh_range_diff.rs @@ -8,7 +8,6 @@ use axum::{ http::HeaderValue, response::IntoResponse, }; -use axum_extra::extract::Host; use hyper::header::CACHE_CONTROL; use hyper::{ HeaderMap, StatusCode, @@ -34,7 +33,6 @@ static MARKER_RE: LazyLock = pub async fn gh_range_diff( Path((owner, repo, basehead)): Path<(String, String, String)>, State(ctx): State>, - host: Host, ) -> axum::response::Result { let Some((oldhead, newhead)) = basehead.split_once("..") else { return Ok(( @@ -122,7 +120,6 @@ pub async fn gh_range_diff( let ((oldbase, old), (newbase, new)) = futures::try_join!(old, new)?; process_old_new( - host, (&owner, &repo), (&oldbase, oldhead, old), (&newbase, newhead, new), @@ -136,7 +133,6 @@ pub async fn gh_range_diff( pub async fn gh_ranges_diff( Path((owner, repo, oldbasehead, newbasehead)): Path<(String, String, String, String)>, State(ctx): State>, - host: Host, ) -> axum::response::Result { let Some((oldbase, oldhead)) = oldbasehead.split_once("..") else { return Ok(( @@ -191,7 +187,6 @@ pub async fn gh_ranges_diff( let (old, new) = futures::try_join!(old, new)?; process_old_new( - host, (&owner, &repo), (&oldbase, oldhead, old), (&newbase, newhead, new), @@ -199,7 +194,6 @@ pub async fn gh_ranges_diff( } fn process_old_new( - Host(host): Host, (owner, repo): (&str, &str), (oldbase, oldhead, mut old): (&str, &str, GithubCompare), (newbase, newhead, mut new): (&str, &str, GithubCompare), @@ -329,7 +323,7 @@ fn process_old_new(

range-diff of {oldbase}...{oldhead} {newbase}...{newhead}

-

Bookmarklet: range-diff 🛈 | {REMOVED_BLOCK_SIGN} before | {ADDED_BLOCK_SIGN} after

+

Legend: {REMOVED_BLOCK_SIGN} before | {ADDED_BLOCK_SIGN} after

"# )?; @@ -609,24 +603,6 @@ impl UnifiedDiffPrinter for HtmlDiffPrinter<'_> { } } -// Create the javascript bookmarklet based on the host -fn bookmarklet(host: &str) -> String { - let protocol = if host.starts_with("localhost:") { - "http" - } else { - "https" - }; - - format!( - r"javascript:(() => {{ - const githubUrlPattern = /^https:\/\/github\.com\/([^\/]+)\/([^\/]+)\/compare\/([^\/]+[.]{{2}}[^\/]+)$/; - const match = window.location.href.match(githubUrlPattern); - if (!match) {{alert('Invalid GitHub Compare URL format.\nExpected: https://github.com/ORG_NAME/REPO_NAME/compare/BASESHA..HEADSHA'); return;}} - const [, orgName, repoName, basehead] = match; window.location = `{protocol}://{host}/gh-range-diff/${{orgName}}/${{repoName}}/${{basehead}}`; -}})();" - ) -} - // Simple abstraction over `unicode_segmentation::split_word_bounds` for `imara_diff::TokenSource` struct SplitWordBoundaries<'a>(&'a str); From 6b9c3e6fe0888d46a6cd4dc9ee26d6ae108d1f85 Mon Sep 17 00:00:00 2001 From: Urgau Date: Sat, 4 Oct 2025 11:41:56 +0200 Subject: [PATCH 2/3] Truncate commit lengths and add direct link to GitHub --- src/gh_range_diff.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/gh_range_diff.rs b/src/gh_range_diff.rs index 388074074..0c49e11d9 100644 --- a/src/gh_range_diff.rs +++ b/src/gh_range_diff.rs @@ -210,8 +210,10 @@ fn process_old_new( // Create the HTML buffer with a very rough approximation for the capacity let mut html: String = String::with_capacity(800 + old.files.len() * 100); - // Compute the bookmarklet for the current host - let bookmarklet = bookmarklet(&host); + let a_oldbase = a_github_commit(owner, repo, oldbase); + let a_oldhead = a_github_commit(owner, repo, oldhead); + let a_newbase = a_github_commit(owner, repo, newbase); + let a_newhead = a_github_commit(owner, repo, newhead); // Write HTML header, style, ... writeln!( @@ -222,7 +224,7 @@ fn process_old_new( - range-diff of {oldbase}...{oldhead} {newbase}...{newhead} + range-diff of {oldbase}..{oldhead} {newbase}..{newhead} -

range-diff of {oldbase}...{oldhead} {newbase}...{newhead}

+

range-diff of {a_oldbase}..{a_oldhead} {a_newbase}..{a_newhead} in {owner}/{repo}

Legend: {REMOVED_BLOCK_SIGN} before | {ADDED_BLOCK_SIGN} after

"# )?; @@ -619,3 +625,10 @@ impl<'a> imara_diff::TokenSource for SplitWordBoundaries<'a> { (self.0.len() as f32 / 4.7f32) as u32 } } + +fn a_github_commit(owner: &str, repo: &str, ref_: &str) -> String { + format!( + r#"{}"#, + &ref_[..=6] + ) +} From ffc08f21b79202009c05aafdfd06d640827a1dd6 Mon Sep 17 00:00:00 2001 From: Urgau Date: Sat, 4 Oct 2025 11:47:48 +0200 Subject: [PATCH 3/3] Increase somewhat the contrast of added lines with the normal lines --- src/gh_range_diff.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gh_range_diff.rs b/src/gh_range_diff.rs index 0c49e11d9..e804b7533 100644 --- a/src/gh_range_diff.rs +++ b/src/gh_range_diff.rs @@ -256,7 +256,7 @@ fn process_old_new( color: rgb(220, 0, 0) }} .line-added-after {{ - color: rgb(0, 73, 0) + color: rgb(0, 221, 0) }} .line-removed-before {{ color: rgb(192, 78, 76)