diff options
| author | Marius Peter <marius.peter@tutanota.com> | 2025-05-28 23:02:14 +0200 | 
|---|---|---|
| committer | Marius Peter <marius.peter@tutanota.com> | 2025-05-28 23:02:14 +0200 | 
| commit | ffae61af1a13862ffc2bf9415313f5da3d90d38e (patch) | |
| tree | d1849eaf647e498e68cc0c9511d6b1d7f786dc62 /lib | |
| parent | 378d9f24bd19855b7aa59936d7104ab1203c42f3 (diff) | |
Add link_to route generator.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/dune | 4 | ||||
| -rw-r--r-- | lib/routes.ml | 30 | ||||
| -rw-r--r-- | lib/views.ml | 59 | 
3 files changed, 55 insertions, 38 deletions
| @@ -2,4 +2,6 @@  (library   (name ogit) - (libraries dream dream-html git-unix toml)) + (libraries dream dream-html git-unix toml) + (preprocess (pps dream-html.ppx))) + diff --git a/lib/routes.ml b/lib/routes.ml new file mode 100644 index 0000000..0778c18 --- /dev/null +++ b/lib/routes.ml @@ -0,0 +1,30 @@ +(* -*- mode: tuareg; -*- *) + +open Dream_html +open HTML + +type t = +  | Root +  | Repo of string +  | Tag of string * string +  | Commit of string * string +  | Tree of string * string * string +  | Blob of string * string * string + +let%path root_path = "/" +let%path repo_path = "/%s" +let%path tag_path = "/%s/refs/%s" +let%path commit_path = "/%s/commit/%s" +let%path tree_path = "/%s/tree/%s/%s" +let%path blob_path = "/%s/blob/%s/%s" + +let path_attr = function +  | Root -> path_attr href root_path +  | Repo repo -> path_attr href repo_path repo +  | Tag (repo, branch) -> path_attr href tag_path repo branch +  | Commit (repo, commit) -> path_attr href commit_path repo commit +  | Tree (repo, commit, path) -> path_attr href tree_path repo commit path +  | Blob (repo, commit, path) -> path_attr href blob_path repo commit path + +let link_to label route = a [ path_attr route ] [ txt "%s" label ] +let li_of_repo repo = li [] [ link_to repo (Repo repo) ] 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) ] | 
