Changeset 41 in code for trunk


Ignore:
Timestamp:
Dec 13, 2022, 11:04:19 PM (2 years ago)
Author:
fox
Message:

In-Reply-To header field. Note extra list.rev in convert

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/cli/conversion.ml

    r39 r41  
    1111        topics: (String_set.t * String_set.t) Topic_set.Map.t;
    1212        references: Ref_set.t Id_map.t;
     13        replies: Ref_set.t Id_map.t;
    1314        texts: Text.t list
    1415}
     
    2627        topics = Topic_set.Map.empty;
    2728        references = Id_map.empty;
     29        replies = Id_map.empty;
    2830        texts = []
    2931}
  • trunk/cli/convert.ml

    r39 r41  
    3434
    3535let fold_refs text refs = String_set.fold (acc_ref text.Text.id) (Text.set "references" text) refs
     36let fold_reps text reps = String_set.fold (acc_ref text.Text.id) (Text.set "in-reply-to" text) reps
    3637
    3738let directory converters noindex repo =
    38         let fn (ts,refs,ls,acc) ((elt,_) as r) =
     39        let fn (ts,refs,reps,ls,acc) ((elt,_) as r) =
    3940                Topic_set.to_map ts (Text.set "topics" elt),
    40                 fold_refs elt refs,
     41                fold_refs elt refs, fold_reps elt reps,
    4142                elt::ls,
    42                 if convert converters repo r then acc+1 else acc 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
     43                if convert converters {repo with references = refs; replies = reps} r then acc+1 else acc in
     44        let topics, references, replies, texts, count =
     45                File_store.(fold ~dir:repo.Conversion.dir ~order:oldest fn
     46                        (Topic_set.Map.empty, Conversion.Id_map.empty, Conversion.Id_map.empty, [], 0)) in
    4547        let topic_roots = try List.rev @@ String_set.list_of_csv (Store.KV.find "Topics" repo.kv)
    4648                with Not_found -> Topic_set.roots topics in
    47         let repo = Conversion.{ repo with topic_roots; topics; references; texts } in
    48         if not noindex then List.iter (fun c -> match c.Conversion.indices with None -> () | Some f -> f repo) converters;
     49        Printf.eprintf "%d\n" (Conversion.Id_map.cardinal replies);
     50        let repo = Conversion.{ repo with
     51                topic_roots; topics; references; replies; texts = List.rev texts } in
     52        if not noindex then
     53                List.iter (fun c -> match c.Conversion.indices with None -> () | Some f -> f repo) converters;
    4954        Printf.printf "Converted: %d Indexed: %d\n" count (List.length texts)
    5055
     
    7479                        | Ok text ->
    7580                                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
     81                                let references, replies = File_store.(fold ~dir ~order:newest
     82                                        (fun (refs, reps) (elt, _) -> fold_refs elt refs, fold_reps elt reps)
     83                                        (Conversion.Id_map.empty, Conversion.Id_map.empty)) in
     84                                let repo = { (Conversion.empty ()) with dir; kv = load_kv ""; references; replies } in
    8285                                ignore @@ convert (converters types repo.kv) repo (text, [path])
    8386                )
  • trunk/cli/html.ml

    r39 r41  
    4040        header body footer
    4141
    42 let topic_link root topic = 
     42let topic_link root topic =
    4343        let replaced_space = String.map (function ' '->'+' | x->x) in
    4444        "<a href='index." ^ root ^ ".htm#" ^ replaced_space topic ^ "'>"
     
    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
     49        let uid_uri u a = Printf.sprintf "%s<a href='%s%s'>&lt;%s&gt;</a>" a u ext u
    5050        let angled_uri u a =
    5151                if try String.sub u 0 10 = "urn:txtid:" with Invalid_argument _ -> false
     
    7474                        String_set.fold (fun r a -> sep_append a (link r)) x ""
    7575                in
     76                Printf.eprintf "%s %d\n" text.id (Conversion.Id_map.cardinal conversion.Conversion.replies);
    7677                "<article><header><dl>"
    7778                ^ opt_kv "Title:" text.title
     
    8283                ^ opt_kv "Id:" text.id
    8384                ^ opt_kv "Refers:" (ref_links (set "references" text))
     85                ^ opt_kv "In reply to:" (ref_links (set "in-reply-to" text))
    8486                ^ opt_kv "Referred by:" (try
    8587                                ref_links (Conversion.Id_map.find text.id conversion.Conversion.references)
    8688                                with Not_found -> "")
     89                ^ opt_kv "Replies:" (try
     90                                ref_links (Conversion.Id_map.find text.id conversion.Conversion.replies)
     91                                with Not_found -> "empty replies")
    8792                ^ {|</dl></header><pre style="white-space:pre-wrap">|} in
    8893        wrap conversion htm text.title ((T.of_string text.body header) ^ "</pre></article>")
  • trunk/lib/text.ml

    r39 r41  
    2323let newest a b = Date.(compare a.date b.date)
    2424let oldest a b = Date.(compare b.date a.date)
    25 let str key m = try String_map.find (String.lowercase_ascii key) m.string_map with Not_found -> ""
    26 let set key m = try String_map.find (String.lowercase_ascii key) m.stringset_map with Not_found -> String_set.empty
    27 let str_set key m = String_set.to_string @@ set key m
    28 let with_str_set ?(separator=String_set.of_csv_string) m key str = { m with
    29         stringset_map = String_map.add (String.lowercase_ascii key) (separator str) m.stringset_map
     25
     26let str key m =
     27        try String_map.find (String.lowercase_ascii key) m.string_map
     28        with Not_found -> ""
     29
     30let set key m =
     31        try String_map.find (String.lowercase_ascii key) m.stringset_map
     32        with Not_found -> String_set.empty
     33
     34let with_str_set ?(separator=String_set.of_csv_string) m key str =
     35        { m with
     36                stringset_map = String_map.add (String.lowercase_ascii key) (separator str)
     37                        m.stringset_map
    3038        }
    3139
     
    3846        | "author"
    3947        | "authors" -> { x with authors = Person.Set.of_string (trim v)}
    40         | "date"                         -> { x with date = Date.{ x.date with created  = Date.of_string v }}
    41         | "date-edited"-> { x with date = Date.{ x.date with edited             = Date.of_string v }}
     48        | "date"                         -> { x with date = Date.{ x.date with created = Date.of_string v }}
     49        | "date-edited"-> { x with date = Date.{ x.date with edited  = Date.of_string v }}
    4250        | "licences" | "topics" | "keywords" | "series" as k -> with_str_set x k v
    43         | "references" -> with_str_set
    44                         ~separator:(fun x -> String_set.map (fun x -> String.(sub x 1 (length x-2)))
    45                                 (String_set.of_ssv_string x))
     51        | "references" | "in-reply-to" -> with_str_set
     52                        ~separator:(fun x -> String_set.map
     53                                (fun x -> String.(sub x 1 (length x-2))) (String_set.of_ssv_string x))
    4654                        x k v
    4755        | k -> { x with string_map = String_map.add k (trim v) x.string_map }
     
    7078        with _ -> Error ("Failed parsing" ^ s)
    7179
    72 let to_string x =
     80let str_set key m = String_set.to_string @@ set key m
     81
     82let to_string x =
    7383        let has_len v = String.length v > 0 in
    7484        let s field value = if has_len value then field ^ ": " ^ value ^ "\n" else "" in
    75         let a value = if Person.Set.is_empty value then "" else "Authors: " ^ Person.Set.to_string value ^ "\n" in
    76         let d field value = match value with "" -> "" | s -> field ^ ": " ^ Date.rfc_string s ^ "\n" in
     85        let a value = if Person.Set.is_empty value then ""
     86                else "Authors: " ^ Person.Set.to_string value ^ "\n" in
     87        let d field value = match value with "" -> ""
     88                | s -> field ^ ": " ^ Date.rfc_string s ^ "\n" in
    7789        let rows = [
    7890                s "ID" x.id;
    79                 d "Date"     x.date.Date.created;
    80                 d "Edited"   x.date.Date.edited;
    81                 s "Title" x.title;
     91                d "Date"   x.date.Date.created;
     92                d "Edited" x.date.Date.edited;
     93                s "Title"  x.title;
    8294                a x.authors;
    8395                s "Licences" (str_set "licences" x);
    8496                s "Topics"   (str_set "topics" x);
    8597                s "Keywords" (str_set "keywords" x);
    86                 s "References"(str_set "references" x);
     98                s "References"(str_set "references" x); (*todo: add to output <>*)
     99                s "In-Reply-To"(str_set "in-reply-to" x);
    87100                s "Series"   (str_set "series" x);
    88101                s "Abstract" (str "abstract" x);
  • trunk/readme.txt

    r39 r41  
    11ID: ka4wtj
    22Title: Logarion
    3 References: <3sqd84> <hvhhwf> <h1a9tg>
    43
    54## Guides
Note: See TracChangeset for help on using the changeset viewer.