diff options
-rw-r--r-- | lib/views.ml | 80 |
1 files changed, 42 insertions, 38 deletions
diff --git a/lib/views.ml b/lib/views.ml index b204674..986aa35 100644 --- a/lib/views.ml +++ b/lib/views.ml @@ -4,8 +4,6 @@ open Dream_html open Git_presenters open Config -type head_data = { page_title : string } - type body_data = { title : string; subtitle : string; @@ -58,14 +56,12 @@ module Page = struct let footer_text = Printf.sprintf "Copyright %s %s" year config.user in footer [] [ txt "%s" footer_text ] - let default_head_data = { page_title = "Ogit" } - - let render ?(head_data = default_head_data) body_data = + let render ?(page_title = "Ogit") body_data = html [] [ head [] [ - title [] "%s" head_data.page_title; + title [] "%s" page_title; link [ rel "stylesheet"; href "/static/styles.css" ]; link [ rel "icon"; type_ "image/x-icon"; href "/static/git_icon.svg" ]; @@ -102,6 +98,8 @@ let root () = Page.render body_data module Repo = struct + let page_title repo = Printf.sprintf "%s — %s" repo (repo_description repo) + let summary repo branches commits authors = let li_of_branch branch = HTML.(li [] [ a [ href "%s" branch.name ] [ txt "%s" branch.name ] ]) @@ -132,10 +130,10 @@ module Repo = struct ul [] (List.map li_of_author authors); ] in - Page.render + Page.render ~page_title:(page_title repo) { title = repo; - subtitle = Git_presenters.repo_description repo; + subtitle = repo_description repo; topnav = Components.topnav repo; content; } @@ -144,15 +142,16 @@ module Repo = struct let li_of_branch branch = HTML.(li [] [ a [ href "%s" branch.name ] [ txt "%s" branch.name ] ]) in - Page.render - HTML. - { - title = repo; - subtitle = Git_presenters.repo_description repo; - topnav = Components.topnav repo; - content = - [ h3 [] [ txt "Branches" ]; ul [] (List.map li_of_branch branches) ]; - } + let content = + HTML.[ h3 [] [ txt "Branches" ]; ul [] (List.map li_of_branch branches) ] + in + Page.render ~page_title:(page_title repo) + { + title = repo; + subtitle = repo_description repo; + topnav = Components.topnav repo; + content; + } let log repo commits = let li_of_commit commit = @@ -167,34 +166,39 @@ module Repo = struct ]) | None -> HTML.(li [] [ a [ href "" ] [ txt "caca!!" ] ]) in - Page.render + let content = HTML. - { - title = repo; - subtitle = Git_presenters.repo_description repo; - topnav = Components.topnav repo; - content = - [ - h3 [] [ txt "All commits" ]; ul [] (List.map li_of_commit commits); - ]; - } + [ h3 [] [ txt "All commits" ]; ul [] (List.map li_of_commit commits) ] + in + Page.render ~page_title:(page_title repo) + { + title = repo; + subtitle = repo_description repo; + topnav = Components.topnav repo; + content; + } let tree repo = - Page.render - HTML. - { - title = repo; - subtitle = Git_presenters.repo_description repo; - topnav = Components.topnav repo; - content = [ null [] ]; - } + let content = HTML.[ null [] ] in + Page.render ~page_title:(page_title repo) + { + title = repo; + subtitle = repo_description repo; + topnav = Components.topnav repo; + content; + } let commit repo commit = 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 commit.short_hash in - Page.render - { title; subtitle = ""; topnav = Components.topnav repo; content } + let content = HTML.[ h3 [] [ txt "%s" message ] ] in + Page.render ~page_title:(page_title repo) + { + title; + subtitle = repo_description repo; + topnav = Components.topnav repo; + content; + } end let error_page message = |