source: code/trunk/cmd/txt/publish.ml@ 78

Last change on this file since 78 was 78, checked in by Izuru Yakumo, 7 weeks ago

Bring back the publish subcommand (adapted)

File size: 3.0 KB
Line 
1let 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/"]
7
8let 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 Kosuzu.File_store.file "txt.conf"
19 (Printf.sprintf "Id: %s\nTitle: %s\nAuthors: %s\n" (Kosuzu.Id.generate ()) title authors);
20 Kosuzu.File_store.of_kv_file ()
21 | _ -> print_endline "Create a txt.conf and run publish again"; exit 1
22
23open Kosuzu
24let publish pubdir ids =
25 let kv =
26 match Kosuzu.File_store.of_kv_file ()
27 with x when x = Kosuzu.Store.KV.empty -> wizard () | x -> x in
28 let predicate t = List.mem t.Text.id ids in
29 let pubdir_source, pubdir = match pubdir with Some d -> "--pubdir ", d | None ->
30 try "txt.conf:Pubdir", Kosuzu.Store.KV.find "Pubdir" kv with Not_found ->
31 try "$TXTPUBDIR", Sys.getenv "TXTPUBDIR" with Not_found -> "$TXTPUBDIR", ""
32 in
33 let targets = targets pubdir in
34 if targets = [] then
35 Printf.eprintf "No target directories in %s='%s' (for example %s)\n"
36 pubdir_source pubdir (Filename.concat pubdir "public_html")
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
47
48open Cmdliner
49
50let ids = Arg.(value & pos_all string [] & info [] ~docv: "Text ID")
51let pubdir = Arg.(value & opt (some string) None & info ["p"; "pubdir"] ~docv: "Directory path" ~doc: "Set top directory for publishing files")
52let publish_t = Term.(const publish $ pubdir $ ids)
53
54let cmd =
55 let doc = "Convert texts into pubnix-style directories if they exist" in
56 let man = [
57 `S Manpage.s_description;
58 `P "This subcommand is meant for people who use this software in shared hosts such as SDF or Tildeverse";
59 `P "Currently supports conversion to public_gemini (.gmi), public_gopher (.txt), and public_html (.htm[l])";
60 `S Manpage.s_environment;
61 `P "TXTPUBDIR - Pubnix-style output directory" ]
62 in
63 let info = Cmd.info "publish" ~doc ~man in
64 Cmd.v info publish_t
65
66(*
67let term =
68 let ids = Arg.(value & pos_all string [] & info [] ~docv:"text ids") in
69 let pubdir = Arg.(value & opt (some string) None & info ["p"; "pubdir"] ~docv:"directory path"
70 ~doc:"set top directory for publishing files") in
71 let doc = "convert texts into standard public dirs pubdir/public_{html,gemini,gopher} if they exist" in
72 Term.(const publish $ pubdir $ ids), Term.info "publish" ~doc ~man:[ `S "DESCRIPTION"; `P doc ]
73 *)
Note: See TracBrowser for help on using the repository browser.