diff options
author | Marius Peter <marius.peter@tutanota.com> | 2025-06-09 18:11:34 +0200 |
---|---|---|
committer | Marius Peter <marius.peter@tutanota.com> | 2025-06-09 18:11:34 +0200 |
commit | 50960c7ccbae4a4e8f4f53010543752635b4d8cd (patch) | |
tree | ec18a7dff3ab0beb6d2c5776ce43572dfdf8c004 /lib/views.ml | |
parent | afe686e6bab1d4b6a85b1f5c610f57fcf1a72d74 (diff) |
Implement Topnav module with proper routes.
Diffstat (limited to 'lib/views.ml')
-rw-r--r-- | lib/views.ml | 51 |
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 |