diff --git a/app/convert.ml b/app/convert.ml index f8c9448..1450c4b 100644 --- a/app/convert.ml +++ b/app/convert.ml @@ -12,30 +12,17 @@ let writer dir name acc (text,store_item) = (* todo: single_parser -> [files] *) match Text.(str "Content-Type" text) with | "" | "text/plain" -> let filename = dir ^ "/" ^ Text.alias text in - let idfilename = dir ^ "/" ^ Id.to_string text.Text.uuid ^ ".txt" in - file_when_changed store_item idfilename (fun _title -> Text.to_string) text.title text; +(* let idfilename = dir ^ "/" ^ Id.to_string text.Text.uuid ^ ".txt" in*) +(* file_when_changed store_item idfilename (fun _title -> Text.to_string) text.title text;*) file_when_changed store_item (filename ^ ".html") (Html.page "") name text; file_when_changed store_item (filename ^ ".gmi") Gemini.page name text; (acc + 1) | x -> prerr_endline ("No converter for Content-Type: " ^ x ^ ", for " ^ text.Text.title); acc -let index_pack archive indexed_texts = - let persons ps = List.rev @@ Person.Set.fold (fun x a -> Msgpck.String (Person.to_string x) :: a) ps [] in - let to_pack a t = - let open Text in - let of_set field t = List.rev @@ String_set.fold (fun x a -> Msgpck.String x :: a) (set field t) [] in - Msgpck.(List [Bytes (Id.to_bytes t.uuid); String t.title; List (persons t.authors); List (of_set "topics" t); List (of_set "keywords" t)]) - :: a - in - let header_pack = Msgpck.List List.(fold_left to_pack [] indexed_texts) in - let columns = Msgpck.(List [String "id"; String "title"; String "authors"; String "topics"; String "keywords"]) in - let archive = Msgpck.(List [Int 0; String archive.A.name; List (persons archive.A.archivists)]) in - Bytes.to_string @@ Msgpck.Bytes.to_string (List [archive; columns; header_pack]) - let index_writer dir archive topic_roots topic_map indexed_texts = let name = archive.A.name in let file path = File_store.file (dir ^ path) in - file "/index.pck" (index_pack archive indexed_texts); + file "/index.pck" (Header_pack.pack archive indexed_texts); file "/index.html" (Html.topic_main_index name topic_roots indexed_texts); List.iter (fun topic -> file ("/index." ^ topic ^ ".htm") (Html.topic_sub_index name topic_map topic indexed_texts)) @@ -49,22 +36,24 @@ let index_writer dir archive topic_roots topic_map indexed_texts = let convert_all dir archive = let name = archive.A.name in - let published_count = A.(fold ~order:newest (writer dir name) 0 (published archive)) in + let count = A.(fold ~order:newest (writer dir name) 0 archive) in (*TODO: merge*) let topic_map, indexed_metas = let topic_map = Logarion.Topic_set.Map.empty in - let fn (ts,ls) (elt,_) = Logarion.(Topic_set.to_map ts (Text.set "topics" elt)), elt::ls in - A.(fold ~order:newest fn (topic_map,[]) (indexed archive)) in + let fn (ts,ls) (elt,_) = + Logarion.(Topic_set.to_map ts (Text.set "topics" elt)), elt::ls in + A.(fold ~order:newest fn (topic_map,[]) archive) in let topic_roots = Logarion.Topic_set.roots topic_map in index_writer dir archive topic_roots topic_map indexed_metas; - print_endline @@ "Converted: " ^ string_of_int (published_count) ^ "\nIndexed: " ^ string_of_int (List.length indexed_metas); + print_endline @@ "Converted: " ^ string_of_int (count) ^ "\nIndexed: " ^ string_of_int (List.length indexed_metas); Ok () let convert_dir cmd_dir = let (>>=) = Result.bind in let config_dir archive = try Ok (Store.KV.find "Export-Dir" archive.File_store.kv) with Not_found -> Error "unspecified export dir" in let init dir = - Result.map_error (function `Msg m -> m) Logarion.File_store.Directory.(directory dir |> print ~descr:"export" dir) in - (A.of_path "." + Result.map_error (function `Msg m -> m) + Logarion.File_store.Directory.(directory dir |> print ~descr:"export" dir) in + (A.of_path "." >>= fun archive -> (match cmd_dir with "" -> config_dir archive | x -> Ok x) >>= fun dir -> init dir >>= fun _ -> convert_all dir archive) diff --git a/app/html.ml b/app/html.ml index d3c9d37..f5435b3 100644 --- a/app/html.ml +++ b/app/html.ml @@ -107,7 +107,7 @@ let listing_index topic_map topic_roots path metas = let topic_main_index title topic_roots metas = wrap title "Topics" (fold_topic_roots topic_roots - ^ "