geochan/src/template_utils.ml

22 lines
598 B
OCaml
Raw Normal View History

2022-03-31 01:43:59 +02:00
let get_title content =
let open Soup in
try
let soup = content |> parse in
soup $ "h1" |> R.leaf_text
with Failure _e -> "Permap"
let render ?title content request =
let title =
match title with None -> get_title content | Some title -> title
in
Dream.html
@@ Template.render_unsafe ~title:(Dream.html_escape title)
~content:(Dream.html_escape content)
request
let render_unsafe ?title content request =
let title =
match title with None -> get_title content | Some title -> title
in
Dream.html @@ Template.render_unsafe ~title ~content request