forked from delftswa/delftswa.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_links.rb
36 lines (27 loc) · 1019 Bytes
/
test_links.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
chapter_name = ARGV[0]
violating_links = []
def perform_check_on_path(path)
p "checking #{path}"
violating_links = []
content = File.read(path)
# Check for links with delftswa2014 in them
res = content.to_enum(:scan, /\[.*\]\((.*delftswa2014.*)\)/).map { Regexp.last_match }
violating_links += res.map { |match| { file: path, link: match[1] } } unless res.empty?
# Check for non-absolute links
res = content.to_enum(:scan, /\[.*\]\(((?!(https?)|\#|images).*)\)/).map { Regexp.last_match }
violating_links += res.map { |match| { file: path, link: match[1] } } unless res.empty?
return violating_links
end
Dir.glob("chapters/#{chapter_name}/**/*.md").each do |path|
violating_links += perform_check_on_path(path)
end
p ""
p ""
if violating_links.empty?
p "All looks well!"
else
p "Seems like some links are pointing to non-accessible locations, ensure they are ok please"
violating_links.each do |o|
p "In file #{o[:file]} the following link was suspicious #{o[:link]}"
end
end