Moved conversion file, conf -> pack, fixes
Conversion:
- Configuration sought in: txt.conf, ~/.config/txt/txt.conf
- logarion.conf to produce index and target formats
Publication:
- `publish <ids>`: copies txt with ID into Pubdir/public_{html,gemini,gopher} (Pubdir fromtxt.conf), if dirs exist, and runs `convert <pubdir>`
Fixes:
- Feed <nav> regression
git-svn-id: file:///srv/svn/repo/kosuzu/trunk@21 eb64cd80-c68d-6f47-b6a3-0ada418499da
This commit is contained in:
@@ -3,11 +3,18 @@ type item_t = t list
|
||||
type record_t = Text.t * item_t
|
||||
|
||||
let extension = ".txt"
|
||||
let def_dir () = try Sys.getenv "txtdir" with Not_found ->
|
||||
|
||||
let txtdir () = try Sys.getenv "txtdir" with Not_found ->
|
||||
let share = Filename.concat (Sys.getenv "HOME") ".local/share/texts/" in
|
||||
match Sys.is_directory share with true -> share
|
||||
| false | exception (Sys_error _) -> "."
|
||||
|
||||
let cfgpath () = match "txt.conf" with
|
||||
| filepath when Sys.file_exists filepath -> filepath
|
||||
| _ -> match Filename.concat (Sys.getenv "HOME") ".config/txt/txt.conf" with
|
||||
| filepath when Sys.file_exists filepath -> filepath
|
||||
| _ -> ""
|
||||
|
||||
let to_string f =
|
||||
let ic = open_in f in
|
||||
let s = really_input_string ic (in_channel_length ic) in
|
||||
@@ -80,13 +87,13 @@ let fold_sort_take ?(predicate=fun _ -> true) ?(number=None) comp flist =
|
||||
@@ List.fast_sort comp @@ TextMap.bindings
|
||||
@@ List.fold_left (fold_valid_text predicate) new_iteration flist
|
||||
|
||||
let iter ?(r=false) ?(dir=def_dir ()) ?(predicate=fun _ -> true) ?order ?number fn =
|
||||
let iter ?(r=false) ?(dir=txtdir ()) ?(predicate=fun _ -> true) ?order ?number fn =
|
||||
let flist = list_fs ~r dir in match order with
|
||||
| Some comp -> List.iter fn @@ fold_sort_take ~predicate ~number comp flist
|
||||
| None -> List.iter fn @@ TextMap.bindings @@
|
||||
List.fold_left (fold_valid_text predicate) new_iteration flist
|
||||
|
||||
let fold ?(r=false) ?(dir=def_dir ()) ?(predicate=fun _ -> true) ?order ?number fn acc =
|
||||
let fold ?(r=false) ?(dir=txtdir ()) ?(predicate=fun _ -> true) ?order ?number fn acc =
|
||||
let flist = list_fs ~r dir in match order with
|
||||
| Some comp -> List.fold_left fn acc @@ fold_sort_take ~predicate ~number comp flist
|
||||
| None -> List.fold_left fn acc @@ TextMap.bindings @@
|
||||
@@ -121,7 +128,7 @@ let id_filename repo extension text =
|
||||
let candidate = Filename.concat repo (text.id ^ "." ^ basename ^ extension) in
|
||||
if Sys.file_exists candidate then Error "Name clash, try again" else Ok candidate
|
||||
|
||||
let with_text ?(dir=def_dir ()) new_text =
|
||||
let with_text ?(dir=txtdir ()) new_text =
|
||||
match id_filename dir extension new_text with
|
||||
| Error _ as e -> e
|
||||
| Ok path ->
|
||||
@@ -133,10 +140,11 @@ module Config = struct
|
||||
let key_value k v a = Store.KV.add k (String.trim v) a
|
||||
end
|
||||
|
||||
let of_kv_file path =
|
||||
let of_kv_file ?(path=cfgpath ()) () =
|
||||
let open Text_parse in
|
||||
let subsyntaxes = Parsers.Key_value.[|
|
||||
(module Make (Config) : Parser.S with type t = Config.t); (module Make (Config)); |] in
|
||||
let of_string text acc =
|
||||
Parser.parse subsyntaxes { text; pos = 0; right_boundary = String.length text - 1 } acc in
|
||||
of_string (to_string @@ path) Store.KV.empty
|
||||
if path <> "" then of_string (to_string @@ path) Store.KV.empty
|
||||
else Store.KV.empty
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
let text_dir = Filename.concat (File_store.def_dir ()) "peers"
|
||||
let text_dir = Filename.concat (File_store.txtdir ()) "peers"
|
||||
|
||||
let fold fn init = match Sys.readdir text_dir with
|
||||
| exception (Sys_error msg) -> prerr_endline msg
|
||||
|
||||
Reference in New Issue
Block a user