class Jekyll::LoadingLazy

Constants

VERSION

Public Class Methods

process(content) click to toggle source
# File lib/jekyll-loading-lazy.rb, line 8
def self.process(content)
  html = content.output
  content.output = process_tags(html) if process_tags?(html)
end
process?(doc) click to toggle source
# File lib/jekyll-loading-lazy.rb, line 13
def self.process?(doc)
  (doc.is_a?(Jekyll::Page) || doc.write?) && doc.output_ext == ".html" ||
    doc.permalink&.end_with?("/")
end

Private Class Methods

process_tags(html) click to toggle source
# File lib/jekyll-loading-lazy.rb, line 22
def self.process_tags(html)
  content = Nokogiri.HTML(html)
  tags = content.css("img[src], iframe[src]")
  tags.each { |tag| tag["loading"] = "lazy" unless tag["loading"] }
  content.to_html
end
process_tags?(html) click to toggle source
# File lib/jekyll-loading-lazy.rb, line 18
def self.process_tags?(html)
  html.include?("<img") || html.include?("<iframe")
end