Files
new-website-jekyll-theme/_plugins/img.rb
f 544fda84c0 feat(upstream): process content images
(cherry picked from commit eacefcd026838e8d47e4d7ae260dc5c6f938b73f)
2025-08-08 18:00:21 -03:00

22 lines
641 B
Ruby

# frozen_string_literal: true
# Renders images in content as picture
Jekyll::Hooks.register :documents, :post_convert do |doc|
max_width = (doc.site.data.dig(*%(bootstrap variables container_max_widths xxl)) || '920px').to_i
template = Liquid::Template.parse("{% render 'sutty/picture.html', image:, class:, img_class:, width: %}")
doc.to_html.css('img').each do |img|
context = {
'image' => {
'path' => img['src'],
'description' => img['alt']
},
'class' => 'd-block w-100',
'img_class' => 'img-fluid',
'width' => max_width
}
img.replace(template.render(context))
end
end