1
+ require 'yaml'
2
+
1
3
task :clean do
2
4
sh ( 'rm -rf _site' )
3
5
end
@@ -24,7 +26,23 @@ task :build => [:dependencies, :submodules] do
24
26
sh ( 'bundle exec jekyll build --config _config.yml' )
25
27
end
26
28
27
- task :validate => [ :build ] do
29
+ task :validate_kit_versions do
30
+ data = YAML . load_file ( '_data/kit_versions.yml' )
31
+ data . each do |entry |
32
+ actual = entry . keys . to_set
33
+ expected = [ 'version' , 'released' ] . to_set
34
+ missing = expected - actual
35
+ extra = actual - expected
36
+ messages = [ ]
37
+ messages << "Missing keys: #{ missing . to_a . join ( ', ' ) } " if missing . size ( ) > 0
38
+ messages << "Extra keys: #{ extra . to_a . join ( ', ' ) } " if extra . size ( ) > 0
39
+ raise "For entry\n #{ entry } \n #{ messages . join ( "\n " ) } \n \n " if messages . size ( ) > 0
40
+ end
41
+
42
+ puts "Kit versions validated successfully"
43
+ end
44
+
45
+ task :validate_links => [ :build ] do
28
46
# Explanation of arguments:
29
47
# --assume-extension # Tells html-proofer that `.html` files can be accessed without the `.html` part in the url.
30
48
# --disable-external # For speed. Ideally we'd check external links too, but ignoring for now.
@@ -33,3 +51,37 @@ task :validate => [:build] do
33
51
# --url-swap # Adjust for Jekyll's baseurl. See https://github.com/gjtorikian/html-proofer/issues/618 for more.
34
52
sh ( 'bundle exec htmlproofer _site --assume-extension --disable-external --empty-alt-ignore --allow-hash-href --url-swap "^/docs/:/"' )
35
53
end
54
+
55
+ task :validate_sidebar_tree => [ :build ] do
56
+ # There are lots of things which this could validate, however we assume that
57
+ # most changes will be eyeballed by a human. We therefore just check the most
58
+ # nuanced case -- that the url must be an exact match for its target page.
59
+
60
+ def check_url ( url )
61
+ if url . end_with? ( "/" ) then
62
+ return if File . directory? ( "_site#{ url } " )
63
+ raise "Imprecise target url '#{ url } ' in sidebar (did you mean '#{ url [ ..-2 ] } '?)\n \n "
64
+ else
65
+ return if File . file? ( "_site#{ url } .html" )
66
+ raise "Imprecise target url '#{ url } ' in sidebar (did you mean '#{ url } /'?)\n \n "
67
+ end
68
+ end
69
+
70
+ def check_nodes ( node )
71
+ check_url ( node [ 'url' ] )
72
+ if node [ 'tree' ] then
73
+ node [ 'tree' ] . each do |x |
74
+ check_nodes ( x )
75
+ end
76
+ end
77
+ end
78
+
79
+ data = YAML . load_file ( '_data/sidebar_tree.yaml' )
80
+ data [ 'tree' ] . each do |x |
81
+ check_nodes ( x )
82
+ end
83
+
84
+ puts "Sidebar links validated successfully"
85
+ end
86
+
87
+ task :validate => [ :validate_kit_versions , :validate_links , :validate_sidebar_tree ]
0 commit comments