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:
@@ -9,20 +9,21 @@ let convert cs r (text, files) = match Text.str "Content-Type" text with
|
||||
let dest = Filename.concat r.Conversion.dir (Text.short_id text) in
|
||||
List.fold_left
|
||||
(fun a f ->
|
||||
let dest = dest ^ f.Conversion.ext in
|
||||
if is_older source dest then (File_store.file dest (f.Conversion.page r text); true) else false
|
||||
|| a)
|
||||
match f.Conversion.page with None -> false || a
|
||||
| Some page ->
|
||||
let dest = dest ^ f.Conversion.ext in
|
||||
(if is_older source dest then (File_store.file dest (page r text); true) else false)
|
||||
|| a)
|
||||
false cs
|
||||
| x -> Printf.eprintf "Can't convert Content-Type: %s file: %s" x text.Text.title; false
|
||||
|
||||
let converters types kv =
|
||||
let n = String.split_on_char ',' types in
|
||||
let t = [] in
|
||||
let t = if ("htm" = types || "all" = types) then
|
||||
(let htm = Html.init kv in
|
||||
Conversion.{ ext = Html.ext; page = Html.page htm; indices = Html.indices htm })::t
|
||||
else t in
|
||||
let t = if ("gmi" = types || "all" = types) then
|
||||
Conversion.{ ext = Gemini.ext; page = Gemini.page; indices = Gemini.indices}::t else t in
|
||||
let t = if List.(mem "all" n || mem "htm" n) then (Html.converter kv)::t else t in
|
||||
let t = if List.(mem "all" n || mem "atom" n) then (Atom.converter "text/html")::t else t in
|
||||
let t = if List.(mem "all" n || mem "gmi" n) then (Gemini.converter)::t else t in
|
||||
let t = if List.(mem "all" n || mem "gmi-atom" n) then (Atom.converter "text/gemini")::t else t in
|
||||
t
|
||||
|
||||
let directory converters noindex dir id kv =
|
||||
@@ -35,7 +36,7 @@ let directory converters noindex dir id kv =
|
||||
let topic_roots = try List.rev @@ String_set.list_of_csv (Store.KV.find "Topics" kv)
|
||||
with Not_found -> Topic_set.roots topics in
|
||||
let repo = Conversion.{ repo with topic_roots; topics; texts } in
|
||||
if not noindex then List.iter (fun c -> c.Conversion.indices repo) converters;
|
||||
if not noindex then List.iter (fun c -> match c.Conversion.indices with None -> () | Some f -> f repo) converters;
|
||||
Printf.printf "Converted: %d Indexed: %d\n" count (List.length texts)
|
||||
|
||||
let at_path types noindex path =
|
||||
@@ -47,8 +48,7 @@ let at_path types noindex path =
|
||||
| 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 = 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
|
||||
|
||||
Reference in New Issue
Block a user