From ffae61af1a13862ffc2bf9415313f5da3d90d38e Mon Sep 17 00:00:00 2001 From: Marius Peter Date: Wed, 28 May 2025 23:02:14 +0200 Subject: Add link_to route generator. --- lib/views.ml | 59 ++++++++++++++++++++++------------------------------------- 1 file changed, 22 insertions(+), 37 deletions(-) (limited to 'lib/views.ml') diff --git a/lib/views.ml b/lib/views.ml index 986aa35..33654ea 100644 --- a/lib/views.ml +++ b/lib/views.ml @@ -82,10 +82,8 @@ let root () = Sys.readdir config.git_project_root |> Array.to_list |> List.sort String.compare in - let li_of_repo repo = - HTML.(li [] [ a [ href "%s/" repo ] [ txt "%s" repo ] ]) - in - HTML.(div [ id "repositories" ] [ ul [] @@ List.map li_of_repo repos ]) + HTML.( + div [ id "repositories" ] [ ul [] @@ List.map Routes.li_of_repo repos ]) in let body_data = { @@ -100,25 +98,25 @@ let root () = module Repo = struct let page_title repo = Printf.sprintf "%s — %s" repo (repo_description repo) + let li_of_branch repo branch = + HTML.(li [] [ Routes.link_to branch.name (Tag (repo, branch.name)) ]) + + let li_of_commit repo commit = + match commit.message with + | Some msg -> + HTML.( + li [] + [ + Routes.link_to + (commit.short_hash ^ " - " ^ msg) + (Commit (repo, commit.hash)); + ]) + | None -> HTML.(li [] [ txt "%s" commit.short_hash ]) + let summary repo branches commits authors = - let li_of_branch branch = - HTML.(li [] [ a [ href "%s" branch.name ] [ txt "%s" branch.name ] ]) - in - let li_of_commit commit = - match commit.message with - | Some msg -> - HTML.( - li [] - [ - a - [ href "commit/?id=%s" commit.hash ] - [ txt "%s %s" commit.short_hash msg ]; - ]) - | None -> HTML.(li [] [ a [ href "" ] [ txt "caca!!" ] ]) - in - let li_of_author author = - HTML.(li [] [ a [ href "" ] [ txt "%s" author ] ]) - in + let li_of_branch = li_of_branch repo in + let li_of_commit = li_of_commit repo in + let li_of_author author = HTML.(li [] [ txt "%s" author ]) in let content = HTML. [ @@ -139,9 +137,7 @@ module Repo = struct } let refs repo branches = - let li_of_branch branch = - HTML.(li [] [ a [ href "%s" branch.name ] [ txt "%s" branch.name ] ]) - in + let li_of_branch = li_of_branch repo in let content = HTML.[ h3 [] [ txt "Branches" ]; ul [] (List.map li_of_branch branches) ] in @@ -154,18 +150,7 @@ module Repo = struct } let log repo commits = - let li_of_commit commit = - match commit.message with - | Some msg -> - HTML.( - li [] - [ - a - [ href "commit/?id=%s" commit.hash ] - [ txt "%s %s" commit.short_hash msg ]; - ]) - | None -> HTML.(li [] [ a [ href "" ] [ txt "caca!!" ] ]) - in + let li_of_commit = li_of_commit repo in let content = HTML. [ h3 [] [ txt "All commits" ]; ul [] (List.map li_of_commit commits) ] -- cgit v1.2.3