1 | type t = Mustache.t
|
---|
2 |
|
---|
3 | let of_string = Mustache.of_string
|
---|
4 | let of_file f = File.load f |> of_string
|
---|
5 |
|
---|
6 | let string s = [Html.data s]
|
---|
7 | let section ~inverted:_ _name _contents = prerr_endline "Mustache sections unsupported"; []
|
---|
8 | let unescaped _elts = prerr_endline "Mustache unescaped not supported; used escaped instead"; []
|
---|
9 | let partial ?indent:_ _name _ _ = prerr_endline "Mustache sections unsupported"; []
|
---|
10 | let comment _ = [Html.data ""]
|
---|
11 | let concat = List.concat
|
---|
12 |
|
---|
13 | let escaped_index ~from:_ ~n:_ _metas _e = [Html.data "temp"]
|
---|
14 | (* match List.hd e with *)
|
---|
15 | (* | "topics" -> *)
|
---|
16 | (* let topics = *)
|
---|
17 | (* ListLabels.fold_left *)
|
---|
18 | (* ~init:(Logarion.Meta.StringSet.empty) *)
|
---|
19 | (* ~f:(fun a e -> Logarion.Meta.unique_topics a e ) metas *)
|
---|
20 | (* in *)
|
---|
21 | (* Logarion.Meta.StringSet.fold (fun e a -> a ^ "<li><a href=\"/topic/" ^ e ^ "\">" ^ e ^ "</a></li>") topics "" *)
|
---|
22 |
|
---|
23 | let header_custom template _linker archive =
|
---|
24 | Mustache.fold ~string ~section ~escaped:(Html.Renderer.archive archive) ~unescaped ~partial ~comment ~concat template
|
---|
25 | |> Html.header
|
---|
26 |
|
---|
27 | let header_default linker archive =
|
---|
28 | Html.(header [title [anchor (linker "/") [data archive.Logarion.Archive.Configuration.title]]])
|
---|
29 |
|
---|
30 | let meta meta =
|
---|
31 | let open Logarion.Meta in
|
---|
32 | let abstract = meta.abstract in
|
---|
33 | let authors = List.map (fun elt -> elt.Author.name) @@ AuthorSet.elements meta.authors in
|
---|
34 | let date = Date.(pretty_date @@ listing meta.date) in
|
---|
35 | let series = stringset_csv meta.series in
|
---|
36 | let topics = stringset_csv meta.topics in
|
---|
37 | let keywords = stringset_csv meta.keywords in
|
---|
38 | let uuid = Id.to_string meta.uuid in
|
---|
39 | Html.meta ~abstract ~authors ~date ~series ~topics ~keywords ~uuid
|
---|
40 |
|
---|
41 | let body_custom template note =
|
---|
42 | Mustache.fold ~string ~section ~escaped:(Html.Renderer.note note) ~unescaped ~partial ~comment ~concat template
|
---|
43 | |> Html.note
|
---|
44 |
|
---|
45 | let body_default note =
|
---|
46 | Html.note
|
---|
47 | [ Html.title [Html.unescaped_data note.Logarion.Note.meta.Logarion.Meta.title]; (* Don't add title if body contains one *)
|
---|
48 | meta note.meta;
|
---|
49 | Html.unescaped_data @@ Omd.to_html @@ Omd.of_string note.Logarion.Note.body ]
|
---|
50 |
|
---|
51 | let page ~style linker title header body =
|
---|
52 | Html.to_string @@ Html.page ~style linker title header body
|
---|
53 |
|
---|
54 | let of_config config k = match config with
|
---|
55 | | Error msg -> prerr_endline ("Couldn't load [templates] section;" ^ msg); None
|
---|
56 | | Ok c ->
|
---|
57 | let open Confix.ConfixToml in
|
---|
58 | path c ("templates" / k)
|
---|
59 |
|
---|
60 | let converter default custom = function
|
---|
61 | | Some p ->
|
---|
62 | if Confix.Config.Path.path_exists p then custom @@ of_file p
|
---|
63 | else (prerr_endline @@ "Couldn't find: " ^ Fpath.to_string p; default)
|
---|
64 | | None -> default
|
---|
65 |
|
---|
66 | let header_converter config = converter header_default header_custom @@ of_config config "header"
|
---|
67 | let body_converter config = converter body_default body_custom @@ of_config config "body"
|
---|
68 |
|
---|
69 | let default_style = Html.default_style
|
---|
70 |
|
---|
71 | let page_of_index ~style linker header archive metas =
|
---|
72 | page ~style linker ("Index | " ^ archive.Logarion.Archive.Configuration.title) (header linker archive) (Html.main (Html.listing_index "" metas))
|
---|
73 |
|
---|
74 | let page_of_log ~style linker header archive metas =
|
---|
75 | page ~style linker ("Log | " ^ archive.Logarion.Archive.Configuration.title) (header linker archive) (Html.main [Html.listing_texts "" metas])
|
---|
76 |
|
---|
77 | let page_of_note ~style linker header body archive note =
|
---|
78 | page ~style linker note.Logarion.Note.meta.Logarion.Meta.title (header linker archive) (body note)
|
---|
79 |
|
---|
80 | let page_of_msg ~style linker header archive title msg =
|
---|
81 | page ~style linker title (header linker archive) (Html.div [Html.data msg])
|
---|