From 4b5f10cd224844b6cd1c82201e3fb54c6228134f Mon Sep 17 00:00:00 2001 From: Daniel Nitsikopoulos Date: Tue, 17 Sep 2024 21:51:39 +1000 Subject: [PATCH] Minify home images --- slices/main/decorators/posts/decorator.rb | 7 +++++++ slices/main/templates/shared/_photo_post.html.slim | 6 +++--- slices/main/views/site/home.rb | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/slices/main/decorators/posts/decorator.rb b/slices/main/decorators/posts/decorator.rb index a16d814..388f2ba 100644 --- a/slices/main/decorators/posts/decorator.rb +++ b/slices/main/decorators/posts/decorator.rb @@ -6,6 +6,7 @@ require "rexml/parsers/pullparser" require "sanitize" require "nokogiri" require "unicode/emoji" +require "mini_magick" module Main module Decorators @@ -32,6 +33,12 @@ module Main __getobj__.photos.select { |p| !p["value"].end_with?("mp4") } end + def photo_thumbnails + photos.map do |photo| + photo["value"] = photo["value"].gsub(".jpeg", "-small.jpeg") + end + end + def videos? __getobj__.photos.count { |p| p["value"].end_with?("mp4") } > 0 end diff --git a/slices/main/templates/shared/_photo_post.html.slim b/slices/main/templates/shared/_photo_post.html.slim index 8b80b96..17b150e 100644 --- a/slices/main/templates/shared/_photo_post.html.slim +++ b/slices/main/templates/shared/_photo_post.html.slim @@ -1,13 +1,13 @@ - if extended - - post.photos.each_with_index do |photo, idx| + - post.photo_thumbnails.each_with_index do |photo, idx| div class="rounded max-w-xs" a href="#{post.permalink}#photo-#{idx}" - img loading="lazy" class="rounded object-cover transition-transform ease-out hover:scale-105 h-48 w-48" src="#{photo["value"]}" alt="#{photo["alt"]}" + img loading="lazy" class="rounded object-cover transition-transform ease-out hover:scale-105 h-48 w-48" src="#{photo}" alt="#{photo["alt"]}" - else - if post.photos.count > 0 div class="rounded max-w-xs" a href="#{post.permalink}" - img loading="lazy" class="rounded object-cover transition-transform ease-out hover:scale-105 h-48 w-48" src="#{post.photos[0]["value"]}" alt="#{post.photos[0]["alt"]}" + img loading="lazy" class="rounded object-cover transition-transform ease-out hover:scale-105 h-48 w-48" src="#{post.photo_thumbnails[0]}" alt="#{post.photos[0]["alt"]}" - if post.videos.count > 0 div class="rounded max-w-xs" a href="#{post.permalink}" diff --git a/slices/main/views/site/home.rb b/slices/main/views/site/home.rb index f33e1bf..506f0da 100644 --- a/slices/main/views/site/home.rb +++ b/slices/main/views/site/home.rb @@ -11,7 +11,7 @@ module Main end private_expose :date do - TZInfo::Timezone.get('Australia/Canberra').now + TZInfo::Timezone.get("Australia/Canberra").now end expose :formatted_date do |date|