From 2dd5ba2602d954aae8af2e23a584214a4dd0b972 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Wed, 19 Jun 2024 08:54:32 +0000 Subject: fix(html): replace relative path with absolute path --- src/html.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/html.rs b/src/html.rs index b35e41c..1e85685 100644 --- a/src/html.rs +++ b/src/html.rs @@ -4,13 +4,7 @@ fn link_from_host_href(url: &Url, href: &str) -> Option { Some(format!( "gemini://{}{}{}", url.domain()?, - { - if href.starts_with('/') { - "" - } else { - "/" - } - }, + { if href.starts_with('/') { "" } else { "/" } }, href )) } @@ -73,7 +67,17 @@ pub fn from_gemini( if href.contains("://") && !href.starts_with("gemini://") { surface = true; } else if !href.starts_with("gemini://") && !href.starts_with('/') { - href = format!("./{href}"); + href = format!( + "{}/{}", + url.domain().unwrap(), + if url.path().ends_with('/') { + format!("{}{}", url.path(), href) + } else { + format!("{}/{}", url.path(), href) + } + ) + .replace("//", "/"); + href = format!("gemini://{href}"); } else if href.starts_with('/') || !href.contains("://") { href = link_from_host_href(url, &href)?; } -- cgit v1.2.3