let esc = Converter.Html.esc
let element tag content = "<" ^ tag ^ ">" ^ content ^ "" ^ tag ^ ">"
let opt_element tag_name content =
if content <> ""
then element tag_name content
else ""
module P = Parsers.Plain_text.Make (Converter.Html)
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.short_id 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) ""
^ "
"
^ P.of_string text.body ""
^ "
\n"
let gmi_entry base_url text =
let open Logarion in
let u = Text.short_id 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 ()) ^ "\n"
^ List.fold_left (fun acc t -> acc ^ entry base_url t) "" texts
^ ""