♻️ Simple & Efficient Gemini-to-HTTP Proxy fuwn.net
proxy gemini-protocol protocol gemini http rust
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat(html): condense links option

Fuwn d3b23dd6 23abedaa

+49 -2
+21
Configuration.md
··· 123 123 ```dotenv 124 124 EMBED_IMAGES=2 125 125 ``` 126 + 127 + ## `CONDENSE_LINKS` 128 + 129 + Condense adjacent links to a single line 130 + 131 + A value of `*` will condense all adjacent links to a single line. 132 + 133 + A comma-separated list of paths will condense adjacent links to a single line only on those paths. 134 + 135 + ### Example 136 + 137 + ```plaintext 138 + <!-- Not condensed --> 139 + 140 + <p><a href="/">Link</a></p> 141 + <p><a href="/">Link</a></p> 142 + <p><a href="/">Link</a></p> 143 + 144 + <!-- Condensed --> 145 + <p><a href="/">Link</a> | <a href="/">Link</a> | <a href="/">Link</a></p> 146 + ```
+28 -2
src/html.rs
··· 26 26 )) 27 27 } 28 28 29 - #[allow(clippy::too_many_lines)] 29 + #[allow(clippy::too_many_lines, clippy::cognitive_complexity)] 30 30 pub fn from_gemini( 31 31 response: &germ::request::Response, 32 32 url: &Url, ··· 38 38 let mut html = String::new(); 39 39 let mut title = String::new(); 40 40 let safe = html_escape::encode_text; 41 + let mut previous_link = false; 42 + let condense_links = { 43 + let links = var("CONDENSE_LINKS").map_or_else( 44 + |_| vec![], 45 + |condense_links| { 46 + condense_links 47 + .split(',') 48 + .map(std::string::ToString::to_string) 49 + .collect() 50 + }, 51 + ); 52 + 53 + links.contains(&url.path().to_string()) || links.contains(&"*".to_string()) 54 + }; 41 55 42 56 for node in ast { 57 + if previous_link && (!matches!(node, Node::Link { .. }) || !condense_links) 58 + { 59 + html.push_str("\n</p>"); 60 + previous_link = false; 61 + } else if previous_link { 62 + html.push_str(" <span style=\"opacity: 50%;\">|</span> "); 63 + } else if !previous_link && matches!(node, Node::Link { .. }) { 64 + html.push_str("<p>"); 65 + } 66 + 43 67 match node { 44 68 Node::Text(text) => html.push_str(&format!("<p>{}</p>", safe(text))), 45 69 Node::Link { to, text } => { ··· 140 164 } 141 165 } 142 166 167 + previous_link = true; 168 + 143 169 html.push_str(&format!( 144 - "<p><a href=\"{}\">{}</a></p>\n", 170 + "<a href=\"{}\">{}</a>", 145 171 href, 146 172 safe(&text.clone().unwrap_or_default()), 147 173 ));