-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathfind-orphans
executable file
·39 lines (34 loc) · 969 Bytes
/
find-orphans
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
36
37
38
39
#!/usr/bin/env ruby
ROOT = File.dirname __dir__
PAGES = Dir["#{ROOT}/docs/**/*.md", "#{ROOT}/docs/**/*.yml"]
linked = Dir[
"#{ROOT}/docs/index.md",
"#{ROOT}/docs/*/commands/_*.yml",
"#{ROOT}/docs/*/configuration/_*.yml",
"#{ROOT}/docs/server/messages/*.yml",
].to_a
PAGES.each do |file|
contents = File.read(file)
# Markdown links
contents.scan(/\[[^\]]+\]\(\/([^\)]+?)\/?(?:\#[^\)]+|\/)?\)/).each do |link|
linked << "#{ROOT}/docs/#{link[0]}.md"
linked << "#{ROOT}/docs/#{link[0]}.yml"
linked << "#{ROOT}/docs/#{link[0]}/index.md"
end
# Markdown includes
contents.scan(/\{!\s*(\S+)\s*!\}/).each do |fragment|
linked << "#{ROOT}/docs/#{fragment[0]}"
end
# Jinja includes
contents.scan(/\{%\s*include\s*"(\S+)"\s*%}/).each do |fragment|
linked << "#{ROOT}/docs/#{fragment[0]}"
end
end
orphaned = 0
PAGES.each do |file|
next if linked.include? file
puts "Orphaned: #{file}"
orphaned += 1
end
puts "#{orphaned} orphaned!"
exit orphaned