Support References field

git-svn-id: file:///srv/svn/repo/kosuzu/trunk@38 eb64cd80-c68d-6f47-b6a3-0ada418499da
This commit is contained in:
fox
2022-12-04 19:18:52 +00:00
parent d07aae3a35
commit e6452a861d
3 changed files with 14 additions and 6 deletions

View File

@@ -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>")