Skip to content

Commit 4568ac8

Browse files
committed
make checking links a flag
1 parent 02a381c commit 4568ac8

File tree

2 files changed

+31
-24
lines changed

2 files changed

+31
-24
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ prep: _generated
7474
.PHONY: example
7575
example: all prep ## Build an sample output
7676
cd _generated; opam exec -- dune exec -- voodoo-do -p ocaml-base-compiler -b
77-
cd _generated; opam exec -- dune exec -- voodoo-gen -o output
77+
cd _generated; opam exec -- dune exec -- voodoo-gen -o output --check-links
7878

7979
.PHONY: gen
8080
gen:
8181
cd _generated; rm -rf output
82-
cd _generated; opam exec -- dune exec -- voodoo-gen -o output
82+
cd _generated; opam exec -- dune exec -- voodoo-gen -o output --check-links
8383

8484
.PHONY: serve
8585
serve:

src/voodoo-gen/main.ml

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ let get_ok = function
6868
Format.eprintf "get_ok: Failure! msg=%s\n%!" m;
6969
failwith "get_ok: Not OK"
7070

71-
let generate_pkgver output_dir name_filter version_filter =
71+
let generate_pkgver output_dir name_filter version_filter check_links_flag =
7272
let linkedpath = Fpath.(v "linked") in
7373
match
7474
Bos.OS.Dir.fold_contents ~elements:`Dirs
@@ -158,27 +158,29 @@ let generate_pkgver output_dir name_filter version_filter =
158158
Package_info.gen ~input:parent ~output:output_prefix paths;
159159
Rendering.render_other ~parent ~otherdocs ~output |> get_ok;
160160

161-
let htmls =
162-
Voodoo_lib.Util.files_with_ext ".html.json" output_prefix
163-
in
164161
let broken_link_files =
165-
List.fold_left
166-
(fun acc path ->
167-
let links =
168-
Bos.OS.File.read path |> get_ok
169-
|> Olinkcheck.Html.from_string
170-
|> Olinkcheck.Html.extract_links
171-
in
172-
let status = Olinkcheck.Link.status_many links in
173-
let broken =
174-
List.combine status links
175-
|> List.filter (fun ((code, _), _) -> code <> 200)
176-
in
177-
if List.length broken <> 0 then
178-
let entry = { file = path; broken_links = broken } in
179-
entry :: acc
180-
else acc)
181-
[] htmls
162+
if check_links_flag then
163+
let htmls =
164+
Voodoo_lib.Util.files_with_ext ".html.json" output_prefix
165+
in
166+
List.fold_left
167+
(fun acc path ->
168+
let links =
169+
Bos.OS.File.read path |> get_ok
170+
|> Olinkcheck.Html.from_string
171+
|> Olinkcheck.Html.extract_links
172+
in
173+
let status = Olinkcheck.Link.status_many links in
174+
let broken =
175+
List.combine status links
176+
|> List.filter (fun ((code, _), _) -> code <> 200)
177+
in
178+
if List.length broken <> 0 then
179+
let entry = { file = path; broken_links = broken } in
180+
entry :: acc
181+
else acc)
182+
[] htmls
183+
else []
182184
in
183185

184186
let otherdocs =
@@ -240,10 +242,15 @@ let package_version_opt =
240242
& opt (some string) None
241243
& info ~docs ~docv:"VERSION" ~doc [ "pkg-version" ])
242244

245+
let check_links_flag =
246+
let doc = "Flag to check if the links in the documentation are broken" in
247+
Arg.(value & flag & info [ "check-links" ] ~doc)
248+
243249
let default_cmd =
244250
let doc = "Documentation generator" in
245251
( Term.(
246-
const generate_pkgver $ output $ package_name_opt $ package_version_opt),
252+
const generate_pkgver $ output $ package_name_opt $ package_version_opt
253+
$ check_links_flag),
247254
Term.info "voodoo-gen" ~version ~doc ~exits:Term.default_exits )
248255

249256
let () = Term.(exit @@ eval default_cmd)

0 commit comments

Comments
 (0)