Read References field; referred by listing; test & tidy documentation
git-svn-id: file:///srv/svn/repo/kosuzu/trunk@39 eb64cd80-c68d-6f47-b6a3-0ada418499da
This commit is contained in:
@@ -26,15 +26,25 @@ let converters types kv =
|
||||
let t = if List.(mem "all" n || mem "gmi-atom" n) then (Atom.converter "text/gemini")::t else t in
|
||||
t
|
||||
|
||||
let acc_ref id t a =
|
||||
Conversion.Id_map.update t (function
|
||||
| Some s -> Some (Conversion.Ref_set.add id s)
|
||||
| None -> Some (Conversion.Ref_set.singleton id)
|
||||
) a
|
||||
|
||||
let fold_refs text refs = String_set.fold (acc_ref text.Text.id) (Text.set "references" text) refs
|
||||
|
||||
let directory converters noindex repo =
|
||||
let fn (ts,ls,acc) ((elt,_) as r) =
|
||||
(Topic_set.to_map ts (Text.set "topics" elt)), elt::ls,
|
||||
let fn (ts,refs,ls,acc) ((elt,_) as r) =
|
||||
Topic_set.to_map ts (Text.set "topics" elt),
|
||||
fold_refs elt refs,
|
||||
elt::ls,
|
||||
if convert converters repo r then acc+1 else acc in
|
||||
let topics, texts, count =
|
||||
File_store.(fold ~dir:repo.Conversion.dir ~order:newest fn (Topic_set.Map.empty,[],0)) in
|
||||
let topics, references, texts, count =
|
||||
File_store.(fold ~dir:repo.Conversion.dir ~order:newest fn (Topic_set.Map.empty, Conversion.Id_map.empty, [], 0)) in
|
||||
let topic_roots = try List.rev @@ String_set.list_of_csv (Store.KV.find "Topics" repo.kv)
|
||||
with Not_found -> Topic_set.roots topics in
|
||||
let repo = Conversion.{ repo with topic_roots; topics; texts } in
|
||||
let repo = Conversion.{ repo with topic_roots; topics; references; texts } in
|
||||
if not noindex then List.iter (fun c -> match c.Conversion.indices with None -> () | Some f -> f repo) converters;
|
||||
Printf.printf "Converted: %d Indexed: %d\n" count (List.length texts)
|
||||
|
||||
@@ -62,7 +72,13 @@ let at_path types noindex path = match path with
|
||||
match File_store.to_text path with
|
||||
| Error s -> prerr_endline s
|
||||
| Ok text ->
|
||||
let repo = { (Conversion.empty ()) with dir = ""; kv = load_kv "" } in
|
||||
let dir = "." in
|
||||
let references = File_store.(fold ~dir ~order:newest
|
||||
(fun refs (elt, _) -> fold_refs elt refs) Conversion.Id_map.empty) in
|
||||
Conversion.Id_map.iter
|
||||
(fun k v -> Conversion.Ref_set.iter (fun e -> Printf.eprintf "%s %s\n" k e) v)
|
||||
references;
|
||||
let repo = { (Conversion.empty ()) with dir; kv = load_kv ""; references } in
|
||||
ignore @@ convert (converters types repo.kv) repo (text, [path])
|
||||
)
|
||||
| path -> Printf.eprintf "Path doesn't exist: %s" path
|
||||
|
||||
Reference in New Issue
Block a user