Skip to content

Commit

Permalink
Improve logging of the link checker (opensearch-project#1252)
Browse files Browse the repository at this point in the history
Signed-off-by: Miki <[email protected]>

Signed-off-by: Miki <[email protected]>
  • Loading branch information
AMoo-Miki authored Sep 19, 2022
1 parent fc03a5e commit 9da8dc2
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions _plugins/link-checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def self.init(site)
@site = site
@urls = {}
@failures = []
@base_url_matcher = /^#{@site.config["url"]}#{@site.baseurl}(\/.*)$/.freeze
end

# Processes a Document or Page and adds the links to a collection
Expand All @@ -74,9 +75,12 @@ def self.process(page)
relative_path = page.path[0] == '/' ? Pathname.new(page.path).relative_path_from(Dir.getwd) : page.path

if href.start_with? '#'
p relative_path if (page.content =~ /<[a-z0-9-]+[^>]+id="#{href[1..]}"/i).nil?
@failures << "##{href[1..]}, linked in ./#{relative_path}" if (page.content =~ /<[a-z0-9-]+[^>]+id="#{href[1..]}"/i).nil?
else
match = @base_url_matcher.match(href)
unless match.nil?
href = match[1]
end
@urls[href] = Set[] unless @urls.key?(href)
@urls[href] << relative_path
end
Expand All @@ -101,8 +105,6 @@ def self.verify(site)
end
end

@base_url_matcher = /^#{@site.config["url"]}#{@site.baseurl}(\/.*)$/.freeze

@urls.each do |url, pages|
@failures << "#{url}, linked to in ./#{pages.to_a.join(", ./")}" unless self.check(url)
end
Expand Down

0 comments on commit 9da8dc2

Please sign in to comment.