- Timestamp:
- Oct 26, 2022, 7:36:02 PM (2 years ago)
- Location:
- trunk/cli
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/cli/atom.ml
r3 r19 1 let ext = ".atom" 2 1 3 let esc = Converter.Html.esc 2 4 … … 45 47 ^ "</entry>\n" 46 48 47 let feed title archive_id base_url alternate_type texts = 48 let entry, self = match alternate_type with 49 | "text/gemini" -> gmi_entry, base_url^"/gmi.atom" 50 | "text/html" | _ -> htm_entry, base_url^"/feed.atom" in 51 {|<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" xml:base="|} ^ base_url ^ {|"><title>|} 52 ^ title ^ {|</title><link rel="alternate" type="|} ^ alternate_type ^ {|" href="|} 53 ^ base_url ^ {|/" /><link rel="self" type="application/atom+xml" href="|} 54 ^ self ^ {|" /><id>urn:uuid:|} ^ archive_id ^ "</id><updated>" 55 ^ Logarion.Date.now () ^ "</updated>\n" 56 ^ List.fold_left (fun acc t -> acc ^ entry base_url t) "" texts 57 ^ "</feed>" 49 let base_url kv protocol = try 50 let locs = Logarion.Store.KV.find "Locations" kv in 51 let _i = Str.(search_forward (regexp (protocol ^ "://[^;]*")) locs 0) in 52 Str.(matched_string locs) 53 with Not_found -> Printf.eprintf "Missing location for %s" protocol; "" 54 55 let indices alternate_type c = 56 let file name = Logarion.File_store.file (Filename.concat c.Conversion.dir name) in 57 let title = try Logarion.Store.KV.find "Title" c.Conversion.kv with Not_found -> "" in 58 let entry, fname, protocol_regexp = match alternate_type with 59 | "text/gemini" -> gmi_entry, "gmi.atom", "gemini" 60 | "text/html" | _ -> htm_entry, "feed.atom", "https?" 61 in 62 let base_url = base_url c.kv protocol_regexp in 63 let self = Filename.concat base_url fname in 64 file fname @@ 65 {|<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" xml:base="|} ^ base_url ^ {|"><title>|} 66 ^ title ^ {|</title><link rel="alternate" type="|} ^ alternate_type ^ {|" href="|} 67 ^ base_url ^ {|/" /><link rel="self" type="application/atom+xml" href="|} 68 ^ self ^ {|" /><id>urn:uuid:|} ^ c.Conversion.id ^ "</id><updated>" 69 ^ Logarion.Date.now () ^ "</updated>\n" 70 ^ List.fold_left (fun acc t -> acc ^ entry base_url t) "" c.texts 71 ^ "</feed>" 72 73 let converter format = Conversion.{ ext; page = None; indices = Some (indices format) } -
trunk/cli/conversion.ml
r3 r19 10 10 type fn_t = { 11 11 ext: string; 12 page: t -> Logarion.Text.t -> string;13 indices: t -> unit;12 page: (t -> Logarion.Text.t -> string) option; 13 indices: (t -> unit) option; 14 14 } -
trunk/cli/convert.ml
r15 r19 10 10 List.fold_left 11 11 (fun a f -> 12 let dest = dest ^ f.Conversion.ext in 13 if is_older source dest then (File_store.file dest (f.Conversion.page r text); true) else false 14 || a) 12 match f.Conversion.page with None -> false || a 13 | Some page -> 14 let dest = dest ^ f.Conversion.ext in 15 (if is_older source dest then (File_store.file dest (page r text); true) else false) 16 || a) 15 17 false cs 16 18 | x -> Printf.eprintf "Can't convert Content-Type: %s file: %s" x text.Text.title; false 17 19 18 20 let converters types kv = 21 let n = String.split_on_char ',' types in 19 22 let t = [] in 20 let t = if ("htm" = types || "all" = types) then 21 (let htm = Html.init kv in 22 Conversion.{ ext = Html.ext; page = Html.page htm; indices = Html.indices htm })::t 23 else t in 24 let t = if ("gmi" = types || "all" = types) then 25 Conversion.{ ext = Gemini.ext; page = Gemini.page; indices = Gemini.indices}::t else t in 23 let t = if List.(mem "all" n || mem "htm" n) then (Html.converter kv)::t else t in 24 let t = if List.(mem "all" n || mem "atom" n) then (Atom.converter "text/html")::t else t in 25 let t = if List.(mem "all" n || mem "gmi" n) then (Gemini.converter)::t else t in 26 let t = if List.(mem "all" n || mem "gmi-atom" n) then (Atom.converter "text/gemini")::t else t in 26 27 t 27 28 … … 36 37 with Not_found -> Topic_set.roots topics in 37 38 let repo = Conversion.{ repo with topic_roots; topics; texts } in 38 if not noindex then List.iter (fun c -> c.Conversion.indicesrepo) converters;39 if not noindex then List.iter (fun c -> match c.Conversion.indices with None -> () | Some f -> f repo) converters; 39 40 Printf.printf "Converted: %d Indexed: %d\n" count (List.length texts) 40 41 … … 48 49 let kv = let f = Filename.concat dir ".convert.conf" in (* TODO: better place to store convert conf? *) 49 50 if Sys.file_exists f then File_store.of_kv_file f else Store.KV.empty in 50 let kv = if Store.KV.mem "Title" kv then kv 51 else Store.KV.add "Title" info.Header_pack.title kv in 51 let kv = if Store.KV.mem "Title" kv then kv else Store.KV.add "Title" info.Header_pack.title kv in 52 52 let kv = Store.KV.add "Locations" (String.concat ";\n" info.Header_pack.locations) kv in 53 53 let kv = Store.KV.add "Peers" (String.concat ";\n" Header_pack.(to_str_list peers)) kv in -
trunk/cli/gemini.ml
r15 r19 91 91 let index_name = try Store.KV.find "Gemini-index" r.kv with Not_found -> "index.gmi" in 92 92 let title = try Store.KV.find "Title" r.Conversion.kv with Not_found -> "" in 93 94 if index_name <> "" then 95 file index_name (topic_main_index r title r.topic_roots r.texts); 96 93 if index_name <> "" then file index_name (topic_main_index r title r.topic_roots r.texts); 97 94 file "index.date.gmi" (date_index title r.texts); 98 99 95 List.iter 100 96 (fun topic -> file ("index." ^ topic ^ ".gmi") 101 97 (topic_sub_index title r.topics topic r.texts)) 102 r.topic_roots ;98 r.topic_roots 103 99 104 let base_url = try 105 let _i = Str.(search_forward (regexp "gemini?://[^;]*") (Store.KV.find "Locations" r.kv) 0) in 106 Str.(matched_string (Store.KV.find "Locations" r.kv)) 107 with Not_found -> prerr_endline "Missing location for Gemini"; "" in 108 file "gmi.atom" (Atom.feed title r.id base_url "text/gemini" r.texts) 100 let converter = Conversion.{ ext; page = Some page; indices = Some indices} -
trunk/cli/html.ml
r18 r19 15 15 { templates = { header; footer} } 16 16 17 let wrap c htm text_title body =18 let site_title = try Logarion.Store.KV.find "Title" c .Conversion.kv17 let wrap conv htm text_title body = 18 let site_title = try Logarion.Store.KV.find "Title" conv.Conversion.kv 19 19 with Not_found -> "" in 20 20 let replace x = let open Str in … … 58 58 let keywords = str_set "keywords" text in 59 59 let header = 60 let time x = {|<time datetime="|} ^ x ^ {|">|} ^ x ^ "</time>" in 60 let time x = Printf.sprintf {|<time datetime="%s">%s</time>|} 61 (Date.rfc_string x) (Date.pretty_date x) in 61 62 let topic_links x = 62 63 let to_linked t a = … … 67 68 ^ opt_kv "Title:" text.title 68 69 ^ opt_kv "Authors:" authors 69 ^ opt_kv "Date: " (time (Date. (pretty_date @@ listing text.date)))70 ^ opt_kv "Date: " (time (Date.listing text.date)) 70 71 ^ opt_kv "Series: " (str_set "series" text) 71 72 ^ opt_kv "Topics: " (topic_links (set "topics" text)) … … 162 163 ^ listing_index topic_map [topic_root] "" metas) 163 164 164 open Logarion165 165 let indices htm c = 166 166 let file name = Logarion.File_store.file (Filename.concat c.Conversion.dir name) in 167 let index_name = try Store.KV.find "HTM-index" c.Conversion.kv with Not_found -> "index.html" in 168 let title = try Store.KV.find "Title" c.Conversion.kv with Not_found -> "" in 169 170 if index_name <> "" then 171 file index_name (topic_main_index c htm c.topic_roots c.texts); 172 167 let index_name = try Logarion.Store.KV.find "HTM-index" c.Conversion.kv with Not_found -> "index.html" in 168 if index_name <> "" then file index_name (topic_main_index c htm c.topic_roots c.texts); 173 169 file "index.date.htm" (date_index c htm c.texts); 174 175 170 List.iter 176 171 (fun root -> file ("index." ^ root ^ ".htm") (topic_sub_index c htm c.topics root c.texts)) 177 c.topic_roots ;172 c.topic_roots 178 173 179 let base_url = try 180 let locs = Store.KV.find "Locations" c.kv in 181 let _i = Str.(search_forward (regexp "https?://[^;]*") locs 0) in 182 Str.(matched_string locs) 183 with Not_found -> prerr_endline "Missing location for HTTP(S)"; "" in 184 file "feed.atom" (Atom.feed title c.id base_url "text/html" c.texts) 174 let converter kv = 175 let htm = init kv in 176 Conversion.{ ext; page = Some (page htm); indices = Some (indices htm) }
Note:
See TracChangeset
for help on using the changeset viewer.