Changeset 39 in code


Ignore:
Timestamp:
Dec 12, 2022, 10:52:55 PM (2 years ago)
Author:
fox
Message:

Read References field; referred by listing; test & tidy documentation

Location:
trunk
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/cli/conversion.ml

    r20 r39  
    11open Logarion
     2
     3module Ref_set = Set.Make(String)
     4module Id_map = Map.Make(String)
     5
    26type t = {
    37        id: string;
     
    610        topic_roots: string list;
    711        topics: (String_set.t * String_set.t) Topic_set.Map.t;
     12        references: Ref_set.t Id_map.t;
    813        texts: Text.t list
    914}
     
    2025        topic_roots = [];
    2126        topics = Topic_set.Map.empty;
     27        references = Id_map.empty;
    2228        texts = []
    2329}
  • trunk/cli/convert.ml

    r21 r39  
    2727        t
    2828
     29let 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
     35let fold_refs text refs = String_set.fold (acc_ref text.Text.id) (Text.set "references" text) refs
     36
    2937let 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,
    3242                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)) in
     43        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
    3545        let topic_roots = try List.rev @@ String_set.list_of_csv (Store.KV.find "Topics" repo.kv)
    3646                with Not_found -> Topic_set.roots topics in
    37         let repo = Conversion.{ repo with topic_roots; topics; texts } in
     47        let repo = Conversion.{ repo with topic_roots; topics; references; texts } in
    3848        if not noindex then List.iter (fun c -> match c.Conversion.indices with None -> () | Some f -> f repo) converters;
    3949        Printf.printf "Converted: %d Indexed: %d\n" count (List.length texts)
     
    6373                        | Error s -> prerr_endline s
    6474                        | 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
    6682                                ignore @@ convert (converters types repo.kv) repo (text, [path])
    6783                )
  • trunk/cli/html.ml

    r38 r39  
    2626                with Not_found -> if Sys.file_exists (Filename.concat conv.Conversion.dir "feed.atom")
    2727                        then "feed.atom" else "" in
    28         let header = match htm.templates.header with 
     28        let header = match htm.templates.header with
    2929                | Some x -> replace x
    3030                | None -> Printf.(sprintf "<header><a href='.'>%s</a>%s</header>" site_title
     
    4747module HtmlConverter = struct
    4848        include Converter.Html
     49        let uid_uri u a = Printf.sprintf "%s<a href='%s%s'>%s</a>" a u ext u
    4950        let angled_uri u a =
    5051                if try String.sub u 0 10 = "urn:txtid:" with Invalid_argument _ -> false
     
    7071                        String_set.fold to_linked x "" in
    7172                let ref_links x =
    72                         let link l = HtmlConverter.angled_uri (String.(sub l 1 (length l-2))) "" in
     73                        let link l = HtmlConverter.uid_uri l "" in
    7374                        String_set.fold (fun r a -> sep_append a (link r)) x ""
    7475                in
     
    8081                ^ opt_kv "Topics:" (topic_links (set "topics" text))
    8182                ^ 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 -> "")
    8387                ^ {|</dl></header><pre style="white-space:pre-wrap">|} in
    8488        wrap conversion htm text.title ((T.of_string text.body header) ^ "</pre></article>")
  • trunk/lib/id.ml

    r3 r39  
    1313
    1414type t = string
    15 let compare = String.compare   
     15let compare = String.compare
    1616let nil = ""
    1717
  • trunk/lib/string_set.ml

    r3 r39  
    22
    33let list_of_csv x = Str.(split (regexp " *, *")) (String.trim x)
    4 let of_string x = of_list (list_of_csv x)
     4let list_of_ssv x = Str.(split (regexp " +")) (String.trim x)
     5
     6let of_string ?(separator=list_of_csv) x = of_list (separator x)
     7let of_csv_string x = of_string ~separator:list_of_csv x
     8let of_ssv_string x = of_string ~separator:list_of_ssv x
     9
    510let to_string ?(pre="") ?(sep=", ") s =
    611  let j a x = match a, x with "", _ -> x | _, "" -> a | _ -> a ^ sep ^ x in
  • trunk/lib/text.ml

    r38 r39  
    2626let set key m = try String_map.find (String.lowercase_ascii key) m.stringset_map with Not_found -> String_set.empty
    2727let str_set key m = String_set.to_string @@ set key m
    28 let with_str_set m key str = { m with
    29         stringset_map = String_map.add (String.lowercase_ascii key) (String_set.of_string str) m.stringset_map
     28let 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
    3030        }
    3131
     
    4040        | "date"                         -> { x with date = Date.{ x.date with created   = Date.of_string v }}
    4141        | "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
    4347        | k -> { x with string_map = String_map.add k (trim v) x.string_map }
    4448
  • trunk/readme.txt

    r33 r39  
    11ID: ka4wtj
    22Title: Logarion
     3References: <3sqd84> <hvhhwf> <h1a9tg>
    34
    45## Guides
    56
    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>
     7Exploring & pulling texts from Logarion repositories.
     8<urn:txtid:3sqd84>
     9
     10Creating texts & publishing on the net.
     11<urn:txtid:hvhhwf>
     12
     13Txt uniform resource names
     14<urn:txtid:h1a9tg>
    915
    1016## Contacts
    1117
    12 - Mailing list (anonymous) <https://lists.tildeverse.org/postorius/lists/logarion.lists.tildeverse.org/> 📧
    13 - <irc://tilde.chat/#logarion> 💬
     18Mailing list (anonymous): 📧
     19<https://lists.tildeverse.org/postorius/lists/logarion.lists.tildeverse.org/>
     20
     21Irc: 💬
     22<irc://tilde.chat/#logarion>
    1423
    1524
  • trunk/txt/hvhhwf.txt

    r35 r39  
    66# New
    77
    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.
     8To create new text files, use "txt new". For example:
     9        txt new "Hello world"
     10It'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.
    911
    10 Alternatively add the -i flag, `txt new -i "<My title>"` to have the text editor launched to edit the newly created file.
     12Alternatively add the -i flag to have the text editor launched to edit the newly created file:
     13        txt new -i "Some title"
    1114
    1215Text files will be stored in either:
     
    1619
    1720The 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"
    2023
    2124
    2225# Publish
    2326
    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:
     27Texts 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:
    25281. The current working directory
    26292. $HOME/.config/txt/txt.conf
    2730
    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.
     31With 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.
    2932
    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.
     33Logarion 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.
    3134
    3235## txt.conf keys
    3336
    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
     37Id:
     38        A random, unique, alphanumeric string for distinguishing the repository (atleast 6 characters of Crockford's Base32 recommended)
     39
     40Title:
     41        a human-friendly title
     42
     43Authors:
     44        comma seperated list of names and, optionally, addresses
     45
     46Topics:
     47        topics the repository aims to cover
     48
     49Locations:
     50        list of URIs the repositories can be accessed
     51
     52Peers:
     53        list of peer URIs
     54
     55Pubdir:
     56        (optional) the directory that contains publication subdirectories
    4157
    4258
     
    4561There are some special settings for HTML publication:
    4662
    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
     63HTM-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
     66HTM-header:
     67        path to a file, inserted in every .htm file, right after the body tag
     68
     69HTM-footer:
     70        path to a file, inserted in every .htm file, right before the body tag
     71
     72HTM-index:
     73        if defined, determines the filename for the index files. Left undefined, defaults to `index.html`
     74
     75HTM-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.