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

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

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

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

Instance Method Summary collapse

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

#add_issue, create, #initialize

Methods included from Int::PluginRegistry::PluginMethods

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

Methods inherited from Int::Context

#get_binding, #initialize

Constructor Details

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

Instance Method Details

#runvoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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[:internal_links]` will be skipped.



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

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
  resource_uris_with_filenames = ::Nanoc::Extra::LinkCollector.new(filenames, :internal).filenames_per_resource_uri

  uris = hrefs_with_filenames.merge(resource_uris_with_filenames)
  uris.each_pair do |href, fns|
    fns.each do |filename|
      next if valid?(href, filename)

      add_issue(
        "broken reference to #{href}",
        subject: filename,
      )
    end
  end
end