Files
kosuzu/cli/index.ml
fox 787cba90fe - 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

git-svn-id: file:///srv/svn/repo/kosuzu/trunk@3 eb64cd80-c68d-6f47-b6a3-0ada418499da
2022-04-15 13:17:01 +00:00

60 lines
2.5 KiB
OCaml

open Logarion
let index print title authors locations peers dir =
let fname = Filename.concat dir "index.pck" in
let pck = match Header_pack.of_string @@ File_store.to_string fname with
| Error s -> failwith s
| Ok pck -> let info = Header_pack.{ pck.info with
title = if title <> "" then title else pck.info.title;
people = if authors <> ""
then (String_set.list_of_csv authors) else pck.info.people;
locations = if locations <> ""
then (String_set.list_of_csv locations) else pck.info.locations;
} in
Header_pack.{ info; fields;
texts = of_text_list @@ File_store.fold ~dir
(fun a (t,_) -> of_text a t) [];
peers = if peers <> ""
then (str_list @@ String_set.list_of_csv peers) else pck.peers;
}
| exception (Sys_error _) -> Header_pack.{
info = {
version = version; id = Id.generate (); title;
people = String_set.list_of_csv authors;
locations = String_set.list_of_csv locations };
fields;
texts = of_text_list @@ File_store.fold ~dir
(fun a (t,_) -> of_text a t) [];
peers = str_list @@ String_set.list_of_csv peers;
} in
File_store.file fname (Header_pack.string pck);
let open Header_pack in
let s ss = String.concat "\n\t" ss in
if print then
Printf.printf "Title: %s\nAuthors: %s\nLocations:\n\t%s\nPeers:\n\t%s\n"
pck.info.title (String.concat "," pck.info.people)
(s pck.info.locations) (s (to_str_list pck.peers))
open Cmdliner
let term =
let print = Arg.(value & flag & info ["print"] ~doc:"print info") in
let title= Arg.(value & opt string "" & info ["t"; "title"]
~docv:"string" ~doc:"Title for index") in
let auth = Arg.(value & opt string "" & info ["a"; "authors"]
~docv:"comma-separated names" ~doc:"Index authors") in
let locs = Arg.(value & opt string "" & info ["l"; "locations"]
~docv:"comma-separated URLs" ~doc:"repository URLs") in
let peers= Arg.(value & opt string "" & info ["p"; "peers"]
~docv:"comma-separated URLs" ~doc:"URLs to other known text repositories") in
let dir = Arg.(value & pos 0 string "." & info []
~docv:"directory to index") in
let doc = "Generate an index.pck for texts in a directory" in
Term.(const index $ print $ title $ auth $ locs $ peers $ dir),
Term.info "index" ~doc
~man:[ `S "DESCRIPTION"; `Pre "An index contains:\n
* an info section with: title for the index, the authors, locations (URLs) the texts can be access\n
* listing of texts with: ID, date, title, authors, topics\n
* list of other text repositories (peers)\n\n
MessagePack format. <msgpack.org>" ]