source: code/trunk/lib/header_pack.ml@ 6

Last change on this file since 6 was 3, checked in by fox, 3 years ago
  • Removed 'txt init'

Format

  • New B32 ID

Index

  • New option: txt index --print
  • Move scheme to peers
  • Replace peer.*.conf files with index packed locations Instead of adding a URL to peers.*.conf, run txt pull <url>

Conversion

  • Rewritten converters
  • txt-convert looks for a .convert.conf containing key: value lines.
  • Specifiable topic-roots from .convert.conf.
  • Added Topics: key, with comma seperated topics.

If set only those topics will appear in the main index and used as topic roots.
Other topics will have sub-indices generated, but won't be listed in the main index.

  • HTML converter header & footer options
  • HTML-index renamed to HTM-index

Internal

  • Change types: uuid:Uuid -> id:string
  • File_store merges identical texts
  • Use peer ID for store path, store peers' texts in .local/share/texts
  • Simple URN resolution for converter

Continue to next feed if parsing one fails

  • Phasing-out Archive, replaced by improved packs
  • Eliminate Bos, Cohttp, lwt, uri, tls, Re, Ptime, dependencies
  • Lock version for Cmdliner, fix dune-project
  • Optional resursive store
  • Improve header_pack
  • Fix recursive mkdir
File size: 3.3 KB
Line 
1let version = 0
2type info_t = { version: int; id: string; title: string; people: string list; locations: string list }
3type t = { info: info_t; fields: Msgpck.t; texts: Msgpck.t; peers: Msgpck.t }
4
5let of_id id = Msgpck.of_string id
6let to_id = Msgpck.to_string
7
8let person p = Msgpck.String (Person.to_string p)
9let persons ps = Msgpck.of_list @@ List.rev @@ Person.Set.fold (fun p a -> person p :: a) ps []
10
11let str = Msgpck.of_string
12let str_list ls = Msgpck.of_list @@ List.map str ls
13let to_str_list x = List.map Msgpck.to_string (Msgpck.to_list x)
14
15let of_set field t =
16 List.rev @@ String_set.fold (fun s a -> Msgpck.String s :: a) (Text.set field t) []
17
18let date = function "" -> Int32.zero | date -> Int32.of_int (Date.to_secs date)
19
20let to_sec = function Msgpck.Int i -> Int32.of_int i | Msgpck.Uint32 i -> i | x -> Msgpck.to_uint32 x
21
22let fields = Msgpck.(List [String "id"; String "time"; String "title"; String "authors"; String "topics"])
23let to_fields fieldpack = List.map Msgpck.to_string (Msgpck.to_list fieldpack)
24
25let to_info = function
26 | Msgpck.List (v::id::n::a::ls::[]) ->
27 let people = to_str_list a in
28 let locations = to_str_list ls in
29 Msgpck.({version = to_int v; id = to_string id; title = to_string n; people; locations})
30 | _ -> invalid_arg "Pack header"
31
32let of_info i = let open Msgpck in
33 List [Int i.version; String i.id; String i.title; str_list i.people; str_list i.locations]
34
35let of_text a t =
36 let open Text in
37 Msgpck.(List [
38 of_id t.id; of_uint32 (date (Date.listing t.date));
39 String t.title; persons t.authors; List (of_set "topics" t)
40 ]) :: a
41
42let of_text_list l = Msgpck.List l
43
44let pack p = Msgpck.List [of_info p.info; p.fields; p.texts; p.peers]
45let string p = Bytes.to_string @@ Msgpck.Bytes.to_string @@ pack p
46
47let unpack = function
48 | Msgpck.List (i::fields::texts::[]) ->
49 Ok { info = to_info i; fields; texts; peers = Msgpck.List [] }
50 | Msgpck.List (i::fields::texts::peers::[]) ->
51 Ok { info = to_info i; fields; texts; peers }
52 | _ -> Error "format mismatch"
53
54let of_string s = unpack @@ snd @@ Msgpck.StringBuf.read s
55
56let list filename = try
57 let texts_list = function
58 | Msgpck.List (_info :: _fields :: [texts]) -> Msgpck.to_list texts
59 | _ -> prerr_endline "malformed feed"; [] in
60 let _pos, data = Msgpck.StringBuf.read @@ File_store.to_string filename in
61 Ok (texts_list data)
62 with Not_found -> Error "unspecified export dir"
63
64let contains text = function
65 | Msgpck.List (id::_time::title::_authors::_topics::[]) ->
66 (match to_id id with
67 | "" -> prerr_endline ("Invalid id for " ^ Msgpck.to_string title); false
68 | id -> text.Text.id = id)
69 | _ -> prerr_endline ("Invalid record pattern"); false
70
71
72(*let pack_filename ?(filename="index.pck") archive =*)
73(* let dir = Store.KV.find "Export-Dir" archive.File_store.kv in (*raises Not_found*)*)
74(* dir ^ "/" ^ filename*)
75
76(*let add archive records =*)
77(* let fname = pack_filename archive in*)
78(* let append published (t, _f) = if List.exists (contains t) published then published else to_pack published t in*)
79(* match list fname with Error e -> prerr_endline e | Ok published_list ->*)
80(* let header_pack = List.fold_left append published_list records in*)
81(* let archive = Msgpck.(List [*)
82(* Int 0; String archive.File_store.name; persons archive.people]) in*)
83(* File_store.file fname @@ Bytes.to_string*)
84(* @@ Msgpck.Bytes.to_string (List [archive; fields; Msgpck.List header_pack])*)
Note: See TracBrowser for help on using the repository browser.