Changeset 39 in code
- Timestamp:
- Dec 12, 2022, 10:52:55 PM (2 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/cli/conversion.ml
r20 r39 1 1 open Logarion 2 3 module Ref_set = Set.Make(String) 4 module Id_map = Map.Make(String) 5 2 6 type t = { 3 7 id: string; … … 6 10 topic_roots: string list; 7 11 topics: (String_set.t * String_set.t) Topic_set.Map.t; 12 references: Ref_set.t Id_map.t; 8 13 texts: Text.t list 9 14 } … … 20 25 topic_roots = []; 21 26 topics = Topic_set.Map.empty; 27 references = Id_map.empty; 22 28 texts = [] 23 29 } -
trunk/cli/convert.ml
r21 r39 27 27 t 28 28 29 let acc_ref id t a = 30 Conversion.Id_map.update t (function 31 | Some s -> Some (Conversion.Ref_set.add id s) 32 | None -> Some (Conversion.Ref_set.singleton id) 33 ) a 34 35 let fold_refs text refs = String_set.fold (acc_ref text.Text.id) (Text.set "references" text) refs 36 29 37 let directory converters noindex repo = 30 let fn (ts,ls,acc) ((elt,_) as r) = 31 (Topic_set.to_map ts (Text.set "topics" elt)), elt::ls, 38 let fn (ts,refs,ls,acc) ((elt,_) as r) = 39 Topic_set.to_map ts (Text.set "topics" elt), 40 fold_refs elt refs, 41 elt::ls, 32 42 if convert converters repo r then acc+1 else acc in 33 let topics, texts, count =34 File_store.(fold ~dir:repo.Conversion.dir ~order:newest fn (Topic_set.Map.empty, [],0)) in43 let topics, references, texts, count = 44 File_store.(fold ~dir:repo.Conversion.dir ~order:newest fn (Topic_set.Map.empty, Conversion.Id_map.empty, [], 0)) in 35 45 let topic_roots = try List.rev @@ String_set.list_of_csv (Store.KV.find "Topics" repo.kv) 36 46 with Not_found -> Topic_set.roots topics in 37 let repo = Conversion.{ repo with topic_roots; topics; texts } in47 let repo = Conversion.{ repo with topic_roots; topics; references; texts } in 38 48 if not noindex then List.iter (fun c -> match c.Conversion.indices with None -> () | Some f -> f repo) converters; 39 49 Printf.printf "Converted: %d Indexed: %d\n" count (List.length texts) … … 63 73 | Error s -> prerr_endline s 64 74 | Ok text -> 65 let repo = { (Conversion.empty ()) with dir = ""; kv = load_kv "" } in 75 let dir = "." in 76 let references = File_store.(fold ~dir ~order:newest 77 (fun refs (elt, _) -> fold_refs elt refs) Conversion.Id_map.empty) in 78 Conversion.Id_map.iter 79 (fun k v -> Conversion.Ref_set.iter (fun e -> Printf.eprintf "%s %s\n" k e) v) 80 references; 81 let repo = { (Conversion.empty ()) with dir; kv = load_kv ""; references } in 66 82 ignore @@ convert (converters types repo.kv) repo (text, [path]) 67 83 ) -
trunk/cli/html.ml
r38 r39 26 26 with Not_found -> if Sys.file_exists (Filename.concat conv.Conversion.dir "feed.atom") 27 27 then "feed.atom" else "" in 28 let header = match htm.templates.header with 28 let header = match htm.templates.header with 29 29 | Some x -> replace x 30 30 | None -> Printf.(sprintf "<header><a href='.'>%s</a>%s</header>" site_title … … 47 47 module HtmlConverter = struct 48 48 include Converter.Html 49 let uid_uri u a = Printf.sprintf "%s<a href='%s%s'>%s</a>" a u ext u 49 50 let angled_uri u a = 50 51 if try String.sub u 0 10 = "urn:txtid:" with Invalid_argument _ -> false … … 70 71 String_set.fold to_linked x "" in 71 72 let ref_links x = 72 let link l = HtmlConverter. angled_uri (String.(sub l 1 (length l-2)))"" in73 let link l = HtmlConverter.uid_uri l "" in 73 74 String_set.fold (fun r a -> sep_append a (link r)) x "" 74 75 in … … 80 81 ^ opt_kv "Topics:" (topic_links (set "topics" text)) 81 82 ^ opt_kv "Id:" text.id 82 ^ opt_kv "References:" (ref_links (set "references" text)) 83 ^ opt_kv "Refers:" (ref_links (set "references" text)) 84 ^ opt_kv "Referred by:" (try 85 ref_links (Conversion.Id_map.find text.id conversion.Conversion.references) 86 with Not_found -> "") 83 87 ^ {|</dl></header><pre style="white-space:pre-wrap">|} in 84 88 wrap conversion htm text.title ((T.of_string text.body header) ^ "</pre></article>") -
trunk/lib/id.ml
r3 r39 13 13 14 14 type t = string 15 let compare = String.compare 15 let compare = String.compare 16 16 let nil = "" 17 17 -
trunk/lib/string_set.ml
r3 r39 2 2 3 3 let list_of_csv x = Str.(split (regexp " *, *")) (String.trim x) 4 let of_string x = of_list (list_of_csv x) 4 let list_of_ssv x = Str.(split (regexp " +")) (String.trim x) 5 6 let of_string ?(separator=list_of_csv) x = of_list (separator x) 7 let of_csv_string x = of_string ~separator:list_of_csv x 8 let of_ssv_string x = of_string ~separator:list_of_ssv x 9 5 10 let to_string ?(pre="") ?(sep=", ") s = 6 11 let j a x = match a, x with "", _ -> x | _, "" -> a | _ -> a ^ sep ^ x in -
trunk/lib/text.ml
r38 r39 26 26 let set key m = try String_map.find (String.lowercase_ascii key) m.stringset_map with Not_found -> String_set.empty 27 27 let str_set key m = String_set.to_string @@ set key m 28 let with_str_set m key str = { m with29 stringset_map = String_map.add (String.lowercase_ascii key) ( String_set.of_stringstr) m.stringset_map28 let with_str_set ?(separator=String_set.of_csv_string) m key str = { m with 29 stringset_map = String_map.add (String.lowercase_ascii key) (separator str) m.stringset_map 30 30 } 31 31 … … 40 40 | "date" -> { x with date = Date.{ x.date with created = Date.of_string v }} 41 41 | "date-edited"-> { x with date = Date.{ x.date with edited = Date.of_string v }} 42 | "licences" | "topics" | "keywords" | "references" | "series" as k -> with_str_set x k v 42 | "licences" | "topics" | "keywords" | "series" as k -> with_str_set x k v 43 | "references" -> with_str_set 44 ~separator:(fun x -> String_set.map (fun x -> String.(sub x 1 (length x-2))) 45 (String_set.of_ssv_string x)) 46 x k v 43 47 | k -> { x with string_map = String_map.add k (trim v) x.string_map } 44 48 -
trunk/readme.txt
r33 r39 1 1 ID: ka4wtj 2 2 Title: Logarion 3 References: <3sqd84> <hvhhwf> <h1a9tg> 3 4 4 5 ## Guides 5 6 6 - Exploring & pulling texts from Logarion repositories. <urn:txtid:3sqd84> 7 - Creating texts & publishing on the net. <urn:txtid:hvhhwf> 8 - Txt uniform resource names <urn:txtid:h1a9tg> 7 Exploring & pulling texts from Logarion repositories. 8 <urn:txtid:3sqd84> 9 10 Creating texts & publishing on the net. 11 <urn:txtid:hvhhwf> 12 13 Txt uniform resource names 14 <urn:txtid:h1a9tg> 9 15 10 16 ## Contacts 11 17 12 - Mailing list (anonymous) <https://lists.tildeverse.org/postorius/lists/logarion.lists.tildeverse.org/> 📧 13 - <irc://tilde.chat/#logarion> 💬 18 Mailing list (anonymous): 📧 19 <https://lists.tildeverse.org/postorius/lists/logarion.lists.tildeverse.org/> 20 21 Irc: 💬 22 <irc://tilde.chat/#logarion> 14 23 15 24 -
trunk/txt/hvhhwf.txt
r35 r39 6 6 # New 7 7 8 To create new text files, use `txt new "<My title>"` where <my title> is the initial title you wish the text to have. It's important to enclose the title with quotation marks if it contains spaces. The command will return the filename of the new text. The filename starts with a part of the ID and the title of the text. Use the file name to open it with your text editor. 8 To create new text files, use "txt new". For example: 9 txt new "Hello world" 10 It's important to enclose the title with quotation marks if it contains spaces. The command will return the filename of the new text. The filename starts with a part of the ID and the title of the text. Use the file name to open it with your text editor. 9 11 10 Alternatively add the -i flag, `txt new -i "<My title>"` to have the text editor launched to edit the newly created file. 12 Alternatively add the -i flag to have the text editor launched to edit the newly created file: 13 txt new -i "Some title" 11 14 12 15 Text files will be stored in either: … … 16 19 17 20 The simplest approach is to put all texts in the local-share directory and override that on occasion with 18 `txtdir`. For example:19 txtdir=. txt new "Hello world"21 $txtdir. For example: 22 txtdir=. txt new "Hello world" 20 23 21 24 22 25 # Publish 23 26 24 Texts created with "new" are treated as personal until published. To publish a text, use `txt publish <id>` where <id>is the text of the text to publish. Publication requires a `txt.conf` file which must exist in either:27 Texts created with "new" are treated as personal until published. To publish a text, use `txt publish [id]` where [id] is the text of the text to publish. Publication requires a `txt.conf` file which must exist in either: 25 28 1. The current working directory 26 29 2. $HOME/.config/txt/txt.conf 27 30 28 With the above in place, `txt publish <id>` will add the text file with <id>in the publication-directory and reproduce the `index.pck` in that directory. If Pubdir is not defined in `txt.conf` then the environmental variable `txtpubdir` is used. If that is also undefined, the current working directory is used as a publication directory.31 With the above in place, `txt publish [id]` will add the text file with [id] in the publication-directory and reproduce the `index.pck` in that directory. If Pubdir is not defined in `txt.conf` then the environmental variable `txtpubdir` is used. If that is also undefined, the current working directory is used as a publication directory. 29 32 30 Logarion is protocol agnostic, so publish looks for the existence of directories to copy the files, ready for publication. At the time of writing the three directories are `public_html`, `public_gemini` and `public_gopher`. For each of these directories, `txt publish <id>` will copy the text file, revise the `index.pck` and also convert produce converted files, such .htm for public_html.33 Logarion is protocol agnostic, so publish looks for the existence of directories to copy the files, ready for publication. At the time of writing the three directories are `public_html`, `public_gemini` and `public_gopher`. For each of these directories, `txt publish [id]` will copy the text file, revise the `index.pck` and also convert produce converted files, such .htm for public_html. 31 34 32 35 ## txt.conf keys 33 36 34 Id: A random, unique, alphanumeric string for distinguishing the repository (atleast 6 characters of Crockford's Base32 recommended) 35 Title: a human-friendly title 36 Authors: comma seperated list of names and, optionally, addresses 37 Topics: topics the repository aims to cover 38 Locations: list of URIs the repositories can be accessed 39 Peers: list of peer URIs 40 Pubdir: (optional) the directory that contains publication subdirectories 37 Id: 38 A random, unique, alphanumeric string for distinguishing the repository (atleast 6 characters of Crockford's Base32 recommended) 39 40 Title: 41 a human-friendly title 42 43 Authors: 44 comma seperated list of names and, optionally, addresses 45 46 Topics: 47 topics the repository aims to cover 48 49 Locations: 50 list of URIs the repositories can be accessed 51 52 Peers: 53 list of peer URIs 54 55 Pubdir: 56 (optional) the directory that contains publication subdirectories 41 57 42 58 … … 45 61 There are some special settings for HTML publication: 46 62 47 HTM-style: path to a CSS style. It will be inserted in every .htm file. To link to a single CSS consider using `@import` 48 HTM-header: path to a file, inserted in every .htm file, right after the <body> tag 49 HTM-footer: path to a file, inserted in every .htm file, right before the </body> tag 50 HTM-index: if defined, determines the filename for the index files. Left undefined, defaults to `index.html` 51 HTM-feed: if defined, this will overrite the feed URI used in HTML files. If left undefined the default `feed.atom` is used 63 HTM-style: 64 path to a CSS style. It will be inserted in every .htm file. To link to a single CSS consider using `@import` 65 66 HTM-header: 67 path to a file, inserted in every .htm file, right after the body tag 68 69 HTM-footer: 70 path to a file, inserted in every .htm file, right before the body tag 71 72 HTM-index: 73 if defined, determines the filename for the index files. Left undefined, defaults to `index.html` 74 75 HTM-feed: 76 if defined, this will overrite the feed URI used in HTML files. If left undefined the default `feed.atom` is used
Note:
See TracChangeset
for help on using the changeset viewer.