diff --git a/src/converters/html.ml b/src/converters/html.ml index bfd9f0e..ca60316 100644 --- a/src/converters/html.ml +++ b/src/converters/html.ml @@ -15,7 +15,7 @@ let default_style = "/static/main.css" let page ?(style=default_style) blog_url head_title header main = html (head ~style head_title) (body [ header; main ]) -let heading1 data = h1 [ pcdata data ] +let heading1 = h1 let header = header diff --git a/src/converters/template.ml b/src/converters/template.ml index 54289a1..c16efe1 100644 --- a/src/converters/template.ml +++ b/src/converters/template.ml @@ -47,12 +47,12 @@ let front ps = map_tpl_opt (fun v -> Front v) ps.Configuration.front ps let list ps = map_tpl_opt (fun v -> List v) ps.Configuration.list ps let item ps = map_tpl_opt (fun v -> Item v) ps.Configuration.item ps -let string s = Html.data s -let section ~inverted name contents = Html.unescaped_data ("section " ^ String.concat "." name) -let unescaped elts = Html.unescaped_data "use escaped instead" -let partial ?indent name _ _ = Html.data "partials not supported" -let comment _ = Html.data "" -let concat l = l +let string s = [Html.data s] +let section ~inverted name contents = [Html.unescaped_data ("section " ^ String.concat "." name)] +let unescaped elts = [Html.unescaped_data "use escaped instead"] +let partial ?indent name _ _ = [Html.data "partials not supported"] +let comment _ = [Html.data ""] +let concat = List.concat let escaped_meta (meta : Logarion.Meta.t) e = let open Logarion in @@ -64,13 +64,12 @@ let escaped_meta (meta : Logarion.Meta.t) e = | tag -> Meta.value_with_name meta tag let escaped_note note e = match List.hd e with - | "body" -> Html.unescaped_data @@ Omd.to_html @@ Omd.of_string note.Logarion.Note.body - | _ -> Html.unescaped_data @@ escaped_meta note.Logarion.Note.meta e + | "body" -> [Html.unescaped_data @@ Omd.to_html @@ Omd.of_string note.Logarion.Note.body] + | _ -> [Html.unescaped_data @@ escaped_meta note.Logarion.Note.meta e] -let escaped_header blog_url title e = match List.hd e with - (* | "blog_url" -> *) - | "title" -> Html.heading1 title - | tag -> prerr_endline ("unknown tag: " ^ tag); Html.unescaped_data "" +let escaped_header archive e = match List.hd e with + | "title" -> [Html.heading1 [Html.anchor ("index.html") [Html.data archive.Logarion.Archive.Configuration.title]]] + | tag -> prerr_endline ("unknown tag: " ^ tag); [Html.unescaped_data ""] let anchor_of_meta meta = let module Meta = Logarion.Meta in @@ -84,7 +83,7 @@ let listing metas = let open Html in list_unordered @@ List.map (fun m -> list_item @@ anchor_of_meta @@ m) metas -let escaped_index ~from ~n metas e = Html.data "temp" +let escaped_index ~from ~n metas e = [Html.data "temp"] (* match List.hd e with *) (* | "navigation" -> *) (* "" *) @@ -100,16 +99,17 @@ let escaped_index ~from ~n metas e = Html.data "temp" (* Logarion.Meta.StringSet.fold (fun e a -> a ^ "
  • " ^ e ^ "
  • ") topics "" *) (* | e -> prerr_endline ("unknown tag: " ^ e); "" *) -let header_html template url title = match template with +let header_html template archive = match template with | Some (Header s) -> - Mustache.fold ~string ~section ~escaped:(escaped_header url title) ~unescaped ~partial ~comment ~concat:(fun l -> Html.div l) s - |> (fun x -> Html.header [x]) - | None -> Html.(header [heading1 title]) + Mustache.fold ~string ~section ~escaped:(escaped_header archive) ~unescaped ~partial ~comment ~concat s + |> (fun x -> Html.header x) + | None -> Html.(header [heading1 [title]]) let note_page ?(header_template=None) ?(note_template=None) ~style url title note = let note_html = match note_template with | Some (Note s) -> - Mustache.fold ~string ~section ~escaped:(escaped_note note) ~unescaped ~partial ~comment ~concat:(fun l -> Html.article l) s + Mustache.fold ~string ~section ~escaped:(escaped_note note) ~unescaped ~partial ~comment ~concat s + |> Html.article | None -> let open Logarion.Note in let open Logarion.Meta in @@ -128,7 +128,8 @@ let note_page ?(header_template=None) ?(note_template=None) ~style url title not let listing_page ?(header_template=None) ?(listing_template=None) ~style ~from ~n url title metas = let listing_html = match listing_template with | Some (Note s) -> - Mustache.fold ~string ~section ~escaped:(escaped_index ~from ~n metas) ~unescaped ~partial ~comment ~concat:(fun l -> Html.article l) s + Mustache.fold ~string ~section ~escaped:(escaped_index ~from ~n metas) ~unescaped ~partial ~comment ~concat s + |> Html.article | None -> Html.article [listing metas] in Html.to_string @@ Html.page ~style url title (header_html header_template url title) listing_html