mirror of
https://github.com/c-cube/tiny_httpd.git
synced 2025-12-06 11:15:35 -05:00
feat(bin): use details for hiding hidden files by default
This commit is contained in:
parent
2b95c181b8
commit
6ddc38a7c1
1 changed files with 9 additions and 2 deletions
|
|
@ -42,6 +42,8 @@ let (//) = Filename.concat
|
||||||
let encode_path s =
|
let encode_path s =
|
||||||
U.percent_encode ~skip:(fun c -> c='/') s
|
U.percent_encode ~skip:(fun c -> c='/') s
|
||||||
|
|
||||||
|
let is_hidden s = String.length s>0 && s.[0] = '.'
|
||||||
|
|
||||||
let html_list_dir ~top ~parent d : string =
|
let html_list_dir ~top ~parent d : string =
|
||||||
let entries = Sys.readdir @@ (top // d) in
|
let entries = Sys.readdir @@ (top // d) in
|
||||||
Array.sort compare entries;
|
Array.sort compare entries;
|
||||||
|
|
@ -57,8 +59,13 @@ let html_list_dir ~top ~parent d : string =
|
||||||
Printf.bprintf body "<a href=\"/%s\"> (parent directory) </a>\n" p;
|
Printf.bprintf body "<a href=\"/%s\"> (parent directory) </a>\n" p;
|
||||||
end;
|
end;
|
||||||
Printf.bprintf body "<ul>\n";
|
Printf.bprintf body "<ul>\n";
|
||||||
Array.iter
|
Array.iteri
|
||||||
(fun f ->
|
(fun i f ->
|
||||||
|
if is_hidden f && (i=0 || not (is_hidden entries.(i-1))) then (
|
||||||
|
Printf.bprintf body "<details> <summary>(hidden files)</summary>\n";
|
||||||
|
) else if not (is_hidden f) && i>0 && is_hidden entries.(i-1) then (
|
||||||
|
Printf.bprintf body "</details/>\n";
|
||||||
|
);
|
||||||
if not @@ contains_dot_dot (d // f) then (
|
if not @@ contains_dot_dot (d // f) then (
|
||||||
let fpath = top // d // f in
|
let fpath = top // d // f in
|
||||||
if not @@ Sys.file_exists fpath then (
|
if not @@ Sys.file_exists fpath then (
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue