Sha256: 16876483f57826e6d311147b67bbcef32721e6fe58c6a3bc36428bc380276797

Contents?: true

Size: 703 Bytes

Versions: 6

Compression:

Stored size: 703 Bytes

Contents

description 'Add query parameter "aspect" to images'
dependencies 'utils/xml'

Filter.create :fix_image_links do |context, content|
  doc = XML::Fragment(content)
  linked_images = doc.css('a img')
  doc.css('img').each do |image|
    path = image['src']
    unless path =~ %r{^w+://} || path.starts_with?(build_path('_')) ||
        (path.starts_with?('/') && !path.starts_with?(build_path('')))
      unless path.include?('aspect=')
        image['src'] = path + (path.include?('?') ? '&' : '?') + 'aspect=image'
      end
      unless linked_images.include?(image)
        image.swap("<a href=\"#{escape_html path.sub(/\?.*/, '')}\">#{image.to_xhtml}</a>")
      end
    end
  end
  doc.to_xhtml
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
olelo-0.9.10 plugins/filters/fix_image_links.rb
olelo-0.9.9 plugins/filters/fix_image_links.rb
olelo-0.9.8 plugins/filters/fix_image_links.rb
olelo-0.9.7 plugins/filters/fix_image_links.rb
olelo-0.9.6 plugins/filters/fix_image_links.rb
olelo-0.9.5 plugins/filters/fix_image_links.rb