lib/nanoc/extra/checking/checks/external_links.rb in nanoc-4.0.2 vs lib/nanoc/extra/checking/checks/external_links.rb in nanoc-4.1.0a1
- old
+ new
@@ -12,11 +12,11 @@
identifiers :external_links, :elinks
def run
# Find all broken external hrefs
# TODO: de-duplicate this (duplicated in internal links check)
- filenames = output_filenames.select { |f| File.extname(f) == '.html' }
+ filenames = output_filenames.select { |f| File.extname(f) == '.html' && !excluded_file?(f) }
hrefs_with_filenames = ::Nanoc::Extra::LinkCollector.new(filenames, :external).filenames_per_href
results = select_invalid(hrefs_with_filenames.keys)
# Report them
results.each do |res|
@@ -87,10 +87,13 @@
url = URI.parse(href)
rescue URI::InvalidURIError
return Result.new(href, 'invalid URI')
end
+ # Skip excluded URLs
+ return nil if self.excluded?(href)
+
# Skip non-HTTP URLs
return nil if url.scheme !~ /^https?$/
# Get status
res = nil
@@ -158,8 +161,18 @@
if url.instance_of? URI::HTTPS
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
http.request(req)
+ end
+
+ def excluded?(href)
+ excludes = @config.fetch(:checks, {}).fetch(:external_links, {}).fetch(:exclude, [])
+ excludes.any? { |pattern| Regexp.new(pattern).match(href) }
+ end
+
+ def excluded_file?(file)
+ excludes = @config.fetch(:checks, {}).fetch(:external_links, {}).fetch(:exclude_files, [])
+ excludes.any? { |pattern| Regexp.new(pattern).match(file) }
end
end
end