From f0d229c42396056190a1ea71303e7bdc08b9b5d6 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Mon, 6 May 2024 15:42:12 +1200 Subject: [PATCH] use smaller versions of lemmy images #159 --- app/models.py | 7 +++++-- app/templates/post/_post_full.html | 4 ++-- app/templates/post/_post_teaser_masonry.html | 7 +------ 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/app/models.py b/app/models.py index 6b49fb8d..a84b5c02 100644 --- a/app/models.py +++ b/app/models.py @@ -204,9 +204,12 @@ class File(db.Model): thumbnail_width = db.Column(db.Integer) thumbnail_height = db.Column(db.Integer) - def view_url(self): + def view_url(self, resize=False): 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: 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}" diff --git a/app/templates/post/_post_full.html b/app/templates/post/_post_full.html index a5b1bcce..631a50c3 100644 --- a/app/templates/post/_post_full.html +++ b/app/templates/post/_post_full.html @@ -32,10 +32,10 @@
{% if post.image_id %} {% if low_bandwidth %} - {{ post.image.alt_text if post.image.alt_text else post.title }}{{ post.image.alt_text if post.image.alt_text else post.title }} {% else %} - {{ post.image.alt_text if post.image.alt_text else post.title }} + {{ post.image.alt_text if post.image.alt_text else post.title }} {% endif %} {% else %} diff --git a/app/templates/post/_post_teaser_masonry.html b/app/templates/post/_post_teaser_masonry.html index 16bd9833..a5e8eb53 100644 --- a/app/templates/post/_post_teaser_masonry.html +++ b/app/templates/post/_post_teaser_masonry.html @@ -7,11 +7,6 @@
{% 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 %}
{% if post.type == POST_TYPE_LINK or post.type == POST_TYPE_VIDEO %} {% if post.image.medium_url() %} @@ -27,7 +22,7 @@ loading="{{ 'lazy' if low_bandwidth else 'eager' }}" /> {% endif %} {% elif post.type == POST_TYPE_IMAGE %} - {{ post.image.alt_text if post.image.alt_text else '' }} {% else %}