@@ -68,7 +68,7 @@ let get_ok = function
68
68
Format. eprintf " get_ok: Failure! msg=%s\n %!" m;
69
69
failwith " get_ok: Not OK"
70
70
71
- let generate_pkgver output_dir name_filter version_filter =
71
+ let generate_pkgver output_dir name_filter version_filter check_links_flag =
72
72
let linkedpath = Fpath. (v " linked" ) in
73
73
match
74
74
Bos.OS.Dir. fold_contents ~elements: `Dirs
@@ -158,27 +158,29 @@ let generate_pkgver output_dir name_filter version_filter =
158
158
Package_info. gen ~input: parent ~output: output_prefix paths;
159
159
Rendering. render_other ~parent ~otherdocs ~output |> get_ok;
160
160
161
- let htmls =
162
- Voodoo_lib.Util. files_with_ext " .html.json" output_prefix
163
- in
164
161
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 []
182
184
in
183
185
184
186
let otherdocs =
@@ -240,10 +242,15 @@ let package_version_opt =
240
242
& opt (some string ) None
241
243
& info ~docs ~docv: " VERSION" ~doc [ " pkg-version" ])
242
244
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
+
243
249
let default_cmd =
244
250
let doc = " Documentation generator" in
245
251
( 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),
247
254
Term. info " voodoo-gen" ~version ~doc ~exits: Term. default_exits )
248
255
249
256
let () = Term. (exit @@ eval default_cmd)
0 commit comments