-- Leo's gemini proxy
-- Connecting to typed-hole.org:1965...
-- Connected
-- Sending request
-- Meta line: 20 text/gemini
commit eb55d58f2c0cc09a911676fdf9e8d04d1467fc78
Author: Julien Blanchard <julien@sideburns.eu>
Date: Sat Jul 13 13:55:43 2019 +0200
Handle relative links
diff --git a/src/main.rs b/src/main.rs
index e29ee1c..2cef9ee 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -133,30 +133,28 @@ fn follow_link(s: &mut Cursive, line: &str) {
if re1.is_match(&text) {
let caps = re1.captures(&text).unwrap();
let url = caps.get(3).map_or("", |m| m.as_str());
- let next_url = if url.starts_with("gemini://") {
- url.to_owned()
- } else if url.starts_with("/") {
- format!("gemini://{}{}", get_last_host(), url)
- } else {
- format!("gemini://{}/{}", get_last_host(), url)
- };
+ let next_url = parse_link(url);
visit_url(s, &next_url)
} else if re2.is_match(&text) {
let caps = re2.captures(&text).unwrap();
let url = caps.get(1).map_or("", |m| m.as_str());
- let next_url = if url.starts_with("gemini://") {
- url.to_owned()
- } else if url.starts_with("/") {
- format!("gemini://{}{}", get_last_host(), url)
- } else {
- format!("gemini://{}/{}", get_last_host(), url)
- };
+ let next_url = parse_link(url);
visit_url(s, &next_url)
} else {
()
}
}
+fn parse_link(url: &str) -> String {
+ if url.starts_with("gemini://") {
+ url.to_owned()
+ } else if url.starts_with("/") {
+ format!("gemini://{}{}", get_last_host(), url)
+ } else {
+ format!("gemini://{}/{}", get_last_host(), url)
+ }
+}
+
fn is_link(line: &str) -> bool {
let text = format!("{}", line);
let re1 = Regex::new(r"^\[(.*)\|(URL:)?(.*)\]$").unwrap(); // `[Foo|URL:link]` links
---
Served by Pollux Gemini Server.
-- Response ended
-- Page fetched on Sun May 19 09:37:09 2024