diff options
| author | Fuwn <[email protected]> | 2024-06-19 08:54:32 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-06-19 08:54:32 +0000 |
| commit | 2dd5ba2602d954aae8af2e23a584214a4dd0b972 (patch) | |
| tree | 0f262b04ae24bccfd05fdfa57405de77956f3b0e | |
| parent | feat: bump september (diff) | |
| download | september-2dd5ba2602d954aae8af2e23a584214a4dd0b972.tar.xz september-2dd5ba2602d954aae8af2e23a584214a4dd0b972.zip | |
fix(html): replace relative path with absolute path
| -rw-r--r-- | Cargo.toml | 2 | ||||
| -rw-r--r-- | src/html.rs | 20 |
2 files changed, 13 insertions, 9 deletions
@@ -2,7 +2,7 @@ [package] name = "september" -version = "0.2.19" +version = "0.2.20" authors = ["Fuwn <[email protected]>"] edition = "2021" description = "A simple and efficient Gemini-to-HTTP proxy." 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<String> { 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)?; } |