74 lines
2.6 KiB
OCaml
74 lines
2.6 KiB
OCaml
let page _archive_title text =
|
|
let open Logarion.Text in
|
|
"# " ^ text.title
|
|
^ "\nAuthors: " ^ Logarion.Person.Set.to_string text.authors
|
|
^ "\nDate: " ^ Logarion.Date.(pretty_date @@ listing text.date)
|
|
^ let module T = Parsers.Plain_text.Make (Converter.Gemini) in
|
|
"\n" ^ T.of_string text.body ""
|
|
|
|
let date_index title meta_list =
|
|
List.fold_left
|
|
(fun a m ->
|
|
a ^ "=> " ^ Logarion.Text.alias m ^ ".gmi " ^
|
|
Logarion.(Date.(pretty_date (listing m.date)) ^ " " ^ m.title) ^ "\n")
|
|
("# " ^ title ^ "\n\n## Posts by date\n\n") meta_list
|
|
|
|
let to_dated_links ?(limit) meta_list =
|
|
let meta_list = match limit with
|
|
| None -> meta_list
|
|
| Some limit->
|
|
let rec reduced acc i = function
|
|
| [] -> acc
|
|
| h::t -> if i < limit then reduced (h::acc) (i+1) t else acc in
|
|
List.rev @@ reduced [] 0 meta_list
|
|
in
|
|
List.fold_left
|
|
(fun a m ->
|
|
a
|
|
^ "=> " ^ Logarion.Text.alias m ^ ".gmi "
|
|
^ Logarion.(Date.(pretty_date (listing m.Text.date))) ^ " "
|
|
^ m.Logarion.Text.title ^ "\n")
|
|
"" meta_list
|
|
|
|
let topic_link root topic =
|
|
"=> index." ^ root ^ ".gmi " ^ String.capitalize_ascii topic ^ "\n"
|
|
|
|
let text_item path meta =
|
|
let open Logarion in
|
|
"=> " ^ path ^ Text.alias meta ^ ".gmi "
|
|
^ Date.(pretty_date (listing meta.Text.date)) ^ " "
|
|
^ meta.Text.title ^ "\n"
|
|
|
|
let listing_index topic_map topic_roots path metas =
|
|
let rec item_group topics =
|
|
List.fold_left (fun acc topic -> acc ^ sub_groups topic ^ items topic) "" topics
|
|
and sub_groups topic = match Logarion.Topic_set.Map.find_opt topic topic_map with
|
|
| None -> ""
|
|
| Some (_, subtopics) -> item_group (Logarion.String_set.elements subtopics)
|
|
and items topic =
|
|
let items =
|
|
let open Logarion in
|
|
List.fold_left
|
|
(fun a e ->
|
|
if String_set.mem topic (String_set.map (Logarion.Topic_set.topic) (Text.set "Topics" e))
|
|
then text_item path e ^ a else a) "" metas in
|
|
match items with
|
|
| "" -> ""
|
|
| x -> "## " ^ String.capitalize_ascii topic ^ "\n\n" ^ x
|
|
in
|
|
item_group topic_roots
|
|
|
|
let fold_topic_roots topic_roots =
|
|
let list_item root t = topic_link root t in
|
|
List.fold_left (fun a x -> a ^ list_item x x) "" (List.rev topic_roots)
|
|
|
|
let topic_main_index title topic_roots metas =
|
|
"# " ^ title ^ "\n\n"
|
|
^ (if topic_roots <> [] then ("## Main topics\n\n" ^ fold_topic_roots topic_roots) else "")
|
|
^ "\n## Latest\n\n" ^ to_dated_links ~limit:10 metas
|
|
^ "\n=> index.date.gmi More by date\n"
|
|
|
|
let topic_sub_index title topic_map topic_root metas =
|
|
"# " ^ title ^ "\n\n"
|
|
^ listing_index topic_map [topic_root] "" metas
|