summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarius Peter <marius.peter@tutanota.com>2025-05-18 19:21:17 +0200
committerMarius Peter <marius.peter@tutanota.com>2025-05-18 19:21:17 +0200
commitf0c8906cd19479447ff5d0c1044ecbad6ab845d6 (patch)
treeb8f837b190099bf05cdc4c81f214b81c5b23c95c
parente457b7a8702ae3672cb65d8b3d394dd112594a89 (diff)
Good progress today 💯
-rw-r--r--lib/handlers.ml2
-rw-r--r--lib/views.ml28
2 files changed, 20 insertions, 10 deletions
diff --git a/lib/handlers.ml b/lib/handlers.ml
index 321c693..17b9eab 100644
--- a/lib/handlers.ml
+++ b/lib/handlers.ml
@@ -12,7 +12,7 @@ module Repo = struct
let repo_path req = Dream.param req "repo_name"
let summary req =
- let branches = Git_helpers.Branch.all_branches (repo_path req) in
+ let* branches = Git_helpers.Branch.all_branches (repo_path req) in
let* commits = Git_helpers.Commit.recent_commits (repo_path req) 10 in
let authors = [ "John Pork"; "Sebastian Jellybean" ] in
Views.Repo.summary (repo_path req) branches commits authors
diff --git a/lib/views.ml b/lib/views.ml
index e023236..ccaf73b 100644
--- a/lib/views.ml
+++ b/lib/views.ml
@@ -3,21 +3,21 @@ type head_data = { page_title : string }
type body_data = {
title : string;
subtitle : string;
+ topnav : Dream_html.node;
content : Dream_html.node list;
}
module Components = struct
open Dream_html
- let topnav current_path =
+ let topnav repo_path =
let open HTML in
+ let () = Dream.log "%s" ("current path is: " ^ repo_path) in
let li_of_a (path, text) =
- let is_active = path = current_path in
+ let () = Dream.log "%s" ("and path is: " ^ path) in
+ let is_active = String.ends_with ~suffix:path repo_path in
let attrs = if is_active then [ id "active" ] else [] in
- let url =
- if String.equal path "/" then Printf.sprintf "/%s/" current_path
- else Printf.sprintf "/%s/%s" current_path path
- in
+ let url = Printf.sprintf "/%s/%s" repo_path path in
li attrs [ a [ href "%s" url ] [ txt text ] ]
in
nav
@@ -26,7 +26,7 @@ module Components = struct
ul []
@@ List.map li_of_a
[
- ("/", "summary");
+ ("", "summary");
("refs/", "refs");
("log/", "log");
("tree/", "tree");
@@ -40,6 +40,10 @@ module Page = struct
open HTML
let header title subtitle =
+ let subtitle =
+ if String.starts_with ~prefix:"Unnamed repository" subtitle then ""
+ else subtitle
+ in
null [ h1 [] [ txt "%s" title ]; h2 [] [ txt "%s" subtitle ] ]
let footer () =
@@ -63,7 +67,7 @@ module Page = struct
body []
[
header body_data.title body_data.subtitle;
- Components.topnav body_data.title;
+ body_data.topnav;
div [ id "main" ] body_data.content;
footer ();
];
@@ -85,6 +89,7 @@ let root () =
{
title = "Ogit";
subtitle = "Repositories for " ^ Config.author;
+ topnav = HTML.null [];
content = [ repositories_in Config.git_directory ];
}
in
@@ -126,6 +131,7 @@ module Repo = struct
{
title = repo_path;
subtitle = Git_helpers.repo_description repo_path;
+ topnav = Components.topnav repo_path;
content;
}
@@ -136,6 +142,7 @@ module Repo = struct
{
title = repo_path;
subtitle = Git_helpers.repo_description repo_path;
+ topnav = Components.topnav repo_path;
content = [ null [] ];
}
@@ -146,6 +153,7 @@ module Repo = struct
{
title = repo_path;
subtitle = Git_helpers.repo_description repo_path;
+ topnav = Components.topnav repo_path;
content = [ null [] ];
}
@@ -156,6 +164,7 @@ module Repo = struct
{
title = repo_path;
subtitle = Git_helpers.repo_description repo_path;
+ topnav = Components.topnav repo_path;
content = [ null [] ];
}
@@ -165,7 +174,8 @@ module Repo = struct
let message = match commit.message with Some msg -> msg | None -> "" in
let content = HTML.[ h3 [] [ txt "%s" message ] ] in
let title = Printf.sprintf "%s : %s" repo_path (short_hash commit.hash) in
- Page.render { title; subtitle = ""; content }
+ Page.render
+ { title; subtitle = ""; topnav = Components.topnav repo_path; content }
end
let error_page message =
Copyright 2019--2025 Marius PETER