summaryrefslogtreecommitdiff
path: root/lib/views.ml
diff options
context:
space:
mode:
authorMarius Peter <marius.peter@tutanota.com>2025-03-01 19:19:30 +0100
committerMarius Peter <marius.peter@tutanota.com>2025-03-01 19:19:30 +0100
commit4946275b48bfc92ce4b420e36c6cf48694776bbc (patch)
tree0dad20f647c17f90d5ba583539a8a2f02d11e5ce /lib/views.ml
parente92e763e06d58a03224189d53044c4f5e1f907f0 (diff)
Start work on Git "un"helper functions.
Worse is better. I'll revisit the OCaml Git package once I'm more comfortable with OCaml overall.
Diffstat (limited to 'lib/views.ml')
-rw-r--r--lib/views.ml85
1 files changed, 53 insertions, 32 deletions
diff --git a/lib/views.ml b/lib/views.ml
index 797c405..446d601 100644
--- a/lib/views.ml
+++ b/lib/views.ml
@@ -1,7 +1,7 @@
type head_data = { page_title : string }
type body_data = {
- title : string Lwt.t;
+ title : string;
subtitle : string;
topnav : Dream_html.node;
content : Dream_html.node list;
@@ -16,16 +16,13 @@ module Layout = struct
let footer =
let today = Unix.localtime (Unix.time ()) in
- let year = today.Unix.tm_year + 1900 |> string_of_int in
- let space = " " in
- let footer_text =
- String.concat space [ "Copyright"; year; Config.author ]
- in
+ let year = string_of_int (today.Unix.tm_year + 1900) in
+ let footer_text = Printf.sprintf "Copyright %s %s" year Config.author in
footer [] [ txt "%s" footer_text ]
- let head_data = { page_title = "Ogit" }
+ let default_head_data = { page_title = "Ogit" }
- let application ?(head_data = head_data) body_data =
+ let application ?(head_data = default_head_data) body_data =
html []
[
head []
@@ -48,44 +45,63 @@ module Ogit_root = struct
open HTML
let repositories_in directory =
- let repositories = Sys.readdir directory |> Array.to_list
- and li_of_repo repo = li [] [ a [ href "%s" repo ] [ txt "%s" repo ] ] in
- div [ id "repositories" ] [ ul [] @@ List.map li_of_repo repositories ]
+ try
+ let repos =
+ Sys.readdir directory |> Array.to_list |> List.sort String.compare
+ in
+ let li_of_repo repo = li [] [ a [ href "%s" repo ] [ txt "%s" repo ] ] in
+ div [ id "repositories" ] [ ul [] @@ List.map li_of_repo repos ]
+ with Sys_error _ ->
+ div [] [ txt "Error: Unable to read repository list." ]
let body_data =
{
- title = Lwt.return "My repositories";
+ title = "My repositories";
subtitle = "Repositories for " ^ Config.author;
topnav = null [];
content = [ repositories_in Config.git_directory ];
}
- let render () = Lwt.return @@ Layout.application body_data
+ let render () = Layout.application body_data
end
module Repo_root = struct
open Dream_html
open HTML
+ (* open Lwt.Syntax *)
- let topnav =
- nav
- [ id "top" ]
+ let render repo_path =
+ (* let* title_result = Git_helpers.get_head_commit_hash repo_path in *)
+ (* let title = *)
+ (* match title_result with Ok hash -> hash | Error msg -> "Error: " ^ msg *)
+ (* in *)
+ let title = "Finble" in
+ let subtitle = Filename.concat Config.git_directory repo_path in
+ let topnav =
+ nav
+ [ id "top" ]
+ [
+ ul []
+ [
+ li [] [ a [ href "/" ] [ txt "summary" ] ];
+ li [] [ a [ href "/" ] [ txt "refs" ] ];
+ li [] [ a [ href "/" ] [ txt "log" ] ];
+ li [] [ a [ href "/" ] [ txt "tree" ] ];
+ li [] [ a [ href "/" ] [ txt "commit" ] ];
+ li [] [ a [ href "/" ] [ txt "diff" ] ];
+ ];
+ ]
+ in
+ let recent_commits = Git_unhelpers.get_git_log repo_path in
+ let li_of_commit commit =
+ li [] [ a [ href "%s" commit ] [ txt "%s" commit ] ]
+ in
+ let content =
[
- ul []
- [
- li [] [ a [ href "/" ] [ txt "summary" ] ];
- li [] [ a [ href "/" ] [ txt "refs" ] ];
- li [] [ a [ href "/" ] [ txt "log" ] ];
- li [] [ a [ href "/" ] [ txt "tree" ] ];
- li [] [ a [ href "/" ] [ txt "commit" ] ];
- li [] [ a [ href "/" ] [ txt "diff" ] ];
- ];
+ h3 [] [ txt "Recent commits" ];
+ ul [] @@ List.map li_of_commit recent_commits;
]
-
- let render repo_name =
- let title = Git_helpers.get_head_commit_hash repo_name in
- let subtitle = "Repository" in
- let content = [ null [] ] in
+ in
let body_data = { title; subtitle; topnav; content } in
Lwt.return @@ Layout.application body_data
end
@@ -93,11 +109,16 @@ end
module Repo_tree = struct
open Dream_html
open HTML
+ open Lwt.Syntax
- let render repo_name =
- let title = repo_name and content = [ txt "foobar" ] in
+ let render repo_path =
+ let* title_result = Git_helpers.get_head_commit_hash repo_path in
+ let title =
+ match title_result with Ok hash -> hash | Error msg -> "Error: " ^ msg
+ in
let subtitle = "Dinglefops" in
let topnav = null [] in
+ let content = [ txt "foobar" ] in
let body_data = { title; subtitle; topnav; content } in
Lwt.return @@ Layout.application body_data
end
Copyright 2019--2025 Marius PETER