Changeset 39 in code for trunk/cli


Ignore:
Timestamp:
Dec 12, 2022, 10:52:55 PM (2 years ago)
Author:
fox
Message:

Read References field; referred by listing; test & tidy documentation

Location:
trunk/cli
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/cli/conversion.ml

    r20 r39  
    11open Logarion
     2
     3module Ref_set = Set.Make(String)
     4module Id_map = Map.Make(String)
     5
    26type t = {
    37        id: string;
     
    610        topic_roots: string list;
    711        topics: (String_set.t * String_set.t) Topic_set.Map.t;
     12        references: Ref_set.t Id_map.t;
    813        texts: Text.t list
    914}
     
    2025        topic_roots = [];
    2126        topics = Topic_set.Map.empty;
     27        references = Id_map.empty;
    2228        texts = []
    2329}
  • trunk/cli/convert.ml

    r21 r39  
    2727        t
    2828
     29let acc_ref id t a =
     30        Conversion.Id_map.update t (function
     31        | Some s -> Some (Conversion.Ref_set.add id s)
     32        | None -> Some (Conversion.Ref_set.singleton id)
     33        ) a
     34
     35let fold_refs text refs = String_set.fold (acc_ref text.Text.id) (Text.set "references" text) refs
     36
    2937let directory converters noindex repo =
    30         let fn (ts,ls,acc) ((elt,_) as r) =
    31                 (Topic_set.to_map ts (Text.set "topics" elt)), elt::ls,
     38        let fn (ts,refs,ls,acc) ((elt,_) as r) =
     39                Topic_set.to_map ts (Text.set "topics" elt),
     40                fold_refs elt refs,
     41                elt::ls,
    3242                if convert converters repo r then acc+1 else acc in
    33         let topics, texts, count =
    34                 File_store.(fold ~dir:repo.Conversion.dir ~order:newest fn (Topic_set.Map.empty,[],0)) in
     43        let topics, references, texts, count =
     44                File_store.(fold ~dir:repo.Conversion.dir ~order:newest fn (Topic_set.Map.empty, Conversion.Id_map.empty, [], 0)) in
    3545        let topic_roots = try List.rev @@ String_set.list_of_csv (Store.KV.find "Topics" repo.kv)
    3646                with Not_found -> Topic_set.roots topics in
    37         let repo = Conversion.{ repo with topic_roots; topics; texts } in
     47        let repo = Conversion.{ repo with topic_roots; topics; references; texts } in
    3848        if not noindex then List.iter (fun c -> match c.Conversion.indices with None -> () | Some f -> f repo) converters;
    3949        Printf.printf "Converted: %d Indexed: %d\n" count (List.length texts)
     
    6373                        | Error s -> prerr_endline s
    6474                        | Ok text ->
    65                                 let repo = { (Conversion.empty ()) with dir = ""; kv = load_kv "" } in
     75                                let dir = "." in
     76                                let references = File_store.(fold ~dir ~order:newest
     77                                        (fun refs (elt, _) -> fold_refs elt refs) Conversion.Id_map.empty) in
     78                                        Conversion.Id_map.iter
     79                                                (fun k v -> Conversion.Ref_set.iter (fun e -> Printf.eprintf "%s %s\n" k e) v)
     80                                                references;
     81                                let repo = { (Conversion.empty ()) with dir; kv = load_kv ""; references } in
    6682                                ignore @@ convert (converters types repo.kv) repo (text, [path])
    6783                )
  • trunk/cli/html.ml

    r38 r39  
    2626                with Not_found -> if Sys.file_exists (Filename.concat conv.Conversion.dir "feed.atom")
    2727                        then "feed.atom" else "" in
    28         let header = match htm.templates.header with 
     28        let header = match htm.templates.header with
    2929                | Some x -> replace x
    3030                | None -> Printf.(sprintf "<header><a href='.'>%s</a>%s</header>" site_title
     
    4747module HtmlConverter = struct
    4848        include Converter.Html
     49        let uid_uri u a = Printf.sprintf "%s<a href='%s%s'>%s</a>" a u ext u
    4950        let angled_uri u a =
    5051                if try String.sub u 0 10 = "urn:txtid:" with Invalid_argument _ -> false
     
    7071                        String_set.fold to_linked x "" in
    7172                let ref_links x =
    72                         let link l = HtmlConverter.angled_uri (String.(sub l 1 (length l-2))) "" in
     73                        let link l = HtmlConverter.uid_uri l "" in
    7374                        String_set.fold (fun r a -> sep_append a (link r)) x ""
    7475                in
     
    8081                ^ opt_kv "Topics:" (topic_links (set "topics" text))
    8182                ^ opt_kv "Id:" text.id
    82                 ^ opt_kv "References:" (ref_links (set "references" text))
     83                ^ opt_kv "Refers:" (ref_links (set "references" text))
     84                ^ opt_kv "Referred by:" (try
     85                                ref_links (Conversion.Id_map.find text.id conversion.Conversion.references)
     86                                with Not_found -> "")
    8387                ^ {|</dl></header><pre style="white-space:pre-wrap">|} in
    8488        wrap conversion htm text.title ((T.of_string text.body header) ^ "</pre></article>")
Note: See TracChangeset for help on using the changeset viewer.