Sha256: 162d1f0d5383421d22c5dea6f50666331537c10438b313702a69d8d4a1eae2dc

Contents?: true

Size: 342 Bytes

Versions: 1

Compression:

Stored size: 342 Bytes

Contents

require 'html/pipeline'

class LinkRewriterFilter < HTML::Pipeline::Filter
  LINK_REGEX = /(.+?)\.md$/

  def call
    prefix = context[:link_rewriter_prefix] || '/docs/'
    doc.search('a').each do |a|
      next if a['href'].nil? || a['href'].blank?
      a['href'] = "#{prefix}#{$1}/" if a['href'] =~ LINK_REGEX
    end

    doc
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
link-rewriter-filter-1.0.0 lib/link-rewriter-filter.rb