-
Notifications
You must be signed in to change notification settings - Fork 2
/
bco-htmlproof
65 lines (53 loc) · 2.42 KB
/
bco-htmlproof
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
#!/usr/bin/env ruby
require 'html/proofer'
if ARGV[0].nil?
path_to_check="./_site"
else
path_to_check=ARGV[0]
end
## Will throw an exception (exiting false) if any internal links don't
## work. The Makefile will terminate on the failure
HTML::Proofer.new(
## To test, uncomment the array below and comment out ./_site and :disable_external
#[ "/foo/bar#baz", "/foo/bar", "#", "#wallet", "/foo.css", "/bar.png", "/zh_TW/bitcoin-for-businesses" ],
path_to_check,
{
## Disable external link checking by default to avoid spurious
## Travis CI failures. TODO: take an argument to optionally
## enable external link checking as part of the Makefile
## manual checks
:disable_external => true,
## Check whether HTML is well-formed
:check_html => true,
## Links to ignore
:href_ignore => [
'#', ## hrefs pointing to the current page (htmlproofer fails them)
/^$/, ## anchors with no href attribute set (for clickable javascript elements)
/^\/bin/, ## /bin dir is not part of repository; holds Bitcoin Core binaries
'bitcoin:3FkenCiXpSLqD8L79intRNXUgjRoH9sjXa', ## bitcoin address handlers
/^\/stats/ ## /stats dir is not part of repository; generated by separate stats script
],
## Mangle links. If we enable external link checking, this will
## require updating
:href_swap => {
## (Hack) Append '$' to the ends of filenames we don't want to append .html to
/(css|png|rss|pdf|jpg|asc|xml)$/ => '\1$',
## Append .html to end of most URLs so proofer can find the local files
/^(
[^#]+ ## Don't match URL containing a hash, we'll deal with them separately
[^\/$] ## Don't match URLs ending in a slash or $
)$/x => '\1.html',
## Insert .html between page and anchor, but only if there's a
## page name
/^(.+)(#.+)/ => '\1.html\2',
/\/(.html#.+)/ => '\1',
## (Un-hack) Remove previously-appended '$' from URLs
/\$$/ => '',
},
## It'd be nice if we had a _local_config.yaml file or something
## for settings specific to particular systems, but for now I
## think 2 is a good setting for Travis CI ("1.5 processors")
## and me (usually 2 processors)
:parallel => { :in_processes => 2 }
}
).run