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 comment c = c
|
||||||
let concat l = String.concat "" l
|
let concat l = String.concat "" l
|
||||||
|
|
||||||
let fold_note ymd =
|
let escaped_meta (meta : Logarion.Meta.t) e =
|
||||||
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 open Logarion in
|
let open Logarion in
|
||||||
let escaped e =
|
|
||||||
let e = List.hd e in
|
let e = List.hd e in
|
||||||
match e with
|
match e with
|
||||||
| "url" -> "/note/" ^ Meta.alias meta
|
| "url" -> "/note/" ^ Meta.alias meta
|
||||||
| "date" | "date_created" | "date_edited" | "date_published" | "date_human" ->
|
| "date" | "date_created" | "date_edited" | "date_published" | "date_human" ->
|
||||||
"<time>" ^ Meta.value_with_name meta e ^ "</time>"
|
"<time>" ^ Meta.value_with_name meta e ^ "</time>"
|
||||||
| tag -> Meta.value_with_name meta tag in
|
| tag -> Meta.value_with_name meta tag
|
||||||
Mustache.fold ~string ~section ~escaped ~unescaped ~partial ~comment ~concat
|
|
||||||
|
|
||||||
let fold_meta tpl meta = fold_meta meta tpl
|
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_header blog_url title =
|
let escaped_header blog_url title e = match List.hd e with
|
||||||
let escaped e =
|
|
||||||
let e = List.hd e in
|
|
||||||
match e with
|
|
||||||
| "blog_url" -> blog_url
|
| "blog_url" -> blog_url
|
||||||
| "title" -> title
|
| "title" -> title
|
||||||
| _ -> prerr_endline ("unknown tag: " ^ e); "" in
|
| tag -> prerr_endline ("unknown tag: " ^ tag); ""
|
||||||
Mustache.fold ~string ~section ~escaped ~unescaped ~partial ~comment ~concat
|
|
||||||
|
|
||||||
let anchor_of_meta meta =
|
let anchor_of_meta meta =
|
||||||
let module Meta = Logarion.Meta in
|
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 note_page ?(header_template=None) ?(note_template=None) ~style url title note =
|
||||||
|
|
||||||
let header_html = match header_template with
|
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))
|
| None -> Html.(header (heading1 title))
|
||||||
in
|
in
|
||||||
|
|
||||||
let note_html = match note_template with
|
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 ->
|
| None ->
|
||||||
let open Logarion.Note in
|
let open Logarion.Note in
|
||||||
let open Logarion.Meta 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 listing_page ?(header_template=None) ?(listing_template=None) ~style ~from ~n url title metas =
|
||||||
|
|
||||||
let header_html = match header_template with
|
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))
|
| None -> Html.(header (heading1 title))
|
||||||
in
|
in
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user