22 lines
641 B
Ruby
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
|