zapashcanon
3 years ago
6 changed files with 141 additions and 40 deletions
@ -0,0 +1,61 @@ |
|||
version=0.18.0 |
|||
align-cases=false |
|||
align-constructors-decl=false |
|||
align-variants-decl=false |
|||
assignment-operator=end-line |
|||
break-before-in=fit-or-vertical |
|||
break-cases=all |
|||
break-collection-expressions=fit-or-vertical |
|||
break-fun-decl=wrap |
|||
break-fun-sig=wrap |
|||
break-infix=wrap |
|||
break-infix-before-func=false |
|||
break-separators=before |
|||
break-sequences=true |
|||
break-string-literals=auto |
|||
break-struct=force |
|||
cases-exp-indent=2 |
|||
cases-matching-exp-indent=normal |
|||
disambiguate-non-breaking-match=false |
|||
doc-comments=before |
|||
doc-comments-padding=2 |
|||
doc-comments-tag-only=default |
|||
dock-collection-brackets=false |
|||
exp-grouping=preserve |
|||
extension-indent=2 |
|||
field-space=loose |
|||
function-indent=2 |
|||
function-indent-nested=never |
|||
if-then-else=k-r |
|||
indent-after-in=0 |
|||
indicate-multiline-delimiters=space |
|||
indicate-nested-or-patterns=unsafe-no |
|||
infix-precedence=indent |
|||
leading-nested-match-parens=false |
|||
let-and=sparse |
|||
let-binding-indent=2 |
|||
let-binding-spacing=compact |
|||
let-module=compact |
|||
margin=80 |
|||
match-indent=0 |
|||
match-indent-nested=never |
|||
max-indent=68 |
|||
module-item-spacing=sparse |
|||
nested-match=wrap |
|||
ocp-indent-compat=false |
|||
parens-ite=false |
|||
parens-tuple=always |
|||
parens-tuple-patterns=multi-line-only |
|||
parse-docstrings=true |
|||
sequence-blank-line=preserve-one |
|||
sequence-style=terminator |
|||
single-case=compact |
|||
space-around-arrays=true |
|||
space-around-lists=true |
|||
space-around-records=true |
|||
space-around-variants=true |
|||
stritem-extension-indent=0 |
|||
type-decl=sparse |
|||
type-decl-indent=2 |
|||
wrap-comments=false |
|||
wrap-fun-args=true |
@ -1,47 +1,72 @@ |
|||
let rec gen in_path out_path = |
|||
if not @@ Utils.is_directory in_path then |
|||
Utils.error (Format.sprintf "directory `%s` doesn't exist" (Fpath.to_string in_path)); |
|||
Utils.error |
|||
(Format.sprintf "directory `%s` doesn't exist" (Fpath.to_string in_path)); |
|||
|
|||
let content = |
|||
match Bos.OS.Dir.contents ~dotfiles:true ~rel:true in_path with |
|||
| Ok content -> content |
|||
| Error _e -> Utils.error (Format.sprintf "can't get content of directory `%s`" (Fpath.to_string in_path)) |
|||
| Error _e -> |
|||
Utils.error |
|||
(Format.sprintf "can't get content of directory `%s`" |
|||
(Fpath.to_string in_path) ) |
|||
in |
|||
|
|||
begin match Bos.OS.Dir.create ~path:true ~mode:0o755 out_path with |
|||
| Ok true -> () |
|||
| Error _ | Ok false -> |
|||
Utils.error (Format.sprintf "can't create directory `%s` or it already exists" (Fpath.to_string out_path)) |
|||
begin |
|||
match Bos.OS.Dir.create ~path:true ~mode:0o755 out_path with |
|||
| Ok true -> () |
|||
| Error _ |
|||
| Ok false -> |
|||
Utils.error |
|||
(Format.sprintf "can't create directory `%s` or it already exists" |
|||
(Fpath.to_string out_path) ) |
|||
end; |
|||
|
|||
let index_f, index_d = List.fold_left (fun (index_f, index_d) filename -> |
|||
let in_path = Fpath.append in_path filename in |
|||
if Utils.is_directory in_path then begin |
|||
gen in_path (Fpath.append out_path in_path); |
|||
index_f, ((filename, in_path)::index_d) |
|||
end else if Utils.is_file in_path then begin |
|||
let file_path = Fpath.v (Fpath.to_string filename ^ ".html") in |
|||
File.gen in_path (Fpath.append out_path file_path); |
|||
((filename, file_path)::index_f), index_d |
|||
end else |
|||
Utils.error (Format.sprintf "can't gen `%s`" (Fpath.to_string in_path)) |
|||
) ([], []) |
|||
content |
|||
let index_f, index_d = |
|||
List.fold_left |
|||
(fun (index_f, index_d) filename -> |
|||
let in_path = Fpath.append in_path filename in |
|||
if Utils.is_directory in_path then begin |
|||
gen in_path (Fpath.append out_path in_path); |
|||
(index_f, (filename, in_path) :: index_d) |
|||
end else if Utils.is_file in_path then begin |
|||
let file_path = Fpath.v (Fpath.to_string filename ^ ".html") in |
|||
File.gen in_path (Fpath.append out_path file_path); |
|||
((filename, file_path) :: index_f, index_d) |
|||
end else |
|||
Utils.error |
|||
(Format.sprintf "can't gen `%s`" (Fpath.to_string in_path)) ) |
|||
([], []) content |
|||
in |
|||
|
|||
let index_f = List.map (fun (filename, path) -> |
|||
Format.sprintf {|<li><a href="%s">%s</a></li>|} (Fpath.to_string path) (Fpath.to_string filename) |
|||
) index_f in |
|||
let index_d = List.map (fun (filename, path) -> |
|||
Format.sprintf {|<li><a href="%s/index.html">%s</li>|} (Fpath.to_string path) (Fpath.to_string filename) |
|||
) index_d in |
|||
let index_f = |
|||
List.map |
|||
(fun (filename, path) -> |
|||
Format.sprintf {|<li><a href="%s">%s</a></li>|} (Fpath.to_string path) |
|||
(Fpath.to_string filename) ) |
|||
index_f |
|||
in |
|||
let index_d = |
|||
List.map |
|||
(fun (filename, path) -> |
|||
Format.sprintf {|<li><a href="%s/index.html">%s</li>|} |
|||
(Fpath.to_string path) (Fpath.to_string filename) ) |
|||
index_d |
|||
in |
|||
|
|||
let pp_list = Format.pp_print_list ~pp_sep:(fun fmt () -> Format.fprintf fmt "") Format.pp_print_string in |
|||
let content = Format.asprintf "<ul>%a%a</ul>" pp_list index_d pp_list index_f in |
|||
let pp_list = |
|||
Format.pp_print_list |
|||
~pp_sep:(fun fmt () -> Format.fprintf fmt "") |
|||
Format.pp_print_string |
|||
in |
|||
let content = |
|||
Format.asprintf "<ul>%a%a</ul>" pp_list index_d pp_list index_f |
|||
in |
|||
let content = Format.asprintf "%a" Html.pp content in |
|||
let index_path = Fpath.append out_path (Fpath.v "index.html") in |
|||
|
|||
begin match Bos.OS.File.write index_path content with |
|||
| Ok () -> () |
|||
| Error _e -> Utils.error (Format.sprintf "can't write to file `%s`" (Fpath.to_string index_path)) |
|||
end |
|||
match Bos.OS.File.write index_path content with |
|||
| Ok () -> () |
|||
| Error _e -> |
|||
Utils.error |
|||
(Format.sprintf "can't write to file `%s`" (Fpath.to_string index_path)) |
|||
|
@ -1,12 +1,18 @@ |
|||
let gen in_path out_path = |
|||
if not @@ Utils.is_file in_path then |
|||
Utils.error (Format.sprintf "file `%s` doesn't exist" (Fpath.to_string in_path)); |
|||
Utils.error |
|||
(Format.sprintf "file `%s` doesn't exist" (Fpath.to_string in_path)); |
|||
|
|||
let content = match Bos.OS.File.read in_path with |
|||
| Ok content -> Format.asprintf "%a" Html.pp content |
|||
| Error _e -> Utils.error (Format.sprintf "can't read file `%s`" (Fpath.to_string in_path)) |
|||
let content = |
|||
match Bos.OS.File.read in_path with |
|||
| Ok content -> Format.asprintf "%a" Html.pp content |
|||
| Error _e -> |
|||
Utils.error |
|||
(Format.sprintf "can't read file `%s`" (Fpath.to_string in_path)) |
|||
in |
|||
|
|||
match Bos.OS.File.write out_path content with |
|||
| Ok () -> () |
|||
| Error _e -> Utils.error (Format.sprintf "can't write to file `%s`" (Fpath.to_string out_path)) |
|||
| Error _e -> |
|||
Utils.error |
|||
(Format.sprintf "can't write to file `%s`" (Fpath.to_string out_path)) |
|||
|
Loading…
Reference in new issue