Begin unifying conf and pck code; inline CSS; optional CSS & Atom

git-svn-id: file:///srv/svn/repo/kosuzu/trunk@20 eb64cd80-c68d-6f47-b6a3-0ada418499da
This commit is contained in:
fox
2022-10-30 14:48:02 +00:00
parent 39e9796a6e
commit 0021ae508f
3 changed files with 57 additions and 39 deletions

View File

@@ -1,9 +1,9 @@
type templates_t = { header: string option; footer: string option }
type t = { templates : templates_t }
type t = { templates : templates_t; style : string }
let ext = ".htm"
let empty_templates = { header = None; footer = None }
let default_opts = { templates = empty_templates }
let default_opts = { templates = empty_templates; style = "" }
let init kv =
let open Logarion in
@@ -12,27 +12,31 @@ let init kv =
| exception Not_found -> None in
let header = to_string "HTM-header" kv in
let footer = to_string "HTM-footer" kv in
{ templates = { header; footer} }
let style = match to_string "HTM-style" kv with
| Some s -> Printf.sprintf "<style>%s</style>" s | None -> "" in
{ templates = { header; footer}; style }
let wrap conv htm text_title body =
let site_title = try Logarion.Store.KV.find "Title" conv.Conversion.kv
with Not_found -> "" in
let site_title = try Logarion.Store.KV.find "Title" conv.Conversion.kv with Not_found -> "" in
let replace x = let open Str in
global_replace (regexp "{{archive-title}}") site_title x
global_replace (regexp "{{archive-title}}") site_title x
|> global_replace (regexp "{{text-title}}") text_title
in
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
| Some x -> replace x
| None -> "<header><a href='.'>" ^ site_title ^
"</a><nav><a href='feed.atom' id='feed'>feed</a></nav></header>"
| Some x -> replace x
| None -> Printf.(sprintf "<header><a href='.'>%s</a></header>%s" site_title
(if feed <> "" then sprintf "<nav><a href='%s' id='feed'>feed</a></nav>" feed else ""))
in
let footer = match htm.templates.footer with None -> "" | Some x -> replace x in
Printf.sprintf "<!DOCTYPE HTML><html><head><title>%s%s</title>\n\
<link rel='stylesheet' href='main.css'>\
<link rel='alternate' href='feed.atom' type='application/atom+xml'>\
Printf.sprintf "<!DOCTYPE HTML><html><head><title>%s%s</title>\n%s\n%s\
<meta charset='utf-8'/><meta name='viewport' content='width=device-width, initial-scale=1.0'>\
</head><body>\n%s%s%s</body></html>"
text_title (if site_title <> "" then ("" ^ site_title) else "")
htm.style
(if feed <> "" then Printf.sprintf "<link rel='alternate' href='%s' type='application/atom+xml'>" feed else "")
header body footer
let topic_link root topic =
@@ -150,7 +154,7 @@ let topic_main_index conv htm topic_roots metas =
(fold_topic_roots topic_roots
^ "<nav><h1>Latest</h1><ul>" ^ to_dated_links ~limit:8 metas
^ {|</ul><a href="index.date.htm">More by date</a>|}
^ let peers = Logarion.Store.KV.find "Peers" conv.kv in
^ let peers = try Logarion.Store.KV.find "Peers" conv.kv with Not_found -> "" in
(if peers = "" then "" else
List.fold_left (fun a s -> Printf.sprintf {|%s<li><a href="%s">%s</a>|} a s s) "<h1>Peers</h1><ul>"
(Str.split (Str.regexp ";\n") (Logarion.Store.KV.find "Peers" conv.kv))