Skip to content

Commit 214b59a

Browse files
committed
Merge branch 'validate-data'
2 parents c9c5d2a + 4c2f482 commit 214b59a

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

Rakefile

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'yaml'
2+
13
task :clean do
24
sh('rm -rf _site')
35
end
@@ -24,7 +26,23 @@ task :build => [:dependencies, :submodules] do
2426
sh('bundle exec jekyll build --config _config.yml')
2527
end
2628

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
2846
# Explanation of arguments:
2947
# --assume-extension # Tells html-proofer that `.html` files can be accessed without the `.html` part in the url.
3048
# --disable-external # For speed. Ideally we'd check external links too, but ignoring for now.
@@ -33,3 +51,37 @@ task :validate => [:build] do
3351
# --url-swap # Adjust for Jekyll's baseurl. See https://github.com/gjtorikian/html-proofer/issues/618 for more.
3452
sh('bundle exec htmlproofer _site --assume-extension --disable-external --empty-alt-ignore --allow-hash-href --url-swap "^/docs/:/"')
3553
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]

_data/sidebar_tree.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ tree:
6363
tree:
6464
- url: /programming/sr/vision/markers
6565
title: Markers
66-
- url: /programming/editors
66+
- url: /programming/editors/
6767
title: Code Editors
6868
tree:
6969
- url: /programming/editors/vscode

0 commit comments

Comments
 (0)