From 637556360ebec8e99dc6339164756ee1340b10b9 Mon Sep 17 00:00:00 2001 From: Stavros Polymenis Date: Tue, 28 Nov 2017 23:03:12 +0000 Subject: [PATCH] Reorganise escape functions --- src/converters/template.ml | 52 ++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/src/converters/template.ml b/src/converters/template.ml index d3e964a..a8818cc 100644 --- a/src/converters/template.ml +++ b/src/converters/template.ml @@ -54,33 +54,23 @@ let partial ?indent name _ _ = "partials not supported" let comment c = c let concat l = String.concat "" l -let fold_note ymd = - let escaped e = match List.hd e with - | "body" -> Omd.to_html @@ Omd.of_string ymd.Logarion.Note.body - | tag -> Logarion.Meta.value_with_name ymd.Logarion.Note.meta tag in - Mustache.fold ~string ~section ~escaped ~unescaped ~partial ~comment ~concat - -let fold_meta (meta : Logarion.Meta.t) = +let escaped_meta (meta : Logarion.Meta.t) e = let open Logarion in - let escaped e = - let e = List.hd e in - match e with - | "url" -> "/note/" ^ Meta.alias meta - | "date" | "date_created" | "date_edited" | "date_published" | "date_human" -> - "" - | tag -> Meta.value_with_name meta tag in - Mustache.fold ~string ~section ~escaped ~unescaped ~partial ~comment ~concat + let e = List.hd e in + match e with + | "url" -> "/note/" ^ Meta.alias meta + | "date" | "date_created" | "date_edited" | "date_published" | "date_human" -> + "" + | tag -> Meta.value_with_name meta tag + +let escaped_note note e = match List.hd e with + | "body" -> Omd.to_html @@ Omd.of_string note.Logarion.Note.body + | _ -> escaped_meta note.Logarion.Note.meta e -let fold_meta tpl meta = fold_meta meta tpl - -let fold_header blog_url title = - let escaped e = - let e = List.hd e in - match e with - | "blog_url" -> blog_url - | "title" -> title - | _ -> prerr_endline ("unknown tag: " ^ e); "" in - Mustache.fold ~string ~section ~escaped ~unescaped ~partial ~comment ~concat +let escaped_header blog_url title e = match List.hd e with + | "blog_url" -> blog_url + | "title" -> title + | tag -> prerr_endline ("unknown tag: " ^ tag); "" let anchor_of_meta meta = let module Meta = Logarion.Meta in @@ -115,12 +105,16 @@ let fold_index ~from ~n metas = let note_page ?(header_template=None) ?(note_template=None) ~style url title note = let header_html = match header_template with - | Some (Header s) -> Html.header @@ Html.data @@ fold_header url title s + | Some (Header s) -> + let data = Mustache.fold ~string ~section ~escaped:(escaped_header url title) ~unescaped ~partial ~comment ~concat s in + Html.header @@ Html.data data | None -> Html.(header (heading1 title)) in let note_html = match note_template with - | Some (Note s) -> Html.data @@ fold_note note s + | Some (Note s) -> + let data = Mustache.fold ~string ~section ~escaped:(escaped_note note) ~unescaped ~partial ~comment ~concat s in + Html.data data | None -> let open Logarion.Note in let open Logarion.Meta in @@ -135,7 +129,9 @@ 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 header_html = match header_template with - | Some (Header s) -> Html.header @@ Html.data @@ fold_header url title s + | Some (Header s) -> + let data = Mustache.fold ~string ~section ~escaped:(escaped_header url title) ~unescaped ~partial ~comment ~concat s in + Html.header @@ Html.data data | None -> Html.(header (heading1 title)) in