Method: HTML::Pipeline::CamoFilter#call

Defined in:
lib/html/pipeline/camo_filter.rb

#callObject

Hijacks images in the markup provided, replacing them with URLs that go through the github asset proxy.

[View source]

24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/html/pipeline/camo_filter.rb', line 24

def call
  return doc unless asset_proxy_enabled?

  doc.search("img").each do |element|
    original_src = element['src']
    next unless original_src

    begin
      uri = URI.parse(original_src)
    rescue Exception
      next
    end

    next if uri.host.nil?
    next if asset_host_whitelisted?(uri.host)

    element['src'] = asset_proxy_url(original_src)
    element['data-canonical-src'] = original_src
  end
  doc
end