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.
This commit is contained in:
parent
cef9266648
commit
a7f59ccac1
2 changed files with 16 additions and 1 deletions
|
@ -163,6 +163,9 @@ impl Media {
|
||||||
gallery = GalleryMedia::parse(&data["gallery_data"]["items"], &data["media_metadata"]);
|
gallery = GalleryMedia::parse(&data["gallery_data"]["items"], &data["media_metadata"]);
|
||||||
|
|
||||||
("gallery", &data["url"], None)
|
("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 {
|
} else {
|
||||||
// If type can't be determined, return url
|
// If type can't be determined, return url
|
||||||
("link", &data["url"], None)
|
("link", &data["url"], None)
|
||||||
|
@ -177,6 +180,8 @@ impl Media {
|
||||||
Self {
|
Self {
|
||||||
url: format_url(url_val.as_str().unwrap_or_default()),
|
url: format_url(url_val.as_str().unwrap_or_default()),
|
||||||
alt_url,
|
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(),
|
width: source["width"].as_i64().unwrap_or_default(),
|
||||||
height: source["height"].as_i64().unwrap_or_default(),
|
height: source["height"].as_i64().unwrap_or_default(),
|
||||||
poster: format_url(source["url"].as_str().unwrap_or_default()),
|
poster: format_url(source["url"].as_str().unwrap_or_default()),
|
||||||
|
|
|
@ -100,6 +100,10 @@
|
||||||
{% if post.post_type == "image" %}
|
{% if post.post_type == "image" %}
|
||||||
<div class="post_media_content">
|
<div class="post_media_content">
|
||||||
<a href="{{ post.media.url }}" class="post_media_image" >
|
<a href="{{ post.media.url }}" class="post_media_image" >
|
||||||
|
{% if post.media.height == 0 || post.media.width == 0 %}
|
||||||
|
<!-- i.redd.it images speical case -->
|
||||||
|
<img width="100%" height="100%" loading="lazy" alt="Post image" src="{{ post.media.url }}"/>
|
||||||
|
{% else %}
|
||||||
<svg
|
<svg
|
||||||
width="{{ post.media.width }}px"
|
width="{{ post.media.width }}px"
|
||||||
height="{{ post.media.height }}px"
|
height="{{ post.media.height }}px"
|
||||||
|
@ -109,6 +113,7 @@
|
||||||
<img loading="lazy" alt="Post image" src="{{ post.media.url }}"/>
|
<img loading="lazy" alt="Post image" src="{{ post.media.url }}"/>
|
||||||
</desc>
|
</desc>
|
||||||
</svg>
|
</svg>
|
||||||
|
{% endif %}
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
{% else if post.post_type == "video" || post.post_type == "gif" %}
|
{% else if post.post_type == "video" || post.post_type == "gif" %}
|
||||||
|
@ -216,7 +221,11 @@
|
||||||
<!-- POST MEDIA/THUMBNAIL -->
|
<!-- POST MEDIA/THUMBNAIL -->
|
||||||
{% if (prefs.layout.is_empty() || prefs.layout == "card") && post.post_type == "image" %}
|
{% if (prefs.layout.is_empty() || prefs.layout == "card") && post.post_type == "image" %}
|
||||||
<div class="post_media_content">
|
<div class="post_media_content">
|
||||||
<a href="{{ post.media.url }}" class="post_media_image {% if post.media.height / post.media.width < 2 %}short{% endif %}" >
|
<a href="{{ post.media.url }}" class="post_media_image {% if post.media.height < post.media.width*2 %}short{% endif %}" >
|
||||||
|
{% if post.media.height == 0 || post.media.width == 0 %}
|
||||||
|
<!-- i.redd.it images speical case -->
|
||||||
|
<img width="100%" height="100%" loading="lazy" alt="Post image" src="{{ post.media.url }}"/>
|
||||||
|
{% else %}
|
||||||
<svg
|
<svg
|
||||||
{%if post.flags.nsfw && prefs.blur_nsfw=="on" %}class="post_nsfw_blur"{% endif %}
|
{%if post.flags.nsfw && prefs.blur_nsfw=="on" %}class="post_nsfw_blur"{% endif %}
|
||||||
width="{{ post.media.width }}px"
|
width="{{ post.media.width }}px"
|
||||||
|
@ -227,6 +236,7 @@
|
||||||
<img loading="lazy" alt="Post image" src="{{ post.media.url }}"/>
|
<img loading="lazy" alt="Post image" src="{{ post.media.url }}"/>
|
||||||
</desc>
|
</desc>
|
||||||
</svg>
|
</svg>
|
||||||
|
{% endif %}
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
{% else if (prefs.layout.is_empty() || prefs.layout == "card") && post.post_type == "gif" %}
|
{% else if (prefs.layout.is_empty() || prefs.layout == "card") && post.post_type == "gif" %}
|
||||||
|
|
Loading…
Reference in a new issue