Changeset 19 in code for trunk/cli/convert.ml


Ignore:
Timestamp:
Oct 26, 2022, 7:36:02 PM (2 years ago)
Author:
fox
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/cli/convert.ml

    r15 r19  
    1010                List.fold_left
    1111                        (fun a f ->
    12                                 let dest = dest ^ f.Conversion.ext in
    13                                 if is_older source dest then (File_store.file dest (f.Conversion.page r text); true) else false
    14                                 || a)
     12                                match f.Conversion.page with None -> false || a
     13                                | Some page ->
     14                                        let dest = dest ^ f.Conversion.ext in
     15                                        (if is_older source dest then (File_store.file dest (page r text); true) else false)
     16                                        || a)
    1517                        false cs
    1618        | x -> Printf.eprintf "Can't convert Content-Type: %s file: %s" x text.Text.title; false
    1719
    1820let converters types kv =
     21        let n = String.split_on_char ',' types in
    1922        let t = [] in
    20         let t = if ("htm" = types || "all" = types) then
    21                 (let htm = Html.init kv in
    22                  Conversion.{ ext = Html.ext; page = Html.page htm; indices = Html.indices htm })::t
    23                 else t in
    24         let t = if ("gmi" = types || "all" = types) then
    25                 Conversion.{ ext = Gemini.ext; page = Gemini.page; indices = Gemini.indices}::t else t in
     23        let t = if List.(mem "all" n || mem "htm" n) then (Html.converter kv)::t else t in
     24        let t = if List.(mem "all" n || mem "atom" n) then (Atom.converter "text/html")::t else t in
     25        let t = if List.(mem "all" n || mem "gmi" n) then (Gemini.converter)::t else t in
     26        let t = if List.(mem "all" n || mem "gmi-atom" n) then (Atom.converter "text/gemini")::t else t in
    2627        t
    2728
     
    3637                with Not_found -> Topic_set.roots topics in
    3738        let repo = Conversion.{ repo with topic_roots; topics; texts } in
    38         if not noindex then List.iter (fun c -> c.Conversion.indices repo) converters;
     39        if not noindex then List.iter (fun c -> match c.Conversion.indices with None -> () | Some f -> f repo) converters;
    3940        Printf.printf "Converted: %d Indexed: %d\n" count (List.length texts)
    4041
     
    4849                        let kv = let f = Filename.concat dir ".convert.conf" in (* TODO: better place to store convert conf? *)
    4950                                if Sys.file_exists f then File_store.of_kv_file f else Store.KV.empty in
    50                         let kv = if Store.KV.mem "Title" kv then kv
    51                                 else Store.KV.add "Title" info.Header_pack.title kv in
     51                        let kv = if Store.KV.mem "Title" kv then kv else Store.KV.add "Title" info.Header_pack.title kv in
    5252                        let kv = Store.KV.add "Locations" (String.concat ";\n" info.Header_pack.locations) kv in
    5353                        let kv = Store.KV.add "Peers" (String.concat ";\n" Header_pack.(to_str_list peers)) kv in
Note: See TracChangeset for help on using the changeset viewer.