diff --git a/_plugins/link-checker.rb b/_plugins/link-checker.rb index 3eebed64fb9..6aef93566a2 100644 --- a/_plugins/link-checker.rb +++ b/_plugins/link-checker.rb @@ -55,6 +55,11 @@ module Jekyll::LinkChecker # Driven by environment variables, it indicates the need to fail the build for dead links @should_build_fatally + # For red warning/error output to terminal + class String + def red; "\e[31m#{self}\e[0m" end + end + # Initializes the singleton by recording the site # return [void] def self.init(site) @@ -62,6 +67,7 @@ def self.init(site) @urls = {} @failures = [] @base_url_matcher = /^#{@site.config["url"]}#{@site.baseurl}(\/.*)$/.freeze + @bad_url_matcher = /^#{@site.config["url"]}#{@site.baseurl}[^\/]/.freeze end # Processes a Document or Page and adds the links to a collection @@ -111,10 +117,15 @@ def self.verify(site) msg = "Found #{@failures.size} dead link#{@failures.size > 1 ? 's' : ''}:\n#{@failures.join("\n")}" unless @failures.empty? - if @should_build_fatally - raise msg + unless @failures.empty? + if @should_build_fatally + puts "\nLinkChecker: [Error] #{msg}\n".red + exit(1) + else + puts "\nLinkChecker: [Warning] #{msg}\n".red + end else - puts "\nLinkChecker: [Warning] #{msg}\n" + puts "\nLinkChecker: [Notice] All links verified.\n" end end @@ -127,6 +138,8 @@ def self.check(url) url = match[1] end + return false if @bad_url_matcher =~ url + if @external_matcher =~ url return true unless @check_external_links return self.check_external(url)