Accept comma separated converter names, separate Atom from Html and Gemini converters.

Note: atom must be called separately now because of the separation. Example

txt convert -t htm,atom xyz

git-svn-id: file:///srv/svn/repo/kosuzu/trunk@19 eb64cd80-c68d-6f47-b6a3-0ada418499da
This commit is contained in:
fox
2022-10-26 19:36:02 +00:00
parent 02937307f3
commit 39e9796a6e
5 changed files with 55 additions and 55 deletions

View File

@@ -1,3 +1,5 @@
let ext = ".atom"
let esc = Converter.Html.esc
let element tag content = "<" ^ tag ^ ">" ^ content ^ "</" ^ tag ^ ">"
@@ -44,14 +46,28 @@ let gmi_entry base_url text =
^ String_set.fold (fun elt a -> a ^ "<category term=\"" ^ elt ^ "\"/>") (Text.set "topics" text) ""
^ "</entry>\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
{|<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" xml:base="|} ^ base_url ^ {|"><title>|}
^ title ^ {|</title><link rel="alternate" type="|} ^ alternate_type ^ {|" href="|}
^ base_url ^ {|/" /><link rel="self" type="application/atom+xml" href="|}
^ self ^ {|" /><id>urn:uuid:|} ^ archive_id ^ "</id><updated>"
^ Logarion.Date.now () ^ "</updated>\n"
^ List.fold_left (fun acc t -> acc ^ entry base_url t) "" texts
^ "</feed>"
let base_url kv protocol = try
let locs = Logarion.Store.KV.find "Locations" kv in
let _i = Str.(search_forward (regexp (protocol ^ "://[^;]*")) locs 0) in
Str.(matched_string locs)
with Not_found -> Printf.eprintf "Missing location for %s" protocol; ""
let indices alternate_type c =
let file name = Logarion.File_store.file (Filename.concat c.Conversion.dir name) in
let title = try Logarion.Store.KV.find "Title" c.Conversion.kv with Not_found -> "" in
let entry, fname, protocol_regexp = match alternate_type with
| "text/gemini" -> gmi_entry, "gmi.atom", "gemini"
| "text/html" | _ -> htm_entry, "feed.atom", "https?"
in
let base_url = base_url c.kv protocol_regexp in
let self = Filename.concat base_url fname in
file fname @@
{|<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" xml:base="|} ^ base_url ^ {|"><title>|}
^ title ^ {|</title><link rel="alternate" type="|} ^ alternate_type ^ {|" href="|}
^ base_url ^ {|/" /><link rel="self" type="application/atom+xml" href="|}
^ self ^ {|" /><id>urn:uuid:|} ^ c.Conversion.id ^ "</id><updated>"
^ Logarion.Date.now () ^ "</updated>\n"
^ List.fold_left (fun acc t -> acc ^ entry base_url t) "" c.texts
^ "</feed>"
let converter format = Conversion.{ ext; page = None; indices = Some (indices format) }