Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions _plugins/link-checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,19 @@ 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)
@site = 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
Expand Down Expand Up @@ -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

Expand All @@ -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)
Expand Down