Support References field
This commit is contained in:
parent
aae83be27a
commit
8fe548fd5f
12
cli/html.ml
12
cli/html.ml
|
@ -46,8 +46,9 @@ let topic_link root topic =
|
|||
|
||||
module HtmlConverter = struct
|
||||
include Converter.Html
|
||||
let angled_uri u a = if String.sub u 0 10 <> "urn:txtid:" then
|
||||
angled_uri u a else angled_uri (String.(sub u 10 (length u - 10)) ^ ext) a
|
||||
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
|
||||
end
|
||||
|
||||
let page htm conversion text =
|
||||
|
@ -59,7 +60,6 @@ let page htm conversion text =
|
|||
then "<dt>" ^ key ^ "<dd>" ^ value else "" in
|
||||
(* let author acc auth = sep_append acc Person.(auth.name ^ " ") in*)
|
||||
let authors = Person.Set.to_string text.authors in
|
||||
let keywords = str_set "keywords" text in
|
||||
let header =
|
||||
let time x = Printf.sprintf {|<time datetime="%s">%s</time>|}
|
||||
(Date.rfc_string x) (Date.pretty_date x) in
|
||||
|
@ -68,14 +68,18 @@ let page htm conversion text =
|
|||
let ts = Topic_set.of_string t in
|
||||
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
|
||||
String_set.fold (fun r a -> sep_append a (link r)) x ""
|
||||
in
|
||||
"<article><header><dl>"
|
||||
^ opt_kv "Title:" text.title
|
||||
^ opt_kv "Authors:" authors
|
||||
^ opt_kv "Date:" (time (Date.listing text.date))
|
||||
^ opt_kv "Series:" (str_set "series" text)
|
||||
^ opt_kv "Topics:" (topic_links (set "topics" text))
|
||||
^ opt_kv "Keywords:" keywords
|
||||
^ opt_kv "Id:" text.id
|
||||
^ opt_kv "References:" (ref_links (set "references" text))
|
||||
^ {|</dl></header><pre style="white-space:pre-wrap">|} in
|
||||
wrap conversion htm text.title ((T.of_string text.body header) ^ "</pre></article>")
|
||||
|
||||
|
|
1
header
1
header
|
@ -4,6 +4,7 @@ Topics: Comma seperated list of topic names & phrases
|
|||
Title: A title for the text, ideally less than 70 characters
|
||||
Authors: List of name with optional set of <address>
|
||||
Date-edited: ISO8601, use only when text edited
|
||||
References: list of text ID links
|
||||
|
||||
A blank line must follow the last header field.
|
||||
|
||||
|
|
|
@ -25,7 +25,9 @@ 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 m key str = { m with
|
||||
stringset_map = String_map.add (String.lowercase_ascii key) (String_set.of_string str) m.stringset_map
|
||||
}
|
||||
|
||||
let with_kv x (k,v) =
|
||||
let trim = String.trim in
|
||||
|
@ -37,7 +39,7 @@ 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" | "series" as k -> with_str_set x k v
|
||||
| "licences" | "topics" | "keywords" | "references" | "series" as k -> with_str_set 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
|
||||
|
@ -77,6 +79,7 @@ let to_string x =
|
|||
s "Licences" (str_set "licences" x);
|
||||
s "Topics" (str_set "topics" x);
|
||||
s "Keywords" (str_set "keywords" x);
|
||||
s "References"(str_set "references" x);
|
||||
s "Series" (str_set "series" x);
|
||||
s "Abstract" (str "abstract" x);
|
||||
s "Alias" (str "Alias" x)
|
||||
|
|
Loading…
Reference in New Issue