[26] | 1 | let targets pubdir = List.fold_left
|
---|
| 2 | (fun a x ->
|
---|
| 3 | let path = Filename.concat pubdir (snd x) in
|
---|
| 4 | try if Sys.is_directory path then (fst x, path)::a else a with Sys_error _ -> a)
|
---|
| 5 | []
|
---|
| 6 | ["htm,atom", "public_html/"; "gmi,gmi-atom", "public_gemini/"; "", "public_gopher/"]
|
---|
[6] | 7 |
|
---|
[36] | 8 | let wizard () =
|
---|
| 9 | print_endline "No txt.conf found. It's required for the repository name & id. Create one? (y/N)";
|
---|
| 10 | match input_line stdin with
|
---|
| 11 | |"y"->
|
---|
| 12 | let title =
|
---|
| 13 | print_endline "Title for repository: ";
|
---|
| 14 | input_line stdin in
|
---|
| 15 | let authors =
|
---|
| 16 | print_endline "Authors (format: name <name@email> <http://website>): ";
|
---|
| 17 | input_line stdin in
|
---|
| 18 | Logarion.File_store.file "txt.conf"
|
---|
| 19 | (Printf.sprintf "Id: %s\nTitle: %s\nAuthors: %s\n" (Logarion.Id.generate ()) title authors);
|
---|
| 20 | Logarion.File_store.of_kv_file ()
|
---|
| 21 | | _ -> print_endline "Create a txt.conf and run publish again"; exit 1
|
---|
| 22 |
|
---|
[6] | 23 | open Logarion
|
---|
[26] | 24 | let publish pubdir ids =
|
---|
[36] | 25 | let kv =
|
---|
| 26 | match Logarion.File_store.of_kv_file ()
|
---|
| 27 | with x when x = Logarion.Store.KV.empty -> wizard () | x -> x in
|
---|
[6] | 28 | let predicate t = List.mem t.Text.id ids in
|
---|
[27] | 29 | let pubdir_source, pubdir = match pubdir with Some d -> "--pubdir ", d | None ->
|
---|
| 30 | try "txt.conf:Pubdir", Logarion.Store.KV.find "Pubdir" kv with Not_found ->
|
---|
| 31 | try "$txtpubdir", Sys.getenv "txtpubdir" with Not_found -> "$txtpubdir", ""
|
---|
[26] | 32 | in
|
---|
| 33 | let targets = targets pubdir in
|
---|
| 34 | if targets = [] then
|
---|
[36] | 35 | Printf.eprintf "No target directories in %s='%s' (for example %s)\n"
|
---|
| 36 | pubdir_source pubdir (Filename.concat pubdir "public_html")
|
---|
[26] | 37 | else begin
|
---|
| 38 | let pub_dirs = List.map (fun x -> snd x) targets in
|
---|
| 39 | File_store.iter ~predicate (fun (_t, p) ->
|
---|
| 40 | try File.file ((List.hd p)::pub_dirs)
|
---|
| 41 | with Unix.Unix_error (Unix.EEXIST, _, _) -> ());
|
---|
| 42 | List.iter (fun t -> Printf.eprintf "%s %s\n" (fst t) (snd t);
|
---|
| 43 | Index.((load (snd t)) false None None None None);
|
---|
| 44 | Convert.at_path (fst t) false (snd t))
|
---|
| 45 | targets
|
---|
| 46 | end
|
---|
[6] | 47 |
|
---|
| 48 | open Cmdliner
|
---|
| 49 | let term =
|
---|
| 50 | let ids = Arg.(value & pos_all string [] & info [] ~docv:"text ids") in
|
---|
[26] | 51 | let pubdir = Arg.(value & opt (some string) None & info ["p"; "pubdir"] ~docv:"directory path"
|
---|
| 52 | ~doc:"set top directory for publishing files") in
|
---|
| 53 | let doc = "convert texts into standard public dirs pubdir/public_{html,gemini,gopher} if they exist" in
|
---|
| 54 | Term.(const publish $ pubdir $ ids), Term.info "publish" ~doc ~man:[ `S "DESCRIPTION"; `P doc ]
|
---|