Changeset 26 in code for trunk


Ignore:
Timestamp:
Nov 16, 2022, 10:02:07 PM (2 years ago)
Author:
fox
Message:

New optional pubdir parameter for txt publish

  • Inform about pubdir value and txt.conf
Location:
trunk/cli
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/cli/atom.ml

    r19 r26  
    5151        let _i = Str.(search_forward (regexp (protocol ^ "://[^;]*")) locs 0) in
    5252        Str.(matched_string locs)
    53         with Not_found -> Printf.eprintf "Missing location for %s" protocol; ""
     53        with Not_found -> Printf.eprintf "Missing location for %s, add it to txt.conf\n" protocol; ""
    5454
    5555let indices alternate_type c =
     
    6262        let base_url = base_url c.kv protocol_regexp in
    6363        let self = Filename.concat base_url fname in
    64         file fname @@
     64        file fname @@ (*TODO: alternate & self per url*)
    6565          {|<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" xml:base="|} ^ base_url ^ {|"><title>|}
    6666          ^ title ^ {|</title><link rel="alternate" type="|} ^ alternate_type ^ {|" href="|}
  • trunk/cli/publish.ml

    r22 r26  
    1 let targets kv =
    2         let pub_dir =
     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
     8open Logarion
     9let publish pubdir ids =
     10        let kv = Logarion.File_store.of_kv_file () in
     11        let predicate t = List.mem t.Text.id ids in
     12        let pubdir = match pubdir with Some d -> d | None ->
    313                try Logarion.Store.KV.find "Pubdir" kv with Not_found ->
    414                try Sys.getenv "txtpubdir" with Not_found -> ""
    515        in
    6         let exists_dir dir = Sys.is_directory (Filename.concat pub_dir dir) in
    7         List.filter (fun x -> try exists_dir (snd x) with Sys_error _ -> false) [
    8                 "htm,atom", "public_html/";
    9                 "gmi,gmi-atom", "public_gemini/";
    10                 "", "public_gopher/";
    11         ]
    12 
    13 open Logarion
    14 let publish ids =
    15         let kv = Logarion.File_store.of_kv_file () in
    16         let predicate t = List.mem t.Text.id ids in
    17         let targets = targets kv in
    18         let pub_dirs = List.map (fun x -> snd x) targets in
    19         File_store.iter ~predicate (fun (_t, p) ->
    20                 try File.file ((List.hd p)::pub_dirs)
    21                 with Unix.Unix_error (Unix.EEXIST, _, _) -> ());
    22         List.iter (fun t -> Printf.eprintf "%s %s\n" (fst t) (snd t);
    23                 Index.((load (snd t)) false None None None None);
    24                 Convert.at_path (fst t) false (snd t);
    25                 prerr_endline (snd t))
    26                 targets
     16        let targets = targets pubdir in
     17        if targets = [] then
     18                Printf.eprintf "No target directories in $pubdir='%s'\n" pubdir
     19        else begin
     20                let pub_dirs = List.map (fun x -> snd x) targets in
     21                File_store.iter ~predicate (fun (_t, p) ->
     22                        try File.file ((List.hd p)::pub_dirs)
     23                        with Unix.Unix_error (Unix.EEXIST, _, _) -> ());
     24                List.iter (fun t -> Printf.eprintf "%s %s\n" (fst t) (snd t);
     25                        Index.((load (snd t)) false None None None None);
     26                        Convert.at_path (fst t) false (snd t))
     27                        targets
     28        end
    2729
    2830open Cmdliner
    2931let term =
    3032        let ids = Arg.(value & pos_all string [] & info [] ~docv:"text ids") in
    31         let doc = "convert texts into standard public dirs public_{html,gemini,gopher} if they exist" in
    32         Term.(const publish $ ids), Term.info "publish" ~doc ~man:[ `S "DESCRIPTION"; `P doc ]
     33        let pubdir = Arg.(value & opt (some string) None & info ["p"; "pubdir"] ~docv:"directory path"
     34                ~doc:"set top directory for publishing files") in
     35        let doc = "convert texts into standard public dirs pubdir/public_{html,gemini,gopher} if they exist" in
     36        Term.(const publish $ pubdir $ ids), Term.info "publish" ~doc ~man:[ `S "DESCRIPTION"; `P doc ]
Note: See TracChangeset for help on using the changeset viewer.