Changeset 21 in code


Ignore:
Timestamp:
Nov 1, 2022, 5:11:09 PM (2 years ago)
Author:
fox
Message:

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
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/cli/convert.ml

    r20 r21  
    4040
    4141let load_kv dir =
    42         let conf = Filename.concat dir ".convert.conf" in (* TODO: better name? *)
    43         let kv = if Sys.file_exists conf then File_store.of_kv_file conf else Store.KV.empty in
     42        let kv = File_store.of_kv_file () in
    4443        let idx = Filename.concat dir "index.pck" in
    4544        if not (Sys.file_exists idx) then kv else
     
    4948                        let kv = if Store.KV.mem "Id" kv then kv else Store.KV.add "Id" info.Header_pack.id kv in
    5049                        let kv = if Store.KV.mem "Title" kv then kv else Store.KV.add "Title" info.Header_pack.title kv in
    51                         let kv = Store.KV.add "Locations" (String.concat ";\n" info.Header_pack.locations) kv in
     50                        let kv = if Store.KV.mem "Locations" kv then kv else Store.KV.add "Locations" (String.concat ";\n" info.Header_pack.locations) kv in
    5251                        let kv = Store.KV.add "Peers" (String.concat ";\n" Header_pack.(to_str_list peers)) kv in
    5352                        kv
  • trunk/cli/html.ml

    r20 r21  
    2828        let header = match htm.templates.header with
    2929                | Some x -> replace x
    30                 | None -> Printf.(sprintf "<header><a href='.'>%s</a></header>%s" site_title
     30                | None -> Printf.(sprintf "<header><a href='.'>%s</a>%s</header>" site_title
    3131                                (if feed <> "" then sprintf "<nav><a href='%s' id='feed'>feed</a></nav>" feed else ""))
    3232        in
  • trunk/cli/publish.ml

    r13 r21  
    11let targets () =
    2         let home =
    3                 try Sys.getenv "txtpubdir" with Not_found ->
    4                 try Sys.getenv "HOME" with Not_found -> ""
     2        let kv = Logarion.File_store.of_kv_file () in
     3        let pub_dir =
     4                try Logarion.Store.KV.find "Pubdir" kv with Not_found ->
     5                try Sys.getenv "txtpubdir" with Not_found -> ""
    56        in
    6         List.filter
    7                 (fun x -> try Sys.is_directory (snd x) with Sys_error _ -> false)
    8                 [
    9                         "htm", home ^ "/public_html/txt";
    10                         "gmi", home ^ "/public_gemini/txt";
    11                         "", home ^ "/public_gopher/txt";
    12                 ]
     7        let exists_dir dir = Sys.is_directory (Filename.concat pub_dir dir) in
     8        List.filter (fun x -> try exists_dir (snd x) with Sys_error _ -> false) [
     9                "htm,atom", "public_html/";
     10                "gmi,gmi-atom", "public_gemini/";
     11                "", "public_gopher/";
     12        ]
    1313
    1414open Logarion
     
    1717        let targets = targets () in
    1818        let pub_dirs = List.map (fun x -> snd x) targets in
    19         try File_store.iter ~predicate (fun (_t, p) -> File.file ((List.hd p)::pub_dirs))
    20         with Unix.Unix_error (Unix.EEXIST, _, _) -> ();
    21         List.iter (fun t ->
     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);
    2223                Index.((load (snd t)) false None None None None);
    23                 Convert.at_path (fst t) false (snd t))
     24                Convert.at_path (fst t) false (snd t);
     25                prerr_endline (snd t))
    2426                targets
    2527
  • trunk/lib/file_store.ml

    r16 r21  
    44
    55let extension = ".txt"
    6 let def_dir () = try Sys.getenv "txtdir" with Not_found ->
     6
     7let txtdir () = try Sys.getenv "txtdir" with Not_found ->
    78        let share = Filename.concat (Sys.getenv "HOME") ".local/share/texts/" in
    89        match Sys.is_directory share with true -> share
    910        | false | exception (Sys_error _) -> "."
     11
     12let cfgpath () = match "txt.conf" with
     13        | filepath when Sys.file_exists filepath -> filepath
     14        | _ -> match Filename.concat (Sys.getenv "HOME") ".config/txt/txt.conf" with
     15                | filepath when Sys.file_exists filepath -> filepath
     16                | _ -> ""
    1017
    1118let to_string f =
     
    8188        @@ List.fold_left (fold_valid_text predicate) new_iteration flist
    8289
    83 let iter ?(r=false) ?(dir=def_dir ()) ?(predicate=fun _ -> true) ?order ?number fn =
     90let iter ?(r=false) ?(dir=txtdir ()) ?(predicate=fun _ -> true) ?order ?number fn =
    8491        let flist = list_fs ~r dir in match order with
    8592        | Some comp -> List.iter fn @@ fold_sort_take ~predicate ~number comp flist
     
    8794                List.fold_left (fold_valid_text predicate) new_iteration flist
    8895
    89 let fold ?(r=false) ?(dir=def_dir ()) ?(predicate=fun _ -> true) ?order ?number fn acc =
     96let fold ?(r=false) ?(dir=txtdir ()) ?(predicate=fun _ -> true) ?order ?number fn acc =
    9097        let flist = list_fs ~r dir in match order with
    9198        | Some comp -> List.fold_left fn acc @@ fold_sort_take ~predicate ~number comp flist
     
    122129        if Sys.file_exists candidate then Error "Name clash, try again" else Ok candidate
    123130
    124 let with_text ?(dir=def_dir ()) new_text =
     131let with_text ?(dir=txtdir ()) new_text =
    125132        match id_filename dir extension new_text with
    126133        | Error _ as e -> e
     
    134141end
    135142
    136 let of_kv_file path =
     143let of_kv_file ?(path=cfgpath ()) () =
    137144        let open Text_parse in
    138145        let subsyntaxes = Parsers.Key_value.[|
     
    140147        let of_string text acc =
    141148                Parser.parse subsyntaxes { text; pos = 0; right_boundary = String.length text - 1 } acc in
    142         of_string (to_string @@ path) Store.KV.empty
     149        if path <> "" then of_string (to_string @@ path) Store.KV.empty
     150        else Store.KV.empty
  • trunk/lib/peers.ml

    r16 r21  
    1 let text_dir = Filename.concat (File_store.def_dir ()) "peers"
     1let text_dir = Filename.concat (File_store.txtdir ()) "peers"
    22
    33let fold fn init = match Sys.readdir text_dir with
Note: See TracChangeset for help on using the changeset viewer.