From f315ed2d6c6e0aa18cef8debd1b174a48c9a800e Mon Sep 17 00:00:00 2001
From: Fuwn
Date: Thu, 4 Apr 2024 03:01:18 +0000
Subject: feat(html): condense links option
---
src/html.rs | 30 ++++++++++++++++++++++++++++--
1 file changed, 28 insertions(+), 2 deletions(-)
(limited to 'src/html.rs')
diff --git a/src/html.rs b/src/html.rs
index b86c496..07d979e 100644
--- a/src/html.rs
+++ b/src/html.rs
@@ -26,7 +26,7 @@ fn link_from_host_href(url: &Url, href: &str) -> Option {
))
}
-#[allow(clippy::too_many_lines)]
+#[allow(clippy::too_many_lines, clippy::cognitive_complexity)]
pub fn from_gemini(
response: &germ::request::Response,
url: &Url,
@@ -38,8 +38,32 @@ pub fn from_gemini(
let mut html = String::new();
let mut title = String::new();
let safe = html_escape::encode_text;
+ let mut previous_link = false;
+ let condense_links = {
+ let links = var("CONDENSE_LINKS").map_or_else(
+ |_| vec![],
+ |condense_links| {
+ condense_links
+ .split(',')
+ .map(std::string::ToString::to_string)
+ .collect()
+ },
+ );
+
+ links.contains(&url.path().to_string()) || links.contains(&"*".to_string())
+ };
for node in ast {
+ if previous_link && (!matches!(node, Node::Link { .. }) || !condense_links)
+ {
+ html.push_str("\n
");
+ previous_link = false;
+ } else if previous_link {
+ html.push_str(" | ");
+ } else if !previous_link && matches!(node, Node::Link { .. }) {
+ html.push_str("");
+ }
+
match node {
Node::Text(text) => html.push_str(&format!("
{}
", safe(text))),
Node::Link { to, text } => {
@@ -140,8 +164,10 @@ pub fn from_gemini(
}
}
+ previous_link = true;
+
html.push_str(&format!(
- "{}
\n",
+ "{}",
href,
safe(&text.clone().unwrap_or_default()),
));
--
cgit v1.2.3