Skip to content

Instantly share code, notes, and snippets.

@vitaliel
Created July 20, 2018 14:19
Show Gist options
  • Save vitaliel/3e8e3208b99c98f373f8a30bb611b74a to your computer and use it in GitHub Desktop.
Save vitaliel/3e8e3208b99c98f373f8a30bb611b74a to your computer and use it in GitHub Desktop.
#!/usr/bin/env ocaml
#load "str.cma";;
let concat_file_parts l =
String.concat "." l;;
let change_ext name ext =
let old_parts = String.split_on_char '.' name in
match List.rev old_parts with
| [] -> ""
| [old_name] -> concat_file_parts [old_name; ext]
| _ :: tl ->
concat_file_parts (ext :: tl |> List.rev);;
let html_files =
Sys.readdir "."
|> Array.to_list
|> List.filter (function el -> Str.last_chars el 4 = ".htm");;
let cmd file =
let adoc = change_ext file "adoc" in
"lynx -dump " ^ file ^ " | gsed -f _cmds > " ^ adoc;;
let gen_adoc file =
let shell_cmd = cmd file in
print_string shell_cmd;
print_newline ();
if (Sys.command shell_cmd) > 0 then begin
print_string("Failed cmd for " ^ file);
print_newline ();
end
;;
let gen_adocs files =
List.iter gen_adoc files;
;;
let () =
(* print_string (change_ext "x1.erb.html" "haml"); *)
(* print_newline (); *)
(* print_string (cmd "ch1.htm"); *)
(* print_newline (); *)
gen_adocs html_files;
;;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment