self.check_internal

in _plugins/link-checker.rb [161:196]


  def self.check_internal(url)
    return true if @ignored_paths =~ url

    path, hash = url.split('#')

    if @need_no_suffix =~ path
        filename = File.join(@site.config["destination"], path)
        return File.file?(filename)
    else
        unless path.end_with? 'index.html'
          path << '/' unless path.end_with? '/'
          path << 'index.html' unless path.end_with? 'index.html'
        end

        filename = File.join(@site.config["destination"], path)

        return false unless File.file?(filename)

        content = File.read(filename)
        unless content.include? "<title>Redirecting"
          return true if hash.nil? || hash.empty?
          return !(content =~ /<[a-z0-9-]+[^>]+id="#{hash}"/i).nil?
        end

        match = content.match(@href_matcher)
        if match.nil?
          puts "LinkChecker: [Warning] Cannot check #{url} due to an unfollowable redirect"
          return true
        end

        redirect = match[2]
        redirect << '#' + hash unless hash.nil? || hash.empty?
        return self.check(redirect)
    end
  end