Read References field; referred by listing; test & tidy documentation
git-svn-id: file:///srv/svn/repo/kosuzu/trunk@39 eb64cd80-c68d-6f47-b6a3-0ada418499da
This commit is contained in:
parent
e6452a861d
commit
1547dc4d27
@ -1,10 +1,15 @@
|
||||
open Logarion
|
||||
|
||||
module Ref_set = Set.Make(String)
|
||||
module Id_map = Map.Make(String)
|
||||
|
||||
type t = {
|
||||
id: string;
|
||||
dir: string;
|
||||
kv: string Store.KV.t;
|
||||
topic_roots: string list;
|
||||
topics: (String_set.t * String_set.t) Topic_set.Map.t;
|
||||
references: Ref_set.t Id_map.t;
|
||||
texts: Text.t list
|
||||
}
|
||||
|
||||
@ -19,5 +24,6 @@ let empty () = {
|
||||
kv = Store.KV.empty;
|
||||
topic_roots = [];
|
||||
topics = Topic_set.Map.empty;
|
||||
references = Id_map.empty;
|
||||
texts = []
|
||||
}
|
||||
|
@ -26,15 +26,25 @@ let converters types kv =
|
||||
let t = if List.(mem "all" n || mem "gmi-atom" n) then (Atom.converter "text/gemini")::t else t in
|
||||
t
|
||||
|
||||
let acc_ref id t a =
|
||||
Conversion.Id_map.update t (function
|
||||
| Some s -> Some (Conversion.Ref_set.add id s)
|
||||
| None -> Some (Conversion.Ref_set.singleton id)
|
||||
) a
|
||||
|
||||
let fold_refs text refs = String_set.fold (acc_ref text.Text.id) (Text.set "references" text) refs
|
||||
|
||||
let directory converters noindex repo =
|
||||
let fn (ts,ls,acc) ((elt,_) as r) =
|
||||
(Topic_set.to_map ts (Text.set "topics" elt)), elt::ls,
|
||||
let fn (ts,refs,ls,acc) ((elt,_) as r) =
|
||||
Topic_set.to_map ts (Text.set "topics" elt),
|
||||
fold_refs elt refs,
|
||||
elt::ls,
|
||||
if convert converters repo r then acc+1 else acc in
|
||||
let topics, texts, count =
|
||||
File_store.(fold ~dir:repo.Conversion.dir ~order:newest fn (Topic_set.Map.empty,[],0)) in
|
||||
let topics, references, texts, count =
|
||||
File_store.(fold ~dir:repo.Conversion.dir ~order:newest fn (Topic_set.Map.empty, Conversion.Id_map.empty, [], 0)) in
|
||||
let topic_roots = try List.rev @@ String_set.list_of_csv (Store.KV.find "Topics" repo.kv)
|
||||
with Not_found -> Topic_set.roots topics in
|
||||
let repo = Conversion.{ repo with topic_roots; topics; texts } in
|
||||
let repo = Conversion.{ repo with topic_roots; topics; references; texts } in
|
||||
if not noindex then List.iter (fun c -> match c.Conversion.indices with None -> () | Some f -> f repo) converters;
|
||||
Printf.printf "Converted: %d Indexed: %d\n" count (List.length texts)
|
||||
|
||||
@ -62,7 +72,13 @@ let at_path types noindex path = match path with
|
||||
match File_store.to_text path with
|
||||
| Error s -> prerr_endline s
|
||||
| Ok text ->
|
||||
let repo = { (Conversion.empty ()) with dir = ""; kv = load_kv "" } in
|
||||
let dir = "." in
|
||||
let references = File_store.(fold ~dir ~order:newest
|
||||
(fun refs (elt, _) -> fold_refs elt refs) Conversion.Id_map.empty) in
|
||||
Conversion.Id_map.iter
|
||||
(fun k v -> Conversion.Ref_set.iter (fun e -> Printf.eprintf "%s %s\n" k e) v)
|
||||
references;
|
||||
let repo = { (Conversion.empty ()) with dir; kv = load_kv ""; references } in
|
||||
ignore @@ convert (converters types repo.kv) repo (text, [path])
|
||||
)
|
||||
| path -> Printf.eprintf "Path doesn't exist: %s" path
|
||||
|
10
cli/html.ml
10
cli/html.ml
@ -25,7 +25,7 @@ let wrap conv htm text_title body =
|
||||
let feed = try Logarion.Store.KV.find "HTM-feed" conv.Conversion.kv
|
||||
with Not_found -> if Sys.file_exists (Filename.concat conv.Conversion.dir "feed.atom")
|
||||
then "feed.atom" else "" in
|
||||
let header = match htm.templates.header with
|
||||
let header = match htm.templates.header with
|
||||
| Some x -> replace x
|
||||
| None -> Printf.(sprintf "<header><a href='.'>%s</a>%s</header>" site_title
|
||||
(if feed <> "" then sprintf "<nav><a href='%s' id='feed'>feed</a></nav>" feed else ""))
|
||||
@ -46,6 +46,7 @@ let topic_link root topic =
|
||||
|
||||
module HtmlConverter = struct
|
||||
include Converter.Html
|
||||
let uid_uri u a = Printf.sprintf "%s<a href='%s%s'>%s</a>" a u ext u
|
||||
let angled_uri u a =
|
||||
if try String.sub u 0 10 = "urn:txtid:" with Invalid_argument _ -> false
|
||||
then angled_uri (String.(sub u 10 (length u - 10)) ^ ext) a else angled_uri u a
|
||||
@ -69,7 +70,7 @@ let page htm conversion text =
|
||||
sep_append a (List.fold_left (fun a t -> sep_append ~sep:" > " a (topic_link (List.hd ts) t)) "" ts) in
|
||||
String_set.fold to_linked x "" in
|
||||
let ref_links x =
|
||||
let link l = HtmlConverter.angled_uri (String.(sub l 1 (length l-2))) "" in
|
||||
let link l = HtmlConverter.uid_uri l "" in
|
||||
String_set.fold (fun r a -> sep_append a (link r)) x ""
|
||||
in
|
||||
"<article><header><dl>"
|
||||
@ -79,7 +80,10 @@ let page htm conversion text =
|
||||
^ opt_kv "Series:" (str_set "series" text)
|
||||
^ opt_kv "Topics:" (topic_links (set "topics" text))
|
||||
^ opt_kv "Id:" text.id
|
||||
^ opt_kv "References:" (ref_links (set "references" text))
|
||||
^ opt_kv "Refers:" (ref_links (set "references" text))
|
||||
^ opt_kv "Referred by:" (try
|
||||
ref_links (Conversion.Id_map.find text.id conversion.Conversion.references)
|
||||
with Not_found -> "")
|
||||
^ {|</dl></header><pre style="white-space:pre-wrap">|} in
|
||||
wrap conversion htm text.title ((T.of_string text.body header) ^ "</pre></article>")
|
||||
|
||||
|
@ -12,7 +12,7 @@ let random_state = Random.State.make_self_init
|
||||
(*end*)
|
||||
|
||||
type t = string
|
||||
let compare = String.compare
|
||||
let compare = String.compare
|
||||
let nil = ""
|
||||
|
||||
let short ?(len) id =
|
||||
|
1
lib/reference_set.ml
Normal file
1
lib/reference_set.ml
Normal file
@ -0,0 +1 @@
|
||||
module Map = Map.Make(String)
|
@ -1,7 +1,12 @@
|
||||
include Set.Make(String)
|
||||
|
||||
let list_of_csv x = Str.(split (regexp " *, *")) (String.trim x)
|
||||
let of_string x = of_list (list_of_csv x)
|
||||
let list_of_ssv x = Str.(split (regexp " +")) (String.trim x)
|
||||
|
||||
let of_string ?(separator=list_of_csv) x = of_list (separator x)
|
||||
let of_csv_string x = of_string ~separator:list_of_csv x
|
||||
let of_ssv_string x = of_string ~separator:list_of_ssv x
|
||||
|
||||
let to_string ?(pre="") ?(sep=", ") s =
|
||||
let j a x = match a, x with "", _ -> x | _, "" -> a | _ -> a ^ sep ^ x in
|
||||
fold (fun x acc -> j acc x) s pre
|
||||
|
10
lib/text.ml
10
lib/text.ml
@ -25,8 +25,8 @@ let oldest a b = Date.(compare b.date a.date)
|
||||
let str key m = try String_map.find (String.lowercase_ascii key) m.string_map with Not_found -> ""
|
||||
let set key m = try String_map.find (String.lowercase_ascii key) m.stringset_map with Not_found -> String_set.empty
|
||||
let str_set key m = String_set.to_string @@ set key m
|
||||
let with_str_set m key str = { m with
|
||||
stringset_map = String_map.add (String.lowercase_ascii key) (String_set.of_string str) m.stringset_map
|
||||
let with_str_set ?(separator=String_set.of_csv_string) m key str = { m with
|
||||
stringset_map = String_map.add (String.lowercase_ascii key) (separator str) m.stringset_map
|
||||
}
|
||||
|
||||
let with_kv x (k,v) =
|
||||
@ -39,7 +39,11 @@ let with_kv x (k,v) =
|
||||
| "authors" -> { x with authors = Person.Set.of_string (trim v)}
|
||||
| "date" -> { x with date = Date.{ x.date with created = Date.of_string v }}
|
||||
| "date-edited"-> { x with date = Date.{ x.date with edited = Date.of_string v }}
|
||||
| "licences" | "topics" | "keywords" | "references" | "series" as k -> with_str_set x k v
|
||||
| "licences" | "topics" | "keywords" | "series" as k -> with_str_set x k v
|
||||
| "references" -> with_str_set
|
||||
~separator:(fun x -> String_set.map (fun x -> String.(sub x 1 (length x-2)))
|
||||
(String_set.of_ssv_string x))
|
||||
x k v
|
||||
| k -> { x with string_map = String_map.add k (trim v) x.string_map }
|
||||
|
||||
let kv_of_string line = match Str.(bounded_split (regexp ": *")) line 2 with
|
||||
|
19
readme.txt
19
readme.txt
@ -1,16 +1,25 @@
|
||||
ID: ka4wtj
|
||||
Title: Logarion
|
||||
References: <3sqd84> <hvhhwf> <h1a9tg>
|
||||
|
||||
## Guides
|
||||
|
||||
- Exploring & pulling texts from Logarion repositories. <urn:txtid:3sqd84>
|
||||
- Creating texts & publishing on the net. <urn:txtid:hvhhwf>
|
||||
- Txt uniform resource names <urn:txtid:h1a9tg>
|
||||
Exploring & pulling texts from Logarion repositories.
|
||||
<urn:txtid:3sqd84>
|
||||
|
||||
Creating texts & publishing on the net.
|
||||
<urn:txtid:hvhhwf>
|
||||
|
||||
Txt uniform resource names
|
||||
<urn:txtid:h1a9tg>
|
||||
|
||||
## Contacts
|
||||
|
||||
- Mailing list (anonymous) <https://lists.tildeverse.org/postorius/lists/logarion.lists.tildeverse.org/> 📧
|
||||
- <irc://tilde.chat/#logarion> 💬
|
||||
Mailing list (anonymous): 📧
|
||||
<https://lists.tildeverse.org/postorius/lists/logarion.lists.tildeverse.org/>
|
||||
|
||||
Irc: 💬
|
||||
<irc://tilde.chat/#logarion>
|
||||
|
||||
|
||||
## References
|
||||
|
@ -5,9 +5,12 @@ Authors: orbifx
|
||||
|
||||
# New
|
||||
|
||||
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.
|
||||
To create new text files, use "txt new". For example:
|
||||
txt new "Hello world"
|
||||
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.
|
||||
|
||||
Alternatively add the -i flag, `txt new -i "<My title>"` to have the text editor launched to edit the newly created file.
|
||||
Alternatively add the -i flag to have the text editor launched to edit the newly created file:
|
||||
txt new -i "Some title"
|
||||
|
||||
Text files will be stored in either:
|
||||
1. The directory pointed at by txtdir if defined
|
||||
@ -15,37 +18,59 @@ Text files will be stored in either:
|
||||
3. The current working directory, if all else fails
|
||||
|
||||
The simplest approach is to put all texts in the local-share directory and override that on occasion with
|
||||
`txtdir`. For example:
|
||||
txtdir=. txt new "Hello world"
|
||||
$txtdir. For example:
|
||||
txtdir=. txt new "Hello world"
|
||||
|
||||
|
||||
# Publish
|
||||
|
||||
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:
|
||||
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:
|
||||
1. The current working directory
|
||||
2. $HOME/.config/txt/txt.conf
|
||||
|
||||
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.
|
||||
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.
|
||||
|
||||
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.
|
||||
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.
|
||||
|
||||
## txt.conf keys
|
||||
|
||||
Id: A random, unique, alphanumeric string for distinguishing the repository (atleast 6 characters of Crockford's Base32 recommended)
|
||||
Title: a human-friendly title
|
||||
Authors: comma seperated list of names and, optionally, addresses
|
||||
Topics: topics the repository aims to cover
|
||||
Locations: list of URIs the repositories can be accessed
|
||||
Peers: list of peer URIs
|
||||
Pubdir: (optional) the directory that contains publication subdirectories
|
||||
Id:
|
||||
A random, unique, alphanumeric string for distinguishing the repository (atleast 6 characters of Crockford's Base32 recommended)
|
||||
|
||||
Title:
|
||||
a human-friendly title
|
||||
|
||||
Authors:
|
||||
comma seperated list of names and, optionally, addresses
|
||||
|
||||
Topics:
|
||||
topics the repository aims to cover
|
||||
|
||||
Locations:
|
||||
list of URIs the repositories can be accessed
|
||||
|
||||
Peers:
|
||||
list of peer URIs
|
||||
|
||||
Pubdir:
|
||||
(optional) the directory that contains publication subdirectories
|
||||
|
||||
|
||||
## HTML
|
||||
|
||||
There are some special settings for HTML publication:
|
||||
|
||||
HTM-style: path to a CSS style. It will be inserted in every .htm file. To link to a single CSS consider using `@import`
|
||||
HTM-header: path to a file, inserted in every .htm file, right after the <body> tag
|
||||
HTM-footer: path to a file, inserted in every .htm file, right before the </body> tag
|
||||
HTM-index: if defined, determines the filename for the index files. Left undefined, defaults to `index.html`
|
||||
HTM-feed: if defined, this will overrite the feed URI used in HTML files. If left undefined the default `feed.atom` is used
|
||||
HTM-style:
|
||||
path to a CSS style. It will be inserted in every .htm file. To link to a single CSS consider using `@import`
|
||||
|
||||
HTM-header:
|
||||
path to a file, inserted in every .htm file, right after the body tag
|
||||
|
||||
HTM-footer:
|
||||
path to a file, inserted in every .htm file, right before the body tag
|
||||
|
||||
HTM-index:
|
||||
if defined, determines the filename for the index files. Left undefined, defaults to `index.html`
|
||||
|
||||
HTM-feed:
|
||||
if defined, this will overrite the feed URI used in HTML files. If left undefined the default `feed.atom` is used
|
||||
|
Loading…
x
Reference in New Issue
Block a user