List peers (from index.pck) in exported htm and gmi index

orbifx 2 months ago
parent 20d11b1bfe
commit a21be6631a
  1. 3
      cli/convert.ml
  2. 12
      cli/gemini.ml
  3. 14
      cli/html.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 ->

@ -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);

@ -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
"<a href='index." ^ replaced_space root ^ ".htm#" ^ replaced_space topic ^ "'>"
"<a href='index." ^ root ^ ".htm#" ^ replaced_space topic ^ "'>"
^ String.capitalize_ascii topic ^ "</a>"
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
^ "<nav><h1>Latest</h1><ul>" ^ to_dated_links ~limit:8 metas
^ {|</ul><a href="index.date.htm">More by date</a></nav>|} )
^ {|</ul><a href="index.date.htm">More by date</a>|}
^ let peers = Logarion.Store.KV.find "Peers" conv.kv in
(if peers = "" then "" else
List.fold_left (fun a s -> Printf.sprintf {|%s<li><a href="%s">%s</a>|} a s s) "<h1>Peers</h1><ul>"
(Str.split (Str.regexp ";\n") (Logarion.Store.KV.find "Peers" conv.kv))
^ "</ul>"))
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)

Loading…
Cancel
Save