Reorganise escape functions
This commit is contained in:
parent
1283c1de78
commit
637556360e
@ -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" ->
|
||||
"<time>" ^ Meta.value_with_name meta e ^ "</time>"
|
||||
| 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" ->
|
||||
"<time>" ^ Meta.value_with_name meta e ^ "</time>"
|
||||
| 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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user