Skip to content

Commit 60a5cac

Browse files
committed
Add validation of the sidebar links precision
This is needed to ensure that they correctly highlight the current page. This commit also fixes a case where the sidebar was out of step. Fixes #294.
1 parent 7db5215 commit 60a5cac

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

Rakefile

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,34 @@ task :validate_links => [:build] do
5050
sh('bundle exec htmlproofer _site --assume-extension --disable-external --empty-alt-ignore --allow-hash-href --url-swap "^/docs/:/"')
5151
end
5252

53-
task :validate => [:validate_kit_versions, :validate_links]
53+
task :validate_sidebar_tree do # => [:build] do
54+
# There are lots of things which this could validate, however we assume that
55+
# most changes will be eyeballed by a human. We therefore just check the most
56+
# nuanced case -- that the url must be an exact match for its target page.
57+
58+
def check_url(url)
59+
if url.end_with? "/" then
60+
raise "Imprecise target url '#{url}' in sidebar (did you mean '#{url[..-2]}'?)\n\n" unless File.directory?("_site#{url}")
61+
else
62+
raise "Imprecise target url '#{url}' in sidebar (did you mean '#{url}/'?)\n\n" unless File.file?("_site#{url}.html")
63+
end
64+
end
65+
66+
def check_nodes(node)
67+
check_url(node['url'])
68+
if node['tree'] then
69+
node['tree'].each do |x|
70+
check_nodes(x)
71+
end
72+
end
73+
end
74+
75+
data = YAML.load_file('_data/sidebar_tree.yaml')
76+
data['tree'].each do |x|
77+
check_nodes(x)
78+
end
79+
80+
puts "Sidebar links validated successfully"
81+
end
82+
83+
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)