diff options
| author | Marius Peter <marius.peter@tutanota.com> | 2025-01-19 20:00:18 +0100 | 
|---|---|---|
| committer | Marius Peter <marius.peter@tutanota.com> | 2025-01-19 20:00:18 +0100 | 
| commit | 8ab5f20f532bc6e9de38ee457b0ef8dd30c80374 (patch) | |
| tree | ceecccdb379a9298ca2eef7053b1887885134f8d /lib/helpers | |
Initial commit for ogit.
Diffstat (limited to 'lib/helpers')
| -rw-r--r-- | lib/helpers/dune | 9 | ||||
| -rw-r--r-- | lib/helpers/file_helpers.ml | 7 | ||||
| -rw-r--r-- | lib/helpers/html_helpers.ml | 18 | 
3 files changed, 34 insertions, 0 deletions
| diff --git a/lib/helpers/dune b/lib/helpers/dune new file mode 100644 index 0000000..a8c1733 --- /dev/null +++ b/lib/helpers/dune @@ -0,0 +1,9 @@ +(library + (name helpers) + (public_name ogit.helpers) + (libraries +   unix +   ogit.layouts) + (modules +   html_helpers +   file_helpers)) diff --git a/lib/helpers/file_helpers.ml b/lib/helpers/file_helpers.ml new file mode 100644 index 0000000..892d807 --- /dev/null +++ b/lib/helpers/file_helpers.ml @@ -0,0 +1,7 @@ +let list_files dir = +  try +    Array.to_list (Sys.readdir dir) +    |> List.map (fun file -> Printf.sprintf "<li>%s</li>" file) +    |> String.concat "" +  with _ -> +    "<li>Error: Unable to read directory</li>" diff --git a/lib/helpers/html_helpers.ml b/lib/helpers/html_helpers.ml new file mode 100644 index 0000000..da5addc --- /dev/null +++ b/lib/helpers/html_helpers.ml @@ -0,0 +1,18 @@ +(* Helper function to generate links for repositories *) +let generate_repo_links () = +  let git_dir = Filename.concat (Unix.getenv "HOME") "git" in +  if Sys.file_exists git_dir && Sys.is_directory git_dir then +    Sys.readdir git_dir +    |> Array.to_list +    |> List.map (fun repo -> Printf.sprintf "<li><a href='/%s/tree'>%s</a></li>" repo repo) +    |> String.concat "" +  else +    "<li>Error: '~/git' directory not found.</li>" + +(* Page layout function *) +let page_layout ~content = +  "<html><body>" +  ^ Layouts.Header.header () +  ^ Layouts.Topnav.topnav () +  ^ "<main>" ^ content ^ "</main>" +  ^ "</body></html>" | 
