From 77cba2a3ab48ca61e28a47cc25cb658e1712723c Mon Sep 17 00:00:00 2001 From: Fuwn Date: Tue, 2 Apr 2024 08:18:42 +0000 Subject: feat(html): silent image embedding option --- Configuration.md | 6 ++++-- src/html.rs | 15 ++++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Configuration.md b/Configuration.md index e7b48f4..e87678d 100644 --- a/Configuration.md +++ b/Configuration.md @@ -116,8 +116,10 @@ HEADER="This string will show up at the top of my proxied capsule." Embed images in the HTML response if a link to an image is found -Any non-empty value will enable this feature. +A value of `1` will enable this feature, while keeping link to the image. + +Any non-empty value other than `1` will enable this feature, while removing the link to the image. ```dotenv -EMBED_IMAGES=true +EMBED_IMAGES=2 ``` diff --git a/src/html.rs b/src/html.rs index ebe31d9..b86c496 100644 --- a/src/html.rs +++ b/src/html.rs @@ -112,7 +112,7 @@ pub fn from_gemini( } } - if var("EMBED_IMAGES").is_ok() { + if let Ok(embed_images) = var("EMBED_IMAGES") { if let Some(extension) = std::path::Path::new(&href).extension() { if extension == "png" || extension == "jpg" @@ -121,11 +121,16 @@ pub fn from_gemini( || extension == "webp" || extension == "svg" { + if embed_images == "1" { + html.push_str(&format!( + "

{} Embedded below

\n", + href, + safe(&text.clone().unwrap_or_default()), + )); + } + html.push_str(&format!( - "

{} Embedded below

\n

\"{}\"

\n", - href, - safe(&text.clone().unwrap_or_default()), + "

\"{}\"

\n", safe(&href), safe(&text.clone().unwrap_or_default()) )); -- cgit v1.2.3