forked from puppetlabs/puppet-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlink_report.rb
executable file
·57 lines (48 loc) · 1.58 KB
/
link_report.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env ruby
require 'yaml'
if ARGV.empty?
puts %Q{link_report.rb:
Prints a report on broken links (in one or more path prefixes) to stdout.
Before using this, you must run the 'build_and_check_links' rake task.
Usage:
./link_report.rb <PREFIX> [<PREFIX>]
Example:
bundle exec rake build_and_check_links; say "I'm done"
./link_report.rb /pe/2015.3 | bbedit}
exit
end
PREFIXES = "(#{ARGV.join('|')})"
LINK_CHECK_YAML = File.join(File.dirname(__FILE__), 'link_test_results.yaml')
USING_HOSTNAME_IS_OK = [
%r{^/puppet/[^/]+/reference/(function\.|http_api/|indirection\.|configuration\.|man/|metaparameter\.|report\.|type\.|types/)}
]
all_info = YAML.load( File.read( LINK_CHECK_YAML ))
kinds = {
:broken_anchor => "GLITCHY: in-page anchor is broken",
:broken_path => "BROKEN: URL doesn't resolve",
:internal_with_hostname => "UGLY: Internal links with protocol and hostname",
:redirected => "STALE: redirected to a new URL."
}
subset = all_info.select {|key, val| key =~ /^#{PREFIXES}/ }.sort
# Suppress hostname warnings for pages that SHOULD be using the docs site hostname
subset.each do |page, report|
if USING_HOSTNAME_IS_OK.detect {|match| page =~ match}
report.delete(:internal_with_hostname)
end
end
subset.delete_if do |page, report|
report.empty?
end
# Print the report
subset.each do |page, report|
puts "--------------------------------------"
puts "file: #{page}"
report.each do |kind, links|
next unless kinds.include?(kind)
puts "--#{kinds[kind]}"
links.each do |link|
puts " #{link}"
end
puts ""
end
end