Changeset 20 in code for trunk/cli/html.ml


Ignore:
Timestamp:
Oct 30, 2022, 2:48:02 PM (2 years ago)
Author:
fox
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/cli/html.ml

    r19 r20  
    11type templates_t = { header: string option; footer: string option }
    2 type t = { templates : templates_t }
     2type t = { templates : templates_t; style : string }
    33
    44let ext = ".htm"
    55let empty_templates = { header = None; footer = None }
    6 let default_opts = { templates = empty_templates }
     6let default_opts = { templates = empty_templates; style = "" }
    77
    88let init kv =
     
    1313        let header = to_string "HTM-header" kv in
    1414        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 }
    1618
    1719let 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
    2021        let replace x = let open Str in
    21                 global_replace (regexp "{{archive-title}}") site_title x
     22                   global_replace (regexp "{{archive-title}}") site_title x
    2223                |> global_replace (regexp "{{text-title}}") text_title
    2324        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
    2428        let header = match htm.templates.header with
    25         | Some x -> replace x
    26         | 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 ""))
    2832        in
    2933        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\
    3335        <meta charset='utf-8'/><meta name='viewport' content='width=device-width, initial-scale=1.0'>\
    3436        </head><body>\n%s%s%s</body></html>"
    3537        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 "")
    3640        header body footer
    3741
     
    151155                ^ "<nav><h1>Latest</h1><ul>" ^ to_dated_links ~limit:8 metas
    152156                ^ {|</ul><a href="index.date.htm">More by date</a>|}
    153                 ^ let peers = Logarion.Store.KV.find "Peers" conv.kv in
     157                ^ let peers = try Logarion.Store.KV.find "Peers" conv.kv with Not_found -> "" in
    154158                        (if peers = "" then "" else
    155159                                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.