From a7f59ccac17f785ce332e46cf364c03a7428decc Mon Sep 17 00:00:00 2001 From: mikupls <93015331+mikupls@users.noreply.github.com> Date: Fri, 3 Mar 2023 13:50:05 +0100 Subject: [PATCH] Display previews and inline images for reddit-hosted images. This version does not change the svg behaviour in the other cases in an attempt to reduce breakage. --- src/utils.rs | 5 +++++ templates/utils.html | 12 +++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/utils.rs b/src/utils.rs index a823ff5..0246d1e 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -163,6 +163,9 @@ impl Media { gallery = GalleryMedia::parse(&data["gallery_data"]["items"], &data["media_metadata"]); ("gallery", &data["url"], None) + } else if data["is_reddit_media_domain"].as_bool().unwrap_or_default() && data["domain"] == "i.redd.it" { + // If this post contains a reddit media (image) URL. + ("image", &data["url"], None) } else { // If type can't be determined, return url ("link", &data["url"], None) @@ -177,6 +180,8 @@ impl Media { Self { url: format_url(url_val.as_str().unwrap_or_default()), alt_url, + // Note: in the data["is_reddit_media_domain"] path above + // width and height will be 0. width: source["width"].as_i64().unwrap_or_default(), height: source["height"].as_i64().unwrap_or_default(), poster: format_url(source["url"].as_str().unwrap_or_default()), diff --git a/templates/utils.html b/templates/utils.html index 3fdd76d..f5a0945 100644 --- a/templates/utils.html +++ b/templates/utils.html @@ -100,6 +100,10 @@ {% if post.post_type == "image" %}
+ {% if post.media.height == 0 || post.media.width == 0 %} + + Post image + {% else %} + {% endif %}
{% else if post.post_type == "video" || post.post_type == "gif" %} @@ -216,7 +221,11 @@ {% if (prefs.layout.is_empty() || prefs.layout == "card") && post.post_type == "image" %}
- + + {% if post.media.height == 0 || post.media.width == 0 %} + + Post image + {% else %} + {% endif %}
{% else if (prefs.layout.is_empty() || prefs.layout == "card") && post.post_type == "gif" %}