Class: Nanoc::Extra::Checking::Checks::InternalLinks

Inherits:
Nanoc::Extra::Checking::Check show all
Defined in:
lib/nanoc/extra/checking/checks/internal_links.rb

Overview

A check that verifies that all internal links point to a location that exists.

Instance Attribute Summary

Attributes inherited from Nanoc::Extra::Checking::Check

#issues, #site

Instance Method Summary (collapse)

Methods inherited from Nanoc::Extra::Checking::Check

#add_issue, #initialize, #output_filenames

Methods included from PluginRegistry::PluginMethods

#all, #identifier, #identifiers, #named, #register

Constructor Details

This class inherits a constructor from Nanoc::Extra::Checking::Check

Instance Method Details

- (void) run

This method returns an undefined value.

Starts the validator. The results will be printed to stdout.

Internal links that match a regexp pattern in @config[:checks][:internal_links][:exclude] will be skipped.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/nanoc/extra/checking/checks/internal_links.rb', line 16

def run
  # TODO de-duplicate this (duplicated in external links check)
  filenames = output_filenames.select { |f| File.extname(f) == '.html' }
  hrefs_with_filenames = ::Nanoc::Extra::LinkCollector.new(filenames, :internal).filenames_per_href
  hrefs_with_filenames.each_pair do |href, fns|
    fns.each do |filename|
      unless valid?(href, filename)
      add_issue(
        "broken reference to #{href}",
        :subject  => filename)
      end
    end
  end
end