-
Notifications
You must be signed in to change notification settings - Fork 1
/
Checks
65 lines (55 loc) · 2.13 KB
/
Checks
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
require 'open3'
require 'json'
require 'nokogiri'
check :html5 do
cmd = "java -jar opt/validator/vnu.jar --format json --skip-non-html --schema http://s.validator.nu/html5-all.rnc #{@config[:output_dir]}"
res = Open3.popen3(cmd) { |_stdin, _stdout, stderr| stderr.read }
JSON.parse(res).fetch('messages', []).each do |err|
subject = err['url'].sub(/^file:#{Regexp.escape(__dir__)}\//, '')
add_issue("#{err['message']} (line #{err['lastLine']}, column #{err['firstColumn']})", subject: subject)
end
end
check :no_unprocessed_erb do
@output_filenames.each do |filename|
if @config[:text_extensions].any? { |ext| filename =~ /#{ext}$/ } && File.read(filename).match(/<%/)
add_issue("erb detected", :subject => filename)
end
end
end
check :no_unprocessed_markdown do
@output_filenames.each do |filename|
if filename =~ /html$/ && File.read(filename).match(/]\(/)
add_issue('unprocessed markdown detected', subject: filename)
end
end
end
check :no_static_build_paths do
filenames = @output_filenames.select { |f| File.extname(f) == '.html' }
hrefs_with_filenames = ::Nanoc::Extra::LinkCollector.new(filenames, :internal).filenames_per_href
resource_uris_with_filenames = ::Nanoc::Extra::LinkCollector.new(filenames, :internal).filenames_per_resource_uri
uris = hrefs_with_filenames.merge(resource_uris_with_filenames)
uris.each_pair do |href, fns|
fns.each do |filename|
if href.start_with?(@config[:static_root])
add_issue("private build path detected in #{href}", subject: filename)
end
end
end
end
check :spelling do
filenames = @output_filenames.select { |f| File.extname(f) == '.html' }
filenames.each do |filename|
doc = Nokogiri::HTML(File.read(filename))
doc.xpath('descendant-or-self::mark[@class="misspelled"]').each do |node|
add_issue("misspelled word '#{node.text}' detected on line #{node.line}", subject: filename)
end
end
end
deploy_check :internal_links
deploy_check :mixed_content
deploy_check :stale
deploy_check :no_unprocessed_erb
deploy_check :no_unprocessed_markdown
deploy_check :no_static_build_paths
deploy_check :spelling
# vi: ft=ruby