From a21be6631a1090f1c906748e2578488676dd9fb9 Mon Sep 17 00:00:00 2001 From: orbifx Date: Sun, 31 Jul 2022 13:56:39 +0100 Subject: [PATCH] List peers (from index.pck) in exported htm and gmi index --- cli/convert.ml | 3 ++- cli/gemini.ml | 12 ++++++++---- cli/html.ml | 14 ++++++++++---- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/cli/convert.ml b/cli/convert.ml index 55b1f72..a2b0276 100644 --- a/cli/convert.ml +++ b/cli/convert.ml @@ -44,12 +44,13 @@ let at_path types noindex path = let fname = Filename.concat dir "index.pck" in (match Header_pack.of_string @@ File_store.to_string fname with | Error s -> prerr_endline s - | Ok { info; _ } -> + | Ok { info; peers; _ } -> let kv = let f = Filename.concat dir ".convert.conf" in (* TODO: better place to store convert conf? *) if Sys.file_exists f then File_store.of_kv_file f else Store.KV.empty in let kv = if Store.KV.mem "Title" kv then kv else Store.KV.add "Title" info.Header_pack.title kv in let kv = Store.KV.add "Locations" (String.concat ";\n" info.Header_pack.locations) kv in + let kv = Store.KV.add "Peers" (String.concat ";\n" Header_pack.(to_str_list peers)) kv in let cs = converters types kv in directory cs noindex dir info.Header_pack.id kv) | path when Sys.file_exists path -> diff --git a/cli/gemini.ml b/cli/gemini.ml index f43fcb0..598aa1a 100644 --- a/cli/gemini.ml +++ b/cli/gemini.ml @@ -71,11 +71,15 @@ 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" +let topic_main_index r 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" + ^ "\n=> index.date.gmi More by date\n\n" + ^ let peers = Logarion.Store.KV.find "Peers" r.Conversion.kv in + if peers = "" then "" else + List.fold_left (fun a s -> Printf.sprintf "%s=> %s\n" a s) "## Peers\n\n" + (Str.split (Str.regexp ";\n") peers) let topic_sub_index title topic_map topic_root metas = "# " ^ title ^ "\n\n" @@ -88,7 +92,7 @@ let indices r = let title = try Store.KV.find "Title" r.Conversion.kv with Not_found -> "" in if index_name <> "" then - file index_name (topic_main_index title r.topic_roots r.texts); + file index_name (topic_main_index r title r.topic_roots r.texts); file "index.date.gmi" (date_index title r.texts); diff --git a/cli/html.ml b/cli/html.ml index 46d31be..0b2a12c 100644 --- a/cli/html.ml +++ b/cli/html.ml @@ -36,7 +36,7 @@ let wrap c htm text_title body = let topic_link root topic = let replaced_space = String.map (function ' '->'+' | x->x) in - "" + "" ^ String.capitalize_ascii topic ^ "" module HtmlConverter = struct @@ -147,7 +147,12 @@ let topic_main_index conv htm topic_roots metas = wrap conv htm "Topics" (fold_topic_roots topic_roots ^ "|} ) + ^ {|More by date|} + ^ let peers = Logarion.Store.KV.find "Peers" conv.kv in + (if peers = "" then "" else + List.fold_left (fun a s -> Printf.sprintf {|%s
  • %s|} a s s) "

    Peers

    ")) let topic_sub_index conv htm topic_map topic_root metas = wrap conv htm topic_root @@ -171,7 +176,8 @@ let indices htm c = c.topic_roots; let base_url = try - let _i = Str.(search_forward (regexp "https?://[^;]*") (Store.KV.find "Locations" c.kv) 0) in - Str.(matched_string (Store.KV.find "Locations" c.kv)) + let locs = Store.KV.find "Locations" c.kv in + let _i = Str.(search_forward (regexp "https?://[^;]*") locs 0) in + Str.(matched_string locs) with Not_found -> prerr_endline "Missing location for HTTP(S)"; "" in file "feed.atom" (Atom.feed title c.id base_url "text/html" c.texts)