summaryrefslogtreecommitdiff
path: root/lib/views.ml
diff options
context:
space:
mode:
Diffstat (limited to 'lib/views.ml')
-rw-r--r--lib/views.ml51
1 files changed, 25 insertions, 26 deletions
diff --git a/lib/views.ml b/lib/views.ml
index 029e311..ba87571 100644
--- a/lib/views.ml
+++ b/lib/views.ml
@@ -13,27 +13,26 @@ type body_data = {
module Components = struct
open Dream_html
- let topnav repo =
- let open HTML in
- let li_of_a (path, text) =
- let is_active = String.ends_with ~suffix:path repo in
- let attrs = if is_active then [ id "active" ] else [] in
- let url = Printf.sprintf "/%s/%s" repo path in
- li attrs [ a [ href "%s" url ] [ txt text ] ]
- in
- nav
- [ id "top" ]
- [
- ul []
- @@ List.map li_of_a
- [
- ("", "summary");
- ("refs/", "refs");
- ("log/", "log");
- ("tree/", "tree");
- ("commit/", "commit");
- ];
- ]
+ module Topnav = struct
+ type t = None | Summary | Log | Files | Refs
+
+ let v ?(active_path = None) repo =
+ let open HTML in
+ let nav_items =
+ [
+ (Routes.Repo repo, "Summary", Summary);
+ (Routes.Log repo, "Log", Log);
+ (Routes.Files repo, "Files", Files);
+ (Routes.Refs repo, "Refs", Refs);
+ ]
+ in
+ let li_of_item (route, text, path) =
+ let is_active = path = active_path in
+ let attrs = if is_active then [ id "active" ] else [] in
+ HTML.li attrs [ Routes.link_to route (txt "%s" text) ]
+ in
+ nav [ id "top" ] [ ul [] @@ List.map li_of_item nav_items ]
+ end
end
module Page = struct
@@ -146,7 +145,7 @@ module Repo = struct
{
title = repo;
subtitle = repo_description repo;
- topnav = Components.topnav repo;
+ topnav = Components.Topnav.(v ~active_path:Summary repo);
content;
}
@@ -162,7 +161,7 @@ module Repo = struct
{
title = repo;
subtitle = repo_description repo;
- topnav = Components.topnav repo;
+ topnav = Components.Topnav.(v ~active_path:Refs repo);
content;
}
@@ -178,7 +177,7 @@ module Repo = struct
{
title = repo;
subtitle = repo_description repo;
- topnav = Components.topnav repo;
+ topnav = Components.Topnav.(v ~active_path:Log repo);
content;
}
@@ -195,7 +194,7 @@ module Repo = struct
{
title;
subtitle = repo_description repo;
- topnav = Components.topnav repo;
+ topnav = Components.Topnav.(v ~active_path:Files repo);
content;
}
@@ -232,7 +231,7 @@ module Repo = struct
{
title;
subtitle = repo_description repo;
- topnav = Components.topnav repo;
+ topnav = Components.Topnav.v repo;
content;
}
end
Copyright 2019--2025 Marius PETER