lib/nanoc/extra/checking/checks/internal_links.rb in nanoc-4.1.6 vs lib/nanoc/extra/checking/checks/internal_links.rb in nanoc-4.2.0b1

- old
+ new

@@ -32,11 +32,11 @@ # Skip hrefs that point to self # FIXME: this is ugly and won’t always be correct return true if href == '.' # Skip hrefs that are specified in the exclude configuration - return true if excluded?(href) + return true if excluded?(href, origin) # Remove target path = href.sub(/#.*$/, '') return true if path.empty? @@ -63,11 +63,22 @@ # Nope :( false end - def excluded?(href) - excludes = @config.fetch(:checks, {}).fetch(:internal_links, {}).fetch(:exclude, []) + def excluded?(href, origin) + config = @config.fetch(:checks, {}).fetch(:internal_links, {}) + excluded_target?(href, config) || excluded_origin?(origin, config) + end + + def excluded_target?(href, config) + excludes = config.fetch(:exclude_targets, config.fetch(:exclude, [])) excludes.any? { |pattern| Regexp.new(pattern).match(href) } + end + + def excluded_origin?(origin, config) + relative_origin = origin[@config[:output_dir].size..-1] + excludes = config.fetch(:exclude_origins, []) + excludes.any? { |pattern| Regexp.new(pattern).match(relative_origin) } end end end