Render photos individually, optimize gallery images, and prune old releases

This commit is contained in:
2026-09-19 16:20:07 +03:30
parent e112ed7640
commit 3ec6cdd3ec
210 changed files with 117 additions and 12 deletions
+30
View File
@@ -0,0 +1,30 @@
require 'liquid'
require 'nokogiri'
require_relative '../../_plugins/gallery_items'
require_relative '../../_plugins/lazy_images'
class GalleryRenderer
include GalleryItems
include LazyImages
end
renderer = GalleryRenderer.new
batch = '<div id="photo-batch"></div>' +
'<p><img src="/img/arts/uploads/batch/00.jpg" alt="first"></p>' +
'<p><img src="/img/arts/uploads/batch/01.jpg" alt="second"></p>' +
'<span class="image-details">A &amp; B<br>Caption</span>'
items = renderer.gallery_items(renderer.lazy_images(batch))
raise 'Expected one item per uploaded photo' unless items.length == 2
items.each_with_index do |item, index|
html = Nokogiri::HTML::DocumentFragment.parse(item)
raise 'Each item must contain one photo' unless html.css('img').length == 1
raise 'Photo order changed' unless html.at_css('img')['src'].end_with?("0#{index}.jpg")
raise 'Lazy loading lost' unless html.at_css('img')['loading'] == 'lazy'
raise 'Caption lost' unless html.at_css('.image-details').text == 'A & BCaption'
raise 'Anchor must occur on the first photo only' unless html.css('#photo-batch').length == (index.zero? ? 1 : 0)
end
single = '<p><img src="/img/arts/uploads/batch/00.jpg"></p>'
raise 'Single photo changed' unless renderer.gallery_items(single) == [single]
legacy = '<p><img src="/img/old.jpg"></p><p>Existing artwork content</p>'
raise 'Legacy artwork changed' unless renderer.gallery_items(legacy) == [legacy]
puts 'Gallery item regression checks passed'