class Middleman::Extensions::AssetHash::Middleware
def rewrite_paths(body, path)
def rewrite_paths(body, path) dirpath = Pathname.new(File.dirname(path)) # TODO: This regex will change some paths in plan HTML (not in a tag) - is that OK? body.gsub(/([=\'\"\(]\s*)([^\s\'\"\)]+(#{@exts_regex_text}))/) do |match| opening_character = $1 asset_path = $2 relative_path = Pathname.new(asset_path).relative? asset_path = dirpath.join(asset_path).to_s if relative_path if @ignore.any? { |r| asset_path.match(r) } match elsif asset_page = @middleman_app.sitemap.find_resource_by_path(asset_path) replacement_path = "/#{asset_page.destination_path}" replacement_path = Pathname.new(replacement_path).relative_path_from(dirpath).to_s if relative_path "#{opening_character}#{replacement_path}" else match end end end