diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 45139506c..412c908df 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -82,6 +82,14 @@ module ApplicationHelper Images::Optimizer.call(SimpleIDN.to_ascii(image_url), width: width, quality: quality, fetch_format: format) end + def optimized_image_tag(image_url, optimizer_options: {}, image_options: {}) + image_options[:width] ||= optimizer_options[:width] + image_options[:height] ||= optimizer_options[:height] + updated_image_url = Images::Optimizer.call(image_url, optimizer_options) + + image_tag(updated_image_url, image_options) + end + def cloud_cover_url(url) CloudCoverUrl.new(url).call end diff --git a/app/liquid_tags/podcast_tag.rb b/app/liquid_tags/podcast_tag.rb index 1b431d6cd..bdf58d6f7 100644 --- a/app/liquid_tags/podcast_tag.rb +++ b/app/liquid_tags/podcast_tag.rb @@ -33,7 +33,7 @@ class PodcastTag < LiquidTagBase end def render(_context) - ActionController::Base.new.render_to_string( + ApplicationController.render( partial: PARTIAL, locals: { episode: @episode, diff --git a/app/views/articles/_bottom_content.html.erb b/app/views/articles/_bottom_content.html.erb index c9b38e007..0a156bc40 100644 --- a/app/views/articles/_bottom_content.html.erb +++ b/app/views/articles/_bottom_content.html.erb @@ -7,17 +7,9 @@
- <%= cl_image_tag(article.cached_user.profile_image_url, - type: "fetch", - crop: "imagga_scale", - width: 100, - height: 100, - quality: "auto", - flags: "progressive", - fetch_format: "auto", - loading: "lazy", - sign_url: true, - alt: "#{article.cached_user.username} profile image") %> + <%= optimized_image_tag(article.cached_user.profile_image_url, + optimizer_options: { crop: "imagga_scale", width: 100, height: 100 }, + image_options: { loading: "lazy", alt: "#{article.cached_user.username} profile image" }) %>

<%= article.title %>

diff --git a/app/views/podcast_episodes/_episodes_feed.html.erb b/app/views/podcast_episodes/_episodes_feed.html.erb index fb10428c0..545ad8c2b 100644 --- a/app/views/podcast_episodes/_episodes_feed.html.erb +++ b/app/views/podcast_episodes/_episodes_feed.html.erb @@ -2,16 +2,9 @@
- <%= cl_image_tag(episode.image_url || episode.podcast.image_url, - type: "fetch", - crop: "imagga_scale", - width: 240, - height: 240, - quality: "auto", - flags: "progressive", - fetch_format: "auto", - sign_url: true, - alt: episode.title) %> + <%= optimized_image_tag(episode.image_url || episode.podcast.image_url, + optimizer_options: { crop: "imagga_scale", width: 240, height: 240 }, + image_options: { alt: episode.title }) %>

podcast<%= episode.title %>

diff --git a/app/views/podcast_episodes/_liquid.html.erb b/app/views/podcast_episodes/_liquid.html.erb index 67d663b09..e6e10baeb 100644 --- a/app/views/podcast_episodes/_liquid.html.erb +++ b/app/views/podcast_episodes/_liquid.html.erb @@ -15,16 +15,9 @@
play pause - <%= cl_image_tag(podcast.image_url, - type: "fetch", - crop: "fill", - quality: "auto", - sign_url: true, - flags: "progressive", - fetch_format: "auto", - class: "podcastliquidtag__podcastimage", - id: "podcastimage-#{episode.slug}", - alt: podcast.title) %> + <%= optimized_image_tag(podcast.image_url, + optimizer_options: { crop: "fill" }, + image_options: { class: "podcastliquidtag__podcastimage", id: "podcastimage-#{episode.slug}", alt: podcast.title }) %>