Skip to content

Instantly share code, notes, and snippets.

@iloveitaly
Created March 17, 2016 20:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iloveitaly/901f4aa64bdf4780b992 to your computer and use it in GitHub Desktop.
Save iloveitaly/901f4aa64bdf4780b992 to your computer and use it in GitHub Desktop.
GitHub HTML pipeline for adding asset fingerprints to image links
module HTML
class Pipeline
class ImageAssetPathFilter < HTML::Pipeline::Filter
def call
doc.search("img").each do |img|
next if img['src'].nil?
src = img['src'].strip
if src.start_with?('/')
# stripping `/assets/` from the URL enables asset fingerprinting in production
img["src"] = ActionController::Base.helpers.asset_path(src.gsub(/^\/assets\//, ''))
end
end
doc
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment