1
+ require "jekyll"
2
+ require "html-proofer"
3
+
4
+ $site_source_dir = ARGV [ 0 ]
5
+ $site_dest_dir = ARGV [ 1 ]
6
+ $target_range = ARGV [ 2 ]
7
+
8
+ $only_proof_subset = !!$target_range && !$target_range. empty?
9
+
10
+ $proofer_runner = HTMLProofer ::Runner . new ( [ $site_dest_dir] , {
11
+ :type => :directory ,
12
+ :check_html => true ,
13
+ :allow_hash_href => true ,
14
+ :url_ignore => [
15
+ /example\. com/ ,
16
+ /https:\/ \/ github\. com\/ myuser\/ myrepo/ ,
17
+ /robosnap\. net/ ,
18
+ /https:\/ \/ github.com\/ ev3dev\/ ev3dev\. github\. io\/ edit\/ .*/ ,
19
+ /warmcat\. com/ ,
20
+ /robosnap\. net/ ,
21
+ /01\. org/
22
+ ]
23
+ } )
24
+
25
+ begin
26
+ $proofer_runner. run
27
+ rescue => e
28
+ puts e . message
29
+ end
30
+
31
+ failures = $proofer_runner. instance_variable_get :@failures
32
+
33
+ changed_dest_files = [ ]
34
+ if $only_proof_subset
35
+ $site = Jekyll ::Site . new ( Jekyll . configuration ( {
36
+ "source" => $site_source_dir + "/" ,
37
+ "config" => $site_source_dir + "/_config.yml" ,
38
+ "destination" => $site_dest_dir,
39
+ "safe" => true
40
+ } ) )
41
+ $site. read
42
+
43
+ $jekyll_file_map = { }
44
+ def save_entity_mapping ( jekyll_entity )
45
+ current_dest_file = File . expand_path ( jekyll_entity . destination $site. dest )
46
+ $jekyll_file_map[ File . expand_path ( jekyll_entity . path ) ] = current_dest_file
47
+ end
48
+
49
+ $site. pages . each do |page |
50
+ save_entity_mapping page
51
+ end
52
+
53
+ $site. posts . docs . each do |post |
54
+ save_entity_mapping post
55
+ end
56
+
57
+ $site. static_files . each do |file |
58
+ save_entity_mapping file
59
+ end
60
+
61
+ changed_source_files = `git -C "#{ $site_source_dir} " diff --name-only #{ $target_range} --` . split ( "\n " )
62
+ if $?. success?
63
+ changed_dest_files = changed_source_files . map { |file | $jekyll_file_map[ File . expand_path ( file ) ] } . compact
64
+ else
65
+ $only_proof_subset = false
66
+ end
67
+
68
+ end
69
+
70
+ fatal_failures = failures . select { |failure | !$only_proof_subset || ( changed_dest_files . include? File . expand_path ( failure . path ) ) }
71
+
72
+ if fatal_failures . empty?
73
+ puts "No fatal failures found. There may be non-fatal failures printed above."
74
+ exit 0
75
+ else
76
+ puts "The following fatal failures were found:"
77
+ fatal_failures . each do |failure |
78
+ puts "\t " + failure . to_s
79
+ end
80
+ exit 1
81
+ end
0 commit comments