New optional pubdir parameter for txt publish
- Inform about pubdir value and txt.conf git-svn-id: file:///srv/svn/repo/kosuzu/trunk@26 eb64cd80-c68d-6f47-b6a3-0ada418499da
This commit is contained in:
parent
d93e9479bc
commit
0c0ba15974
@ -50,7 +50,7 @@ let base_url kv protocol = try
|
||||
let locs = Logarion.Store.KV.find "Locations" kv in
|
||||
let _i = Str.(search_forward (regexp (protocol ^ "://[^;]*")) locs 0) in
|
||||
Str.(matched_string locs)
|
||||
with Not_found -> Printf.eprintf "Missing location for %s" protocol; ""
|
||||
with Not_found -> Printf.eprintf "Missing location for %s, add it to txt.conf\n" protocol; ""
|
||||
|
||||
let indices alternate_type c =
|
||||
let file name = Logarion.File_store.file (Filename.concat c.Conversion.dir name) in
|
||||
@ -61,7 +61,7 @@ let indices alternate_type c =
|
||||
in
|
||||
let base_url = base_url c.kv protocol_regexp in
|
||||
let self = Filename.concat base_url fname in
|
||||
file fname @@
|
||||
file fname @@ (*TODO: alternate & self per url*)
|
||||
{|<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" xml:base="|} ^ base_url ^ {|"><title>|}
|
||||
^ title ^ {|</title><link rel="alternate" type="|} ^ alternate_type ^ {|" href="|}
|
||||
^ base_url ^ {|/" /><link rel="self" type="application/atom+xml" href="|}
|
||||
|
@ -1,32 +1,36 @@
|
||||
let targets kv =
|
||||
let pub_dir =
|
||||
let targets pubdir = List.fold_left
|
||||
(fun a x ->
|
||||
let path = Filename.concat pubdir (snd x) in
|
||||
try if Sys.is_directory path then (fst x, path)::a else a with Sys_error _ -> a)
|
||||
[]
|
||||
["htm,atom", "public_html/"; "gmi,gmi-atom", "public_gemini/"; "", "public_gopher/"]
|
||||
|
||||
open Logarion
|
||||
let publish pubdir ids =
|
||||
let kv = Logarion.File_store.of_kv_file () in
|
||||
let predicate t = List.mem t.Text.id ids in
|
||||
let pubdir = match pubdir with Some d -> d | None ->
|
||||
try Logarion.Store.KV.find "Pubdir" kv with Not_found ->
|
||||
try Sys.getenv "txtpubdir" with Not_found -> ""
|
||||
in
|
||||
let exists_dir dir = Sys.is_directory (Filename.concat pub_dir dir) in
|
||||
List.filter (fun x -> try exists_dir (snd x) with Sys_error _ -> false) [
|
||||
"htm,atom", "public_html/";
|
||||
"gmi,gmi-atom", "public_gemini/";
|
||||
"", "public_gopher/";
|
||||
]
|
||||
|
||||
open Logarion
|
||||
let publish ids =
|
||||
let kv = Logarion.File_store.of_kv_file () in
|
||||
let predicate t = List.mem t.Text.id ids in
|
||||
let targets = targets kv in
|
||||
let pub_dirs = List.map (fun x -> snd x) targets in
|
||||
File_store.iter ~predicate (fun (_t, p) ->
|
||||
try File.file ((List.hd p)::pub_dirs)
|
||||
with Unix.Unix_error (Unix.EEXIST, _, _) -> ());
|
||||
List.iter (fun t -> Printf.eprintf "%s %s\n" (fst t) (snd t);
|
||||
Index.((load (snd t)) false None None None None);
|
||||
Convert.at_path (fst t) false (snd t);
|
||||
prerr_endline (snd t))
|
||||
targets
|
||||
let targets = targets pubdir in
|
||||
if targets = [] then
|
||||
Printf.eprintf "No target directories in $pubdir='%s'\n" pubdir
|
||||
else begin
|
||||
let pub_dirs = List.map (fun x -> snd x) targets in
|
||||
File_store.iter ~predicate (fun (_t, p) ->
|
||||
try File.file ((List.hd p)::pub_dirs)
|
||||
with Unix.Unix_error (Unix.EEXIST, _, _) -> ());
|
||||
List.iter (fun t -> Printf.eprintf "%s %s\n" (fst t) (snd t);
|
||||
Index.((load (snd t)) false None None None None);
|
||||
Convert.at_path (fst t) false (snd t))
|
||||
targets
|
||||
end
|
||||
|
||||
open Cmdliner
|
||||
let term =
|
||||
let ids = Arg.(value & pos_all string [] & info [] ~docv:"text ids") in
|
||||
let doc = "convert texts into standard public dirs public_{html,gemini,gopher} if they exist" in
|
||||
Term.(const publish $ ids), Term.info "publish" ~doc ~man:[ `S "DESCRIPTION"; `P doc ]
|
||||
let pubdir = Arg.(value & opt (some string) None & info ["p"; "pubdir"] ~docv:"directory path"
|
||||
~doc:"set top directory for publishing files") in
|
||||
let doc = "convert texts into standard public dirs pubdir/public_{html,gemini,gopher} if they exist" in
|
||||
Term.(const publish $ pubdir $ ids), Term.info "publish" ~doc ~man:[ `S "DESCRIPTION"; `P doc ]
|
||||
|
Loading…
x
Reference in New Issue
Block a user