- Timestamp:
- Dec 13, 2022, 11:04:19 PM (2 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/cli/conversion.ml
r39 r41 11 11 topics: (String_set.t * String_set.t) Topic_set.Map.t; 12 12 references: Ref_set.t Id_map.t; 13 replies: Ref_set.t Id_map.t; 13 14 texts: Text.t list 14 15 } … … 26 27 topics = Topic_set.Map.empty; 27 28 references = Id_map.empty; 29 replies = Id_map.empty; 28 30 texts = [] 29 31 } -
trunk/cli/convert.ml
r39 r41 34 34 35 35 let fold_refs text refs = String_set.fold (acc_ref text.Text.id) (Text.set "references" text) refs 36 let fold_reps text reps = String_set.fold (acc_ref text.Text.id) (Text.set "in-reply-to" text) reps 36 37 37 38 let 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) = 39 40 Topic_set.to_map ts (Text.set "topics" elt), 40 fold_refs elt refs, 41 fold_refs elt refs, fold_reps elt reps, 41 42 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 45 47 let topic_roots = try List.rev @@ String_set.list_of_csv (Store.KV.find "Topics" repo.kv) 46 48 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; 49 54 Printf.printf "Converted: %d Indexed: %d\n" count (List.length texts) 50 55 … … 74 79 | Ok text -> 75 80 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 82 85 ignore @@ convert (converters types repo.kv) repo (text, [path]) 83 86 ) -
trunk/cli/html.ml
r39 r41 40 40 header body footer 41 41 42 let topic_link root topic = 42 let topic_link root topic = 43 43 let replaced_space = String.map (function ' '->'+' | x->x) in 44 44 "<a href='index." ^ root ^ ".htm#" ^ replaced_space topic ^ "'>" … … 47 47 module HtmlConverter = struct 48 48 include Converter.Html 49 let uid_uri u a = Printf.sprintf "%s<a href='%s%s'> %s</a>" a u ext u49 let uid_uri u a = Printf.sprintf "%s<a href='%s%s'><%s></a>" a u ext u 50 50 let angled_uri u a = 51 51 if try String.sub u 0 10 = "urn:txtid:" with Invalid_argument _ -> false … … 74 74 String_set.fold (fun r a -> sep_append a (link r)) x "" 75 75 in 76 Printf.eprintf "%s %d\n" text.id (Conversion.Id_map.cardinal conversion.Conversion.replies); 76 77 "<article><header><dl>" 77 78 ^ opt_kv "Title:" text.title … … 82 83 ^ opt_kv "Id:" text.id 83 84 ^ opt_kv "Refers:" (ref_links (set "references" text)) 85 ^ opt_kv "In reply to:" (ref_links (set "in-reply-to" text)) 84 86 ^ opt_kv "Referred by:" (try 85 87 ref_links (Conversion.Id_map.find text.id conversion.Conversion.references) 86 88 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") 87 92 ^ {|</dl></header><pre style="white-space:pre-wrap">|} in 88 93 wrap conversion htm text.title ((T.of_string text.body header) ^ "</pre></article>") -
trunk/lib/text.ml
r39 r41 23 23 let newest a b = Date.(compare a.date b.date) 24 24 let 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 26 let str key m = 27 try String_map.find (String.lowercase_ascii key) m.string_map 28 with Not_found -> "" 29 30 let set key m = 31 try String_map.find (String.lowercase_ascii key) m.stringset_map 32 with Not_found -> String_set.empty 33 34 let 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 30 38 } 31 39 … … 38 46 | "author" 39 47 | "authors" -> { x with authors = Person.Set.of_string (trim v)} 40 | "date" -> { x with date = Date.{ x.date with created 41 | "date-edited"-> { x with date = Date.{ x.date with edited 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 }} 42 50 | "licences" | "topics" | "keywords" | "series" as k -> with_str_set x k v 43 | "references" -> with_str_set44 ~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)) 46 54 x k v 47 55 | k -> { x with string_map = String_map.add k (trim v) x.string_map } … … 70 78 with _ -> Error ("Failed parsing" ^ s) 71 79 72 let to_string x = 80 let str_set key m = String_set.to_string @@ set key m 81 82 let to_string x = 73 83 let has_len v = String.length v > 0 in 74 84 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 77 89 let rows = [ 78 90 s "ID" x.id; 79 d "Date" 80 d "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; 82 94 a x.authors; 83 95 s "Licences" (str_set "licences" x); 84 96 s "Topics" (str_set "topics" x); 85 97 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); 87 100 s "Series" (str_set "series" x); 88 101 s "Abstract" (str "abstract" x); -
trunk/readme.txt
r39 r41 1 1 ID: ka4wtj 2 2 Title: Logarion 3 References: <3sqd84> <hvhhwf> <h1a9tg>4 3 5 4 ## Guides
Note:
See TracChangeset
for help on using the changeset viewer.