Wrap all Tyxml.elt values in lists so that they can be concatenated in a single list. Thanks to Drup

This commit is contained in:
Stavros Polymenis 2017-11-30 01:31:14 +00:00
parent bb5316a3d4
commit 381d4a235f
2 changed files with 21 additions and 20 deletions

View File

@ -15,7 +15,7 @@ let default_style = "/static/main.css"
let page ?(style=default_style) blog_url head_title header main = let page ?(style=default_style) blog_url head_title header main =
html (head ~style head_title) (body [ header; main ]) html (head ~style head_title) (body [ header; main ])
let heading1 data = h1 [ pcdata data ] let heading1 = h1
let header = header let header = header

View File

@ -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 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 item ps = map_tpl_opt (fun v -> Item v) ps.Configuration.item ps
let string s = Html.data s let string s = [Html.data s]
let section ~inverted name contents = Html.unescaped_data ("section " ^ String.concat "." name) let section ~inverted name contents = [Html.unescaped_data ("section " ^ String.concat "." name)]
let unescaped elts = Html.unescaped_data "use escaped instead" let unescaped elts = [Html.unescaped_data "use escaped instead"]
let partial ?indent name _ _ = Html.data "partials not supported" let partial ?indent name _ _ = [Html.data "partials not supported"]
let comment _ = Html.data "" let comment _ = [Html.data ""]
let concat l = l let concat = List.concat
let escaped_meta (meta : Logarion.Meta.t) e = let escaped_meta (meta : Logarion.Meta.t) e =
let open Logarion in let open Logarion in
@ -64,13 +64,12 @@ let escaped_meta (meta : Logarion.Meta.t) e =
| tag -> Meta.value_with_name meta tag | tag -> Meta.value_with_name meta tag
let escaped_note note e = match List.hd e with let escaped_note note e = match List.hd e with
| "body" -> Html.unescaped_data @@ Omd.to_html @@ Omd.of_string note.Logarion.Note.body | "body" -> [Html.unescaped_data @@ Omd.to_html @@ Omd.of_string note.Logarion.Note.body]
| _ -> Html.unescaped_data @@ escaped_meta note.Logarion.Note.meta e | _ -> [Html.unescaped_data @@ escaped_meta note.Logarion.Note.meta e]
let escaped_header blog_url title e = match List.hd e with let escaped_header archive e = match List.hd e with
(* | "blog_url" -> *) | "title" -> [Html.heading1 [Html.anchor ("index.html") [Html.data archive.Logarion.Archive.Configuration.title]]]
| "title" -> Html.heading1 title | tag -> prerr_endline ("unknown tag: " ^ tag); [Html.unescaped_data ""]
| tag -> prerr_endline ("unknown tag: " ^ tag); Html.unescaped_data ""
let anchor_of_meta meta = let anchor_of_meta meta =
let module Meta = Logarion.Meta in let module Meta = Logarion.Meta in
@ -84,7 +83,7 @@ let listing metas =
let open Html in let open Html in
list_unordered @@ List.map (fun m -> list_item @@ anchor_of_meta @@ m) metas 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 *) (* match List.hd e with *)
(* | "navigation" -> *) (* | "navigation" -> *)
(* "" *) (* "" *)
@ -100,16 +99,17 @@ let escaped_index ~from ~n metas e = Html.data "temp"
(* Logarion.Meta.StringSet.fold (fun e a -> a ^ "<li><a href=\"/topic/" ^ e ^ "\">" ^ e ^ "</a></li>") topics "" *) (* Logarion.Meta.StringSet.fold (fun e a -> a ^ "<li><a href=\"/topic/" ^ e ^ "\">" ^ e ^ "</a></li>") topics "" *)
(* | e -> prerr_endline ("unknown tag: " ^ e); "" *) (* | 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) -> | Some (Header s) ->
Mustache.fold ~string ~section ~escaped:(escaped_header url title) ~unescaped ~partial ~comment ~concat:(fun l -> Html.div l) s Mustache.fold ~string ~section ~escaped:(escaped_header archive) ~unescaped ~partial ~comment ~concat s
|> (fun x -> Html.header [x]) |> (fun x -> Html.header x)
| None -> Html.(header [heading1 title]) | None -> Html.(header [heading1 [title]])
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 note_html = match note_template with let note_html = match note_template with
| Some (Note s) -> | 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 -> | None ->
let open Logarion.Note in let open Logarion.Note in
let open Logarion.Meta 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_page ?(header_template=None) ?(listing_template=None) ~style ~from ~n url title metas =
let listing_html = match listing_template with let listing_html = match listing_template with
| Some (Note s) -> | 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] | None -> Html.article [listing metas]
in in
Html.to_string @@ Html.page ~style url title (header_html header_template url title) listing_html Html.to_string @@ Html.page ~style url title (header_html header_template url title) listing_html