Changeset 20 in code for trunk/cli/html.ml
- Timestamp:
- Oct 30, 2022, 2:48:02 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/cli/html.ml
r19 r20 1 1 type templates_t = { header: string option; footer: string option } 2 type t = { templates : templates_t }2 type t = { templates : templates_t; style : string } 3 3 4 4 let ext = ".htm" 5 5 let empty_templates = { header = None; footer = None } 6 let default_opts = { templates = empty_templates }6 let default_opts = { templates = empty_templates; style = "" } 7 7 8 8 let init kv = … … 13 13 let header = to_string "HTM-header" kv in 14 14 let footer = to_string "HTM-footer" kv in 15 { templates = { header; footer} } 15 let style = match to_string "HTM-style" kv with 16 | Some s -> Printf.sprintf "<style>%s</style>" s | None -> "" in 17 { templates = { header; footer}; style } 16 18 17 19 let wrap conv htm text_title body = 18 let site_title = try Logarion.Store.KV.find "Title" conv.Conversion.kv 19 with Not_found -> "" in 20 let site_title = try Logarion.Store.KV.find "Title" conv.Conversion.kv with Not_found -> "" in 20 21 let replace x = let open Str in 21 global_replace (regexp "{{archive-title}}") site_title x22 global_replace (regexp "{{archive-title}}") site_title x 22 23 |> global_replace (regexp "{{text-title}}") text_title 23 24 in 25 let feed = try Logarion.Store.KV.find "HTM-feed" conv.Conversion.kv 26 with Not_found -> if Sys.file_exists (Filename.concat conv.Conversion.dir "feed.atom") 27 then "feed.atom" else "" in 24 28 let header = match htm.templates.header with 25 | Some x -> replace x26 | None -> "<header><a href='.'>" ^ site_title ^27 "</a><nav><a href='feed.atom' id='feed'>feed</a></nav></header>"29 | Some x -> replace x 30 | None -> Printf.(sprintf "<header><a href='.'>%s</a></header>%s" site_title 31 (if feed <> "" then sprintf "<nav><a href='%s' id='feed'>feed</a></nav>" feed else "")) 28 32 in 29 33 let footer = match htm.templates.footer with None -> "" | Some x -> replace x in 30 Printf.sprintf "<!DOCTYPE HTML><html><head><title>%s%s</title>\n\ 31 <link rel='stylesheet' href='main.css'>\ 32 <link rel='alternate' href='feed.atom' type='application/atom+xml'>\ 34 Printf.sprintf "<!DOCTYPE HTML><html><head><title>%s%s</title>\n%s\n%s\ 33 35 <meta charset='utf-8'/><meta name='viewport' content='width=device-width, initial-scale=1.0'>\ 34 36 </head><body>\n%s%s%s</body></html>" 35 37 text_title (if site_title <> "" then (" • " ^ site_title) else "") 38 htm.style 39 (if feed <> "" then Printf.sprintf "<link rel='alternate' href='%s' type='application/atom+xml'>" feed else "") 36 40 header body footer 37 41 … … 151 155 ^ "<nav><h1>Latest</h1><ul>" ^ to_dated_links ~limit:8 metas 152 156 ^ {|</ul><a href="index.date.htm">More by date</a>|} 153 ^ let peers = Logarion.Store.KV.find "Peers" conv.kvin157 ^ let peers = try Logarion.Store.KV.find "Peers" conv.kv with Not_found -> "" in 154 158 (if peers = "" then "" else 155 159 List.fold_left (fun a s -> Printf.sprintf {|%s<li><a href="%s">%s</a>|} a s s) "<h1>Peers</h1><ul>"
Note:
See TracChangeset
for help on using the changeset viewer.