Sha256: d60803547f5cc0ad797ae2b05728a66dd3cd74d219a9bcbe850451d33a18bfaf

Contents?: true

Size: 905 Bytes

Versions: 15

Compression:

Stored size: 905 Bytes

Contents

description  'Classify links as absent/present/external'
dependencies 'utils/xml'

Filter.create :link_classifier do |context, content|
  doc = XML::Fragment(content)
  doc.css('a[href]').each do |link|
    href =  link['href']
    classes = [link['class']].compact
    if href.starts_with?('http://') || href.starts_with?('https://')
      classes << 'external'
    elsif !href.empty? && !href.starts_with?('#')
      path, query = href.split('?')
      if path.starts_with? Config['base_path']
        path = path[Config['base_path'].length..-1]
      elsif !path.starts_with? '/'
        path = context.page.path/'..'/path
      end
      classes << 'internal'
      if !Application.reserved_path?(path)
        classes << (Page.find(path, context.page.tree_version) ? 'present' : 'absent') rescue nil
      end
    end
    link['class'] = classes.join(' ') if !classes.empty?
  end
  doc.to_xhtml
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
olelo-0.9.14 plugins/filters/link_classifier.rb
olelo-0.9.13 plugins/filters/link_classifier.rb
olelo-0.9.12 plugins/filters/link_classifier.rb
olelo-0.9.11 plugins/filters/link_classifier.rb
olelo-0.9.10 plugins/filters/link_classifier.rb
olelo-0.9.9 plugins/filters/link_classifier.rb
olelo-0.9.8 plugins/filters/link_classifier.rb
olelo-0.9.7 plugins/filters/link_classifier.rb
olelo-0.9.6 plugins/filters/link_classifier.rb
olelo-0.9.5 plugins/filters/link_classifier.rb
olelo-0.9.4 plugins/filters/link_classifier.rb
olelo-0.9.3 plugins/filters/link_classifier.rb
olelo-0.9.2 plugins/filters/link_classifier.rb
olelo-0.9.1 plugins/filters/link_classifier.rb
olelo-0.9.0 plugins/filters/link_classifier.rb