debian-mirror-gitlab/lib/banzai/filter/image_lazy_load_filter.rb
2018-11-18 11:00:15 +05:30

20 lines
487 B
Ruby

# frozen_string_literal: true
module Banzai
module Filter
# HTML filter that moves the value of image `src` attributes to `data-src`
# so they can be lazy loaded.
class ImageLazyLoadFilter < HTML::Pipeline::Filter
def call
doc.xpath('descendant-or-self::img').each do |img|
img.add_class('lazy')
img['data-src'] = img['src']
img['src'] = LazyImageTagHelper.placeholder_image
end
doc
end
end
end
end