mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
use smaller versions of lemmy images #159
This commit is contained in:
parent
45e19723ff
commit
f0d229c423
3 changed files with 8 additions and 10 deletions
|
@ -204,9 +204,12 @@ class File(db.Model):
|
||||||
thumbnail_width = db.Column(db.Integer)
|
thumbnail_width = db.Column(db.Integer)
|
||||||
thumbnail_height = db.Column(db.Integer)
|
thumbnail_height = db.Column(db.Integer)
|
||||||
|
|
||||||
def view_url(self):
|
def view_url(self, resize=False):
|
||||||
if self.source_url:
|
if self.source_url:
|
||||||
return self.source_url
|
if resize and '/pictrs/' in self.source_url and '?' not in self.source_url:
|
||||||
|
return f'{self.source_url}?thumbnail=1024'
|
||||||
|
else:
|
||||||
|
return self.source_url
|
||||||
elif self.file_path:
|
elif self.file_path:
|
||||||
file_path = self.file_path[4:] if self.file_path.startswith('app/') else self.file_path
|
file_path = self.file_path[4:] if self.file_path.startswith('app/') else self.file_path
|
||||||
return f"https://{current_app.config['SERVER_NAME']}/{file_path}"
|
return f"https://{current_app.config['SERVER_NAME']}/{file_path}"
|
||||||
|
|
|
@ -32,10 +32,10 @@
|
||||||
<div class="post_image">
|
<div class="post_image">
|
||||||
{% if post.image_id %}
|
{% if post.image_id %}
|
||||||
{% if low_bandwidth %}
|
{% if low_bandwidth %}
|
||||||
<a href="{{ post.image.view_url() }}" rel="nofollow ugc"><img src="{{ post.image.medium_url() }}" alt="{{ post.image.alt_text if post.image.alt_text else post.title }}"
|
<a href="{{ post.image.view_url(resize=True) }}" rel="nofollow ugc"><img src="{{ post.image.medium_url() }}" alt="{{ post.image.alt_text if post.image.alt_text else post.title }}"
|
||||||
width="{{ post.image.width }}" height="{{ post.image.height }}" /></a>
|
width="{{ post.image.width }}" height="{{ post.image.height }}" /></a>
|
||||||
{% else %}
|
{% else %}
|
||||||
<a href="{{ post.image.view_url() }}" rel="nofollow ugc"><img src="{{ post.image.view_url() }}" alt="{{ post.image.alt_text if post.image.alt_text else post.title }}"></a>
|
<a href="{{ post.image.view_url() }}" rel="nofollow ugc"><img src="{{ post.image.view_url(resize=True) }}" alt="{{ post.image.alt_text if post.image.alt_text else post.title }}"></a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% else %}
|
{% else %}
|
||||||
<a href="{{ post.url }}" rel="nofollow ugc" target="_blank" aria-label="Go to image"><img src="{{ post.url }}" style="max-width: 100%; height: auto;" /></a>
|
<a href="{{ post.url }}" rel="nofollow ugc" target="_blank" aria-label="Go to image"><img src="{{ post.url }}" style="max-width: 100%; height: auto;" /></a>
|
||||||
|
|
|
@ -7,11 +7,6 @@
|
||||||
<div class="item{{ ' reported' if post.reports > 0 and current_user.is_authenticated and post.community.is_moderator() }}{{ ' blocked' if content_blocked }}"
|
<div class="item{{ ' reported' if post.reports > 0 and current_user.is_authenticated and post.community.is_moderator() }}{{ ' blocked' if content_blocked }}"
|
||||||
{% if content_blocked %} title="{{ _('Filtered: ') }}{{ content_blocked }}"{% endif %}>
|
{% if content_blocked %} title="{{ _('Filtered: ') }}{{ content_blocked }}"{% endif %}>
|
||||||
{% if post.image_id %}
|
{% if post.image_id %}
|
||||||
{% if post_layout == 'masonry' or low_bandwidth %}
|
|
||||||
{% set thumbnail = post.image.thumbnail_url() %}
|
|
||||||
{% elif post_layout == 'masonry_wide' %}
|
|
||||||
{% set thumbnail = post.image.view_url() %}
|
|
||||||
{% endif %}
|
|
||||||
<div class="masonry_thumb" title="{{ post_title }}">
|
<div class="masonry_thumb" title="{{ post_title }}">
|
||||||
{% if post.type == POST_TYPE_LINK or post.type == POST_TYPE_VIDEO %}
|
{% if post.type == POST_TYPE_LINK or post.type == POST_TYPE_VIDEO %}
|
||||||
{% if post.image.medium_url() %}
|
{% if post.image.medium_url() %}
|
||||||
|
@ -27,7 +22,7 @@
|
||||||
loading="{{ 'lazy' if low_bandwidth else 'eager' }}" /></a>
|
loading="{{ 'lazy' if low_bandwidth else 'eager' }}" /></a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% elif post.type == POST_TYPE_IMAGE %}
|
{% elif post.type == POST_TYPE_IMAGE %}
|
||||||
<a href="{{ post.image.view_url() }}" rel="nofollow ugc" target="_blank"><img src="{{ post.image.medium_url() }}"
|
<a href="{{ post.image.view_url(resize=True) }}" rel="nofollow ugc" target="_blank"><img src="{{ post.image.medium_url() }}"
|
||||||
alt="{{ post.image.alt_text if post.image.alt_text else '' }}" title="{{ post_title }}"
|
alt="{{ post.image.alt_text if post.image.alt_text else '' }}" title="{{ post_title }}"
|
||||||
loading="lazy" width="{{ post.image.width }}" height="{{ post.image.height }}" /></a>
|
loading="lazy" width="{{ post.image.width }}" height="{{ post.image.height }}" /></a>
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|
Loading…
Add table
Reference in a new issue