1 | let page _archive_title text =
|
---|
2 | let open Logarion.Text in
|
---|
3 | "# " ^ text.title
|
---|
4 | ^ "\nAuthors: " ^ Logarion.Person.Set.to_string text.authors
|
---|
5 | ^ "\nDate: " ^ Logarion.Date.(pretty_date @@ listing text.date)
|
---|
6 | ^ let module T = Parsers.Plain_text.Make (Converter.Gemini) in
|
---|
7 | "\n" ^ T.of_string text.body ""
|
---|
8 |
|
---|
9 | let date_index title meta_list =
|
---|
10 | List.fold_left
|
---|
11 | (fun a m ->
|
---|
12 | a ^ "=> " ^ Logarion.Text.short_id m ^ ".gmi " ^
|
---|
13 | Logarion.(Date.(pretty_date (listing m.date)) ^ " " ^ m.title) ^ "\n")
|
---|
14 | ("# " ^ title ^ "\n\n## Posts by date\n\n") meta_list
|
---|
15 |
|
---|
16 | let to_dated_links ?(limit) meta_list =
|
---|
17 | let meta_list = match limit with
|
---|
18 | | None -> meta_list
|
---|
19 | | Some limit->
|
---|
20 | let rec reduced acc i = function
|
---|
21 | | [] -> acc
|
---|
22 | | h::t -> if i < limit then reduced (h::acc) (i+1) t else acc in
|
---|
23 | List.rev @@ reduced [] 0 meta_list
|
---|
24 | in
|
---|
25 | List.fold_left
|
---|
26 | (fun a m ->
|
---|
27 | a
|
---|
28 | ^ "=> " ^ Logarion.Text.short_id m ^ ".gmi "
|
---|
29 | ^ Logarion.(Date.(pretty_date (listing m.Text.date))) ^ " "
|
---|
30 | ^ m.Logarion.Text.title ^ "\n")
|
---|
31 | "" meta_list
|
---|
32 |
|
---|
33 | let topic_link root topic =
|
---|
34 | "=> index." ^ root ^ ".gmi " ^ String.capitalize_ascii topic ^ "\n"
|
---|
35 |
|
---|
36 | let text_item path meta =
|
---|
37 | let open Logarion in
|
---|
38 | "=> " ^ path ^ Text.short_id meta ^ ".gmi "
|
---|
39 | ^ Date.(pretty_date (listing meta.Text.date)) ^ " "
|
---|
40 | ^ meta.Text.title ^ "\n"
|
---|
41 |
|
---|
42 | let listing_index topic_map topic_roots path metas =
|
---|
43 | let rec item_group topics =
|
---|
44 | List.fold_left (fun acc topic -> acc ^ sub_groups topic ^ items topic) "" topics
|
---|
45 | and sub_groups topic = match Logarion.Topic_set.Map.find_opt topic topic_map with
|
---|
46 | | None -> ""
|
---|
47 | | Some (_, subtopics) -> item_group (Logarion.String_set.elements subtopics)
|
---|
48 | and items topic =
|
---|
49 | let items =
|
---|
50 | let open Logarion in
|
---|
51 | List.fold_left
|
---|
52 | (fun a e ->
|
---|
53 | if String_set.mem topic (String_set.map (Logarion.Topic_set.topic) (Text.set "Topics" e))
|
---|
54 | then text_item path e ^ a else a) "" metas in
|
---|
55 | match items with
|
---|
56 | | "" -> ""
|
---|
57 | | x -> "## " ^ String.capitalize_ascii topic ^ "\n\n" ^ x
|
---|
58 | in
|
---|
59 | item_group topic_roots
|
---|
60 |
|
---|
61 | let fold_topic_roots topic_roots =
|
---|
62 | let list_item root t = topic_link root t in
|
---|
63 | List.fold_left (fun a x -> a ^ list_item x x) "" (List.rev topic_roots)
|
---|
64 |
|
---|
65 | let topic_main_index title topic_roots metas =
|
---|
66 | "# " ^ title ^ "\n\n"
|
---|
67 | ^ (if topic_roots <> [] then ("## Main topics\n\n" ^ fold_topic_roots topic_roots) else "")
|
---|
68 | ^ "\n## Latest\n\n" ^ to_dated_links ~limit:10 metas
|
---|
69 | ^ "\n=> index.date.gmi More by date\n"
|
---|
70 |
|
---|
71 | let topic_sub_index title topic_map topic_root metas =
|
---|
72 | "# " ^ title ^ "\n\n"
|
---|
73 | ^ listing_index topic_map [topic_root] "" metas
|
---|