From c366e7377b7de5f333741d1c64c49cb848cad05c Mon Sep 17 00:00:00 2001 From: Marius Peter Date: Sun, 20 Jul 2025 16:32:52 +0200 Subject: Factor out page header and body. --- lib/views.ml | 47 +++++++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 26 deletions(-) (limited to 'lib/views.ml') diff --git a/lib/views.ml b/lib/views.ml index d2f4501..9345bf0 100644 --- a/lib/views.ml +++ b/lib/views.ml @@ -49,28 +49,29 @@ module Page = struct let footer_text = Printf.sprintf "Copyright %s %s" year config.user in HTML.footer [] [ txt "%s" footer_text ] - let render ?(page_title = "Ogit") body_data = + let head page_title = + let open HTML in + head [] + [ + title [] "%s" page_title; + link [ rel "stylesheet"; href "/static/styles.css" ]; + link [ rel "icon"; type_ "image/x-icon"; href "/static/git_icon.svg" ]; + ] + + let body bd = let open HTML in - let bd = body_data in - html [] + body [] [ - head [] - [ - title [] "%s" page_title; - link [ rel "stylesheet"; href "/static/styles.css" ]; - link - [ rel "icon"; type_ "image/x-icon"; href "/static/git_icon.svg" ]; - ]; - body [] - [ - page_header bd.title bd.subtitle; - (match bd.repo with - | None -> HTML.null [] - | Some repo -> Components.topnav ~active:bd.active repo); - div [ id "main" ] bd.content; - page_footer (); - ]; + page_header bd.title bd.subtitle; + (match bd.repo with + | None -> HTML.null [] + | Some repo -> Components.topnav ~active:bd.active repo); + div [ id "main" ] bd.content; + page_footer (); ] + + let render ?(page_title = "Ogit") body_data = + HTML.html [] [ head page_title; body body_data ] end let root () = @@ -240,13 +241,7 @@ let error_page message = respond @@ html [] [ - head [] - [ - title [] "Fatal error"; - link [ rel "stylesheet"; href "/static/styles.css" ]; - link - [ rel "icon"; type_ "image/x-icon"; href "/static/git_icon.svg" ]; - ]; + Page.head "Fatal Error"; body [] [ h1 [] [ txt "Fatal Error" ]; -- cgit v1.2.3