let render ~title ~content = Template.render_unsafe ~title ~content:(Dream.html_escape content) let asset_loader _root path _request = match Content.read ("assets/" ^ path) with | None -> Dream.empty `Not_Found | Some asset -> Dream.respond asset let page path = match Content.read (path ^ ".md") with | None -> None | Some page -> Some (Omd.of_string page |> Omd.to_html) let () = Dream.run @@ Dream.logger @@ Dream.router [ Dream.get "/assets/**" (Dream.static ~loader:asset_loader "") ; Dream.get "/" (fun _request -> match page "index" with | None -> Dream.empty `Not_Found | Some content -> Dream.html (Template.render_unsafe ~title:"title" ~content) ) ; Dream.get "/badge" (fun request -> Dream.respond ~headers:[ ("Content-Type", "image/svg+xml") ] (let open Ocb in let label = match Dream.query "label" request with | None -> "Label" | Some label -> label in let color = match Dream.query "color" request with | None -> Color.Blue | Some color -> Color.of_string color in let style = match Dream.query "style" request with | None -> Style.Flat | Some style -> Style.of_string style in let label_color = match Dream.query "label_color" request with | None -> Color.Black | Some label_color -> Color.of_string label_color in let status = match Dream.query "status" request with | None -> "Status" | Some status -> status in let scale = match Dream.query "scale" request with | None -> 1. | Some scale -> begin match float_of_string_opt scale with | None -> 1. | Some scale -> scale end in Format.asprintf "%a" (Gen.mk ~label ~color ~style ~label_color ~status ~icon:None ~icon_width:0. ~scale ) ()) ) ] @@ Dream.not_found