diff --git a/cli/atom.ml b/cli/atom.ml
index 3ad961c..90e9275 100644
--- a/cli/atom.ml
+++ b/cli/atom.ml
@@ -9,29 +9,49 @@ let opt_element tag_name content =
module P = Parsers.Plain_text.Make (Converter.Html)
-let entry base_url text =
+let id txt = "urn:uuid:" ^ Logarion.(Id.to_string txt.Text.uuid) ^ ""
+let title text = "
" ^ esc text.Logarion.Text.title ^ ""
+
+let authors text =
+ let u acc addr = acc ^ element "uri" (Uri.to_string addr) in
+ let open Logarion in
+ let fn txt a =
+ a ^ "" ^ (opt_element "name" @@ esc txt.Person.name)
+ ^ (List.fold_left u "" txt.Person.addresses)
+ ^ "" in
+ Person.Set.fold fn text.Text.authors ""
+
+let updated txt = let open Logarion in
+ ""^ Date.(txt.Text.date |> listing |> rfc_string) ^""
+
+let htm_entry base_url text =
let open Logarion in
let u = Text.alias text in
- let authors elt a =
- a ^ ""
- ^ (opt_element "name" @@ esc elt.Person.name)
- ^ (List.fold_left (fun acc addr -> acc ^ element "uri" (Uri.to_string addr)) "" elt.Person.addresses)
- ^ ""
- in
- "" ^ esc text.title ^ "urn:uuid:" ^ Id.to_string text.uuid ^ ""
- ^ Date.(text.date |> listing |> rfc_string) ^ ""
- ^ Person.Set.fold authors text.authors ""
+ ""
+ ^ title text ^ id text ^ updated text ^ authors text
^ (opt_element "summary" @@ esc @@ Text.str "abstract" text)
^ String_set.fold (fun elt a -> a ^ "") (Text.set "topics" text) ""
^ ""
^ P.of_string text.body ""
- ^ "
"
+ ^ "\n"
-let feed title archive_id base_url texts =
+let gmi_entry base_url text =
+ let open Logarion in
+ let u = Text.alias text in
+ ""
+ ^ title text ^ id text ^ updated text ^ authors text
+ ^ (opt_element "summary" @@ esc @@ Text.str "abstract" text)
+ ^ String_set.fold (fun elt a -> a ^ "") (Text.set "topics" text) ""
+ ^ "\n"
+
+let feed title archive_id base_url alternate_type texts =
+ let entry, self = match alternate_type with
+ | "text/gemini" -> gmi_entry, base_url^"/gmi.atom"
+ | "text/html" | _ -> htm_entry, base_url^"/feed.atom" in
{||}
- ^ title ^ {|urn:uuid:|} ^ Logarion.Id.to_string archive_id ^ ""
- ^ Ptime.to_rfc3339 (Ptime_clock.now ()) ^ ""
- ^ List.fold_left (fun acc t -> acc ^ entry base_url t) "" texts ^ ""
+ ^ title ^ {|urn:uuid:|} ^ Logarion.Id.to_string archive_id ^ ""
+ ^ Ptime.to_rfc3339 (Ptime_clock.now ()) ^ "\n"
+ ^ List.fold_left (fun acc t -> acc ^ entry base_url t) "" texts
+ ^ ""
diff --git a/cli/convert.ml b/cli/convert.ml
index 8a108fe..6147ef8 100644
--- a/cli/convert.ml
+++ b/cli/convert.ml
@@ -30,19 +30,21 @@ let index_writer types dir archive topic_roots topic_map indexed_texts =
List.iter
(fun topic -> file ("/index." ^ topic ^ ".htm")
(Html.topic_sub_index name topic_map topic indexed_texts))
- topic_roots
+ topic_roots;
+ let base_url = try Store.KV.find "HTTP-URL" archive.File_store.kv
+ with Not_found -> prerr_endline "Missing `HTTP-URL:` in config"; "" in
+ file "/feed.atom" (Atom.feed archive.A.name archive.A.id base_url "text/html" indexed_texts)
);
- let base_url = try Store.KV.find "HTTP-URL" archive.File_store.kv
- with Not_found -> prerr_endline "Missing `HTTP-URL:` in config"; ""
- in
- file "/feed.atom" (Atom.feed archive.A.name archive.A.id base_url indexed_texts);
if "gmi" = types || "all" = types then (
file "/index.gmi" (Gemini.topic_main_index name topic_roots indexed_texts);
file "/index.date.gmi" (Gemini.date_index name indexed_texts);
List.iter
(fun topic -> file ("/index." ^ topic ^ ".gmi")
(Gemini.topic_sub_index name topic_map topic indexed_texts))
- topic_roots
+ topic_roots;
+ let base_url = try Store.KV.find "GEMINI-URL" archive.File_store.kv
+ with Not_found -> prerr_endline "Missing `GEMINI-URL:` in config"; "" in
+ file "/gmi.atom" (Atom.feed archive.A.name archive.A.id base_url "text/gemini" indexed_texts)
)
let txt_writer types dir name ((text, _store_item) as r) =
@@ -77,11 +79,7 @@ let convert_dir types cmd_dir =
open Cmdliner
let term =
- let directory = Arg.(value & pos 0 string ""
- & info [] ~docv:"target directory" ~doc:"Directory to convert into") in
+ let directory = Arg.(value & pos 0 string "" & info [] ~docv:"target directory" ~doc:"Directory to convert into") in
let types = Arg.(value & opt string "all" & info ["t"; "type"] ~docv:"TYPES" ~doc:"Convert to type") in
-
Term.(const convert_dir $ types $ directory),
- Term.info
- "convert" ~doc:"convert archive"
- ~man:[ `S "DESCRIPTION"; `P "Convert Logarion archive" ]
+ Term.info "convert" ~doc:"convert archive" ~man:[ `S "DESCRIPTION"; `P "Convert Logarion archive" ]