In-Reply-To header field. Note extra list.rev in convert
git-svn-id: file:///srv/svn/repo/kosuzu/trunk@41 eb64cd80-c68d-6f47-b6a3-0ada418499da
This commit is contained in:
parent
da47c68af6
commit
3e971f40dc
@ -10,6 +10,7 @@ type t = {
|
|||||||
topic_roots: string list;
|
topic_roots: string list;
|
||||||
topics: (String_set.t * String_set.t) Topic_set.Map.t;
|
topics: (String_set.t * String_set.t) Topic_set.Map.t;
|
||||||
references: Ref_set.t Id_map.t;
|
references: Ref_set.t Id_map.t;
|
||||||
|
replies: Ref_set.t Id_map.t;
|
||||||
texts: Text.t list
|
texts: Text.t list
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,5 +26,6 @@ let empty () = {
|
|||||||
topic_roots = [];
|
topic_roots = [];
|
||||||
topics = Topic_set.Map.empty;
|
topics = Topic_set.Map.empty;
|
||||||
references = Id_map.empty;
|
references = Id_map.empty;
|
||||||
|
replies = Id_map.empty;
|
||||||
texts = []
|
texts = []
|
||||||
}
|
}
|
||||||
|
@ -33,19 +33,24 @@ let acc_ref id t a =
|
|||||||
) a
|
) a
|
||||||
|
|
||||||
let fold_refs text refs = String_set.fold (acc_ref text.Text.id) (Text.set "references" text) refs
|
let fold_refs text refs = String_set.fold (acc_ref text.Text.id) (Text.set "references" text) refs
|
||||||
|
let fold_reps text reps = String_set.fold (acc_ref text.Text.id) (Text.set "in-reply-to" text) reps
|
||||||
|
|
||||||
let directory converters noindex repo =
|
let directory converters noindex repo =
|
||||||
let fn (ts,refs,ls,acc) ((elt,_) as r) =
|
let fn (ts,refs,reps,ls,acc) ((elt,_) as r) =
|
||||||
Topic_set.to_map ts (Text.set "topics" elt),
|
Topic_set.to_map ts (Text.set "topics" elt),
|
||||||
fold_refs elt refs,
|
fold_refs elt refs, fold_reps elt reps,
|
||||||
elt::ls,
|
elt::ls,
|
||||||
if convert converters repo r then acc+1 else acc in
|
if convert converters {repo with references = refs; replies = reps} r then acc+1 else acc in
|
||||||
let topics, references, texts, count =
|
let topics, references, replies, texts, count =
|
||||||
File_store.(fold ~dir:repo.Conversion.dir ~order:newest fn (Topic_set.Map.empty, Conversion.Id_map.empty, [], 0)) in
|
File_store.(fold ~dir:repo.Conversion.dir ~order:oldest fn
|
||||||
|
(Topic_set.Map.empty, Conversion.Id_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)
|
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
|
with Not_found -> Topic_set.roots topics in
|
||||||
let repo = Conversion.{ repo with topic_roots; topics; references; texts } in
|
Printf.eprintf "%d\n" (Conversion.Id_map.cardinal replies);
|
||||||
if not noindex then List.iter (fun c -> match c.Conversion.indices with None -> () | Some f -> f repo) converters;
|
let repo = Conversion.{ repo with
|
||||||
|
topic_roots; topics; references; replies; texts = List.rev 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)
|
Printf.printf "Converted: %d Indexed: %d\n" count (List.length texts)
|
||||||
|
|
||||||
let load_kv dir =
|
let load_kv dir =
|
||||||
@ -73,12 +78,10 @@ let at_path types noindex path = match path with
|
|||||||
| Error s -> prerr_endline s
|
| Error s -> prerr_endline s
|
||||||
| Ok text ->
|
| Ok text ->
|
||||||
let dir = "." in
|
let dir = "." in
|
||||||
let references = File_store.(fold ~dir ~order:newest
|
let references, replies = File_store.(fold ~dir ~order:newest
|
||||||
(fun refs (elt, _) -> fold_refs elt refs) Conversion.Id_map.empty) in
|
(fun (refs, reps) (elt, _) -> fold_refs elt refs, fold_reps elt reps)
|
||||||
Conversion.Id_map.iter
|
(Conversion.Id_map.empty, Conversion.Id_map.empty)) in
|
||||||
(fun k v -> Conversion.Ref_set.iter (fun e -> Printf.eprintf "%s %s\n" k e) v)
|
let repo = { (Conversion.empty ()) with dir; kv = load_kv ""; references; replies } in
|
||||||
references;
|
|
||||||
let repo = { (Conversion.empty ()) with dir; kv = load_kv ""; references } in
|
|
||||||
ignore @@ convert (converters types repo.kv) repo (text, [path])
|
ignore @@ convert (converters types repo.kv) repo (text, [path])
|
||||||
)
|
)
|
||||||
| path -> Printf.eprintf "Path doesn't exist: %s" path
|
| path -> Printf.eprintf "Path doesn't exist: %s" path
|
||||||
|
@ -39,14 +39,14 @@ let wrap conv htm text_title body =
|
|||||||
(if feed <> "" then Printf.sprintf "<link rel='alternate' href='%s' type='application/atom+xml'>" feed else "")
|
(if feed <> "" then Printf.sprintf "<link rel='alternate' href='%s' type='application/atom+xml'>" feed else "")
|
||||||
header body footer
|
header body footer
|
||||||
|
|
||||||
let topic_link root topic =
|
let topic_link root topic =
|
||||||
let replaced_space = String.map (function ' '->'+' | x->x) in
|
let replaced_space = String.map (function ' '->'+' | x->x) in
|
||||||
"<a href='index." ^ root ^ ".htm#" ^ replaced_space topic ^ "'>"
|
"<a href='index." ^ root ^ ".htm#" ^ replaced_space topic ^ "'>"
|
||||||
^ String.capitalize_ascii topic ^ "</a>"
|
^ String.capitalize_ascii topic ^ "</a>"
|
||||||
|
|
||||||
module HtmlConverter = struct
|
module HtmlConverter = struct
|
||||||
include Converter.Html
|
include Converter.Html
|
||||||
let uid_uri u a = Printf.sprintf "%s<a href='%s%s'>%s</a>" a u ext u
|
let uid_uri u a = Printf.sprintf "%s<a href='%s%s'><%s></a>" a u ext u
|
||||||
let angled_uri u a =
|
let angled_uri u a =
|
||||||
if try String.sub u 0 10 = "urn:txtid:" with Invalid_argument _ -> false
|
if try String.sub u 0 10 = "urn:txtid:" with Invalid_argument _ -> false
|
||||||
then angled_uri (String.(sub u 10 (length u - 10)) ^ ext) a else angled_uri u a
|
then angled_uri (String.(sub u 10 (length u - 10)) ^ ext) a else angled_uri u a
|
||||||
@ -73,6 +73,7 @@ let page htm conversion text =
|
|||||||
let link l = HtmlConverter.uid_uri l "" in
|
let link l = HtmlConverter.uid_uri l "" in
|
||||||
String_set.fold (fun r a -> sep_append a (link r)) x ""
|
String_set.fold (fun r a -> sep_append a (link r)) x ""
|
||||||
in
|
in
|
||||||
|
Printf.eprintf "%s %d\n" text.id (Conversion.Id_map.cardinal conversion.Conversion.replies);
|
||||||
"<article><header><dl>"
|
"<article><header><dl>"
|
||||||
^ opt_kv "Title:" text.title
|
^ opt_kv "Title:" text.title
|
||||||
^ opt_kv "Authors:" authors
|
^ opt_kv "Authors:" authors
|
||||||
@ -81,9 +82,13 @@ let page htm conversion text =
|
|||||||
^ opt_kv "Topics:" (topic_links (set "topics" text))
|
^ opt_kv "Topics:" (topic_links (set "topics" text))
|
||||||
^ opt_kv "Id:" text.id
|
^ opt_kv "Id:" text.id
|
||||||
^ opt_kv "Refers:" (ref_links (set "references" text))
|
^ opt_kv "Refers:" (ref_links (set "references" text))
|
||||||
|
^ opt_kv "In reply to:" (ref_links (set "in-reply-to" text))
|
||||||
^ opt_kv "Referred by:" (try
|
^ opt_kv "Referred by:" (try
|
||||||
ref_links (Conversion.Id_map.find text.id conversion.Conversion.references)
|
ref_links (Conversion.Id_map.find text.id conversion.Conversion.references)
|
||||||
with Not_found -> "")
|
with Not_found -> "")
|
||||||
|
^ opt_kv "Replies:" (try
|
||||||
|
ref_links (Conversion.Id_map.find text.id conversion.Conversion.replies)
|
||||||
|
with Not_found -> "empty replies")
|
||||||
^ {|</dl></header><pre style="white-space:pre-wrap">|} in
|
^ {|</dl></header><pre style="white-space:pre-wrap">|} in
|
||||||
wrap conversion htm text.title ((T.of_string text.body header) ^ "</pre></article>")
|
wrap conversion htm text.title ((T.of_string text.body header) ^ "</pre></article>")
|
||||||
|
|
||||||
|
47
lib/text.ml
47
lib/text.ml
@ -22,11 +22,19 @@ let blank ?(id=(Id.generate ())) () = {
|
|||||||
let compare = Stdlib.compare
|
let compare = Stdlib.compare
|
||||||
let newest a b = Date.(compare a.date b.date)
|
let newest a b = Date.(compare a.date b.date)
|
||||||
let oldest a b = Date.(compare b.date a.date)
|
let oldest a b = Date.(compare b.date a.date)
|
||||||
let str key m = try String_map.find (String.lowercase_ascii key) m.string_map with Not_found -> ""
|
|
||||||
let set key m = try String_map.find (String.lowercase_ascii key) m.stringset_map with Not_found -> String_set.empty
|
let str key m =
|
||||||
let str_set key m = String_set.to_string @@ set key m
|
try String_map.find (String.lowercase_ascii key) m.string_map
|
||||||
let with_str_set ?(separator=String_set.of_csv_string) m key str = { m with
|
with Not_found -> ""
|
||||||
stringset_map = String_map.add (String.lowercase_ascii key) (separator str) m.stringset_map
|
|
||||||
|
let set key m =
|
||||||
|
try String_map.find (String.lowercase_ascii key) m.stringset_map
|
||||||
|
with Not_found -> String_set.empty
|
||||||
|
|
||||||
|
let with_str_set ?(separator=String_set.of_csv_string) m key str =
|
||||||
|
{ m with
|
||||||
|
stringset_map = String_map.add (String.lowercase_ascii key) (separator str)
|
||||||
|
m.stringset_map
|
||||||
}
|
}
|
||||||
|
|
||||||
let with_kv x (k,v) =
|
let with_kv x (k,v) =
|
||||||
@ -37,12 +45,12 @@ let with_kv x (k,v) =
|
|||||||
| "id" -> (match v with "" -> x | s -> { x with id = s })
|
| "id" -> (match v with "" -> x | s -> { x with id = s })
|
||||||
| "author"
|
| "author"
|
||||||
| "authors" -> { x with authors = Person.Set.of_string (trim v)}
|
| "authors" -> { x with authors = Person.Set.of_string (trim v)}
|
||||||
| "date" -> { x with date = Date.{ x.date with created = Date.of_string v }}
|
| "date" -> { x with date = Date.{ x.date with created = Date.of_string v }}
|
||||||
| "date-edited"-> { x with date = Date.{ x.date with edited = Date.of_string v }}
|
| "date-edited"-> { x with date = Date.{ x.date with edited = Date.of_string v }}
|
||||||
| "licences" | "topics" | "keywords" | "series" as k -> with_str_set x k v
|
| "licences" | "topics" | "keywords" | "series" as k -> with_str_set x k v
|
||||||
| "references" -> with_str_set
|
| "references" | "in-reply-to" -> with_str_set
|
||||||
~separator:(fun x -> String_set.map (fun x -> String.(sub x 1 (length x-2)))
|
~separator:(fun x -> String_set.map
|
||||||
(String_set.of_ssv_string x))
|
(fun x -> String.(sub x 1 (length x-2))) (String_set.of_ssv_string x))
|
||||||
x k v
|
x k v
|
||||||
| k -> { x with string_map = String_map.add k (trim v) x.string_map }
|
| k -> { x with string_map = String_map.add k (trim v) x.string_map }
|
||||||
|
|
||||||
@ -69,21 +77,26 @@ let of_string s =
|
|||||||
if note.id <> Id.nil then Ok note else Error "Missing ID header"
|
if note.id <> Id.nil then Ok note else Error "Missing ID header"
|
||||||
with _ -> Error ("Failed parsing" ^ s)
|
with _ -> Error ("Failed parsing" ^ s)
|
||||||
|
|
||||||
let to_string x =
|
let str_set key m = String_set.to_string @@ set key m
|
||||||
|
|
||||||
|
let to_string x =
|
||||||
let has_len v = String.length v > 0 in
|
let has_len v = String.length v > 0 in
|
||||||
let s field value = if has_len value then field ^ ": " ^ value ^ "\n" else "" in
|
let s field value = if has_len value then field ^ ": " ^ value ^ "\n" else "" in
|
||||||
let a value = if Person.Set.is_empty value then "" else "Authors: " ^ Person.Set.to_string value ^ "\n" in
|
let a value = if Person.Set.is_empty value then ""
|
||||||
let d field value = match value with "" -> "" | s -> field ^ ": " ^ Date.rfc_string s ^ "\n" in
|
else "Authors: " ^ Person.Set.to_string value ^ "\n" in
|
||||||
|
let d field value = match value with "" -> ""
|
||||||
|
| s -> field ^ ": " ^ Date.rfc_string s ^ "\n" in
|
||||||
let rows = [
|
let rows = [
|
||||||
s "ID" x.id;
|
s "ID" x.id;
|
||||||
d "Date" x.date.Date.created;
|
d "Date" x.date.Date.created;
|
||||||
d "Edited" x.date.Date.edited;
|
d "Edited" x.date.Date.edited;
|
||||||
s "Title" x.title;
|
s "Title" x.title;
|
||||||
a x.authors;
|
a x.authors;
|
||||||
s "Licences" (str_set "licences" x);
|
s "Licences" (str_set "licences" x);
|
||||||
s "Topics" (str_set "topics" x);
|
s "Topics" (str_set "topics" x);
|
||||||
s "Keywords" (str_set "keywords" x);
|
s "Keywords" (str_set "keywords" x);
|
||||||
s "References"(str_set "references" x);
|
s "References"(str_set "references" x); (*todo: add to output <>*)
|
||||||
|
s "In-Reply-To"(str_set "in-reply-to" x);
|
||||||
s "Series" (str_set "series" x);
|
s "Series" (str_set "series" x);
|
||||||
s "Abstract" (str "abstract" x);
|
s "Abstract" (str "abstract" x);
|
||||||
s "Alias" (str "Alias" x)
|
s "Alias" (str "Alias" x)
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
ID: ka4wtj
|
ID: ka4wtj
|
||||||
Title: Logarion
|
Title: Logarion
|
||||||
References: <3sqd84> <hvhhwf> <h1a9tg>
|
|
||||||
|
|
||||||
## Guides
|
## Guides
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user