summaryrefslogtreecommitdiff
path: root/lib/views.ml
diff options
context:
space:
mode:
Diffstat (limited to 'lib/views.ml')
-rw-r--r--lib/views.ml77
1 files changed, 17 insertions, 60 deletions
diff --git a/lib/views.ml b/lib/views.ml
index b625ca6..797c405 100644
--- a/lib/views.ml
+++ b/lib/views.ml
@@ -1,7 +1,7 @@
type head_data = { page_title : string }
type body_data = {
- title : string;
+ title : string Lwt.t;
subtitle : string;
topnav : Dream_html.node;
content : Dream_html.node list;
@@ -14,11 +14,13 @@ module Layout = struct
let header title subtitle =
null [ h1 [] [ txt "%s" title ]; h2 [] [ txt "%s" subtitle ] ]
- let footer name =
+ 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 [ "©"; year; name ] in
+ let footer_text =
+ String.concat space [ "Copyright"; year; Config.author ]
+ in
footer [] [ txt "%s" footer_text ]
let head_data = { page_title = "Ogit" }
@@ -33,10 +35,10 @@ module Layout = struct
];
body []
[
- header body_data.title body_data.subtitle;
+ header "Ogit" body_data.subtitle;
body_data.topnav;
div [ id "main" ] body_data.content;
- footer "Marius PETER";
+ footer;
];
]
end
@@ -52,7 +54,7 @@ module Ogit_root = struct
let body_data =
{
- title = "My repositories";
+ title = Lwt.return "My repositories";
subtitle = "Repositories for " ^ Config.author;
topnav = null [];
content = [ repositories_in Config.git_directory ];
@@ -64,8 +66,6 @@ end
module Repo_root = struct
open Dream_html
open HTML
- open Git
- open Lwt.Infix
let topnav =
nav
@@ -73,62 +73,19 @@ module Repo_root = struct
[
ul []
[
- li [] [ a [ href "/" ] [ txt "Home" ] ];
- 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" ] ];
+ 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" ] ];
];
]
let render repo_name =
- let repo_path = Filename.concat Config.git_directory repo_name in
-
- (* 1. Open the Git repository *)
- let%lwt repo =
- Git_unix.Store.v (Fpath.v repo_path) >>= function
- | Ok repo -> Lwt.return repo
- | Error _ -> Lwt.fail_with "Could not open the Git repository."
- in
-
- (* 2. Resolve HEAD to get the latest commit hash *)
- let%lwt commit_hash =
- Git_unix.Store.Ref.resolve repo Reference.master >>= function
- | Ok hash -> Lwt.return hash
- | Error _ -> Lwt.fail_with "Failed to resolve HEAD"
- in
-
- (* (\* 3. Read the commit *\) *)
- (* let%lwt commit = *)
- (* Commit.v repo commit_hash >>= function *)
- (* | Ok commit -> Lwt.return commit *)
- (* | Error _ -> Lwt.fail_with "Failed to read the commit." *)
- (* in *)
-
- (* (\* 4. Read the tree from the commit *\) *)
- (* let%lwt tree = *)
- (* Tree.v commit.Commit.tree >>= function *)
- (* | Ok tree -> Lwt.return tree *)
- (* | Error _ -> Lwt.fail_with "Failed to read the tree." *)
- (* in *)
-
- (* (\* 5. Generate HTML list items for each tree entry *\) *)
- (* let entries = Tree.entries tree in *)
- (* let items = *)
- (* List.map *)
- (* (fun entry -> *)
- (* let icon = match entry.Tree.perm with `Dir -> "📁 " | _ -> "📄 " in *)
- (* li [] [ a [ href "#" ] [ txt (icon ^ entry.Tree.name) ] ]) *)
- (* entries *)
- (* in *)
-
- (* 6. Assemble the page *)
- let content =
- [ ul [] [ li [] [ txt "%s" (commit_hash |> Digestif.SHA1.to_hex) ] ] ]
- in
- let title = repo_name in
- let subtitle = Git_unix.(repo |> Store.root |> Fpath.to_string) in
+ let title = Git_helpers.get_head_commit_hash repo_name in
+ let subtitle = "Repository" in
+ let content = [ null [] ] in
let body_data = { title; subtitle; topnav; content } in
Lwt.return @@ Layout.application body_data
end
Copyright 2019--2025 Marius PETER