- Removed 'txt init'
Format - New B32 ID Index - New option: txt index --print - Move scheme to peers - Replace peer.*.conf files with index packed locations Instead of adding a URL to peers.*.conf, run `txt pull <url>` Conversion - Rewritten converters - txt-convert looks for a .convert.conf containing `key: value` lines. - Specifiable topic-roots from .convert.conf. - Added `Topics:` key, with comma seperated topics. If set only those topics will appear in the main index and used as topic roots. Other topics will have sub-indices generated, but won't be listed in the main index. - HTML converter header & footer options - HTML-index renamed to HTM-index Internal - Change types: uuid:Uuid -> id:string - File_store merges identical texts - Use peer ID for store path, store peers' texts in .local/share/texts - Simple URN resolution for converter Continue to next feed if parsing one fails - Phasing-out Archive, replaced by improved packs - Eliminate Bos, Cohttp, lwt, uri, tls, Re, Ptime, dependencies - Lock version for Cmdliner, fix dune-project - Optional resursive store - Improve header_pack - Fix recursive mkdir git-svn-id: file:///srv/svn/repo/kosuzu/trunk@3 eb64cd80-c68d-6f47-b6a3-0ada418499da
This commit is contained in:
100
cli/html.ml
100
cli/html.ml
@@ -1,26 +1,57 @@
|
||||
let wrap (title:string) (subtitle:string) body =
|
||||
{|<!DOCTYPE HTML>|}
|
||||
^ {|<html><head><title>|}
|
||||
^ subtitle ^ " | " ^ title
|
||||
^ {|</title><link rel="stylesheet" href="main.css">|}
|
||||
^ {|<link rel="alternate" href="feed.atom" type="application/atom+xml">|}
|
||||
^ {|<meta charset="utf-8"/>|}
|
||||
^ {|<meta name="viewport" content="width=device-width, initial-scale=1.0">|}
|
||||
^ {|</head><body><header><a href=".">|} ^ title
|
||||
^ {|</a> <nav><a href="feed.atom" id="feed">feed</a></nav></header>|} ^ body
|
||||
^ "</body></html>"
|
||||
type templates_t = { header: string option; footer: string option }
|
||||
type t = { templates : templates_t }
|
||||
|
||||
let ext = ".htm"
|
||||
let empty_templates = { header = None; footer = None }
|
||||
let default_opts = { templates = empty_templates }
|
||||
|
||||
let init kv =
|
||||
let open Logarion in
|
||||
let header = match Store.KV.find "HTM-header" kv with
|
||||
| fname -> Some (File_store.to_string fname)
|
||||
| exception Not_found -> None in
|
||||
let footer = match Store.KV.find "HTM-footer" kv with
|
||||
| fname -> Some (File_store.to_string fname)
|
||||
| exception Not_found -> None in
|
||||
{ templates = { header; footer} }
|
||||
|
||||
let wrap c htm text_title body =
|
||||
let site_title = try Logarion.Store.KV.find "Title" c.Conversion.kv
|
||||
with Not_found -> "" in
|
||||
let replace x = let open Str in
|
||||
global_replace (regexp "{{archive-title}}") site_title x
|
||||
|> global_replace (regexp "{{text-title}}") text_title
|
||||
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>"
|
||||
in
|
||||
let footer = match htm.templates.footer with None -> "" | Some x -> replace x in
|
||||
"<!DOCTYPE HTML><html><head><title>" ^ text_title ^ " • " ^ site_title ^ "</title>\n\
|
||||
<link rel='stylesheet' href='main.css'>\
|
||||
<link rel='alternate' href='feed.atom' type='application/atom+xml'>\
|
||||
<meta charset='utf-8'/><meta name='viewport' content='width=device-width, initial-scale=1.0'>\
|
||||
</head><body>\n" ^ header ^ body ^ footer ^ "</body></html>"
|
||||
|
||||
let topic_link root topic =
|
||||
let replaced_space = String.map (function ' '->'+' | x->x) in
|
||||
{|<a href="index.|} ^ root ^ {|.htm#|} ^ replaced_space topic ^ {|">|}
|
||||
"<a href='index." ^ replaced_space root ^ ".htm#" ^ replaced_space topic ^ "'>"
|
||||
^ String.capitalize_ascii topic ^ "</a>"
|
||||
|
||||
let page archive_title text =
|
||||
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
|
||||
end
|
||||
|
||||
let page htm conversion text =
|
||||
let open Logarion in
|
||||
let open Text in
|
||||
let module T = Parsers.Plain_text.Make (Converter.Html) in
|
||||
let module T = Parsers.Plain_text.Make (HtmlConverter) in
|
||||
let sep_append ?(sep=", ") a x = match a,x with "",_ -> x | _, "" -> a | _ -> a ^ sep ^ x in
|
||||
let opt_kv key value = if String.length value > 0 then "<dt>" ^ key ^ "<dd>" ^ value else "" in
|
||||
let opt_kv key value = if String.length value > 0
|
||||
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
|
||||
@@ -38,9 +69,9 @@ let page archive_title text =
|
||||
^ opt_kv "Series: " (str_set "series" text)
|
||||
^ opt_kv "Topics: " (topic_links (set "topics" text))
|
||||
^ opt_kv "Keywords: " keywords
|
||||
^ opt_kv "Id: " (Id.to_string text.uuid)
|
||||
^ opt_kv "Id: " text.id
|
||||
^ {|</dl></header><pre style="white-space:pre-wrap">|} in
|
||||
wrap archive_title text.title ((T.of_string text.body header) ^ "</pre></article>")
|
||||
wrap conversion htm text.title ((T.of_string text.body header) ^ "</pre></article>")
|
||||
|
||||
let to_dated_links ?(limit) meta_list =
|
||||
let meta_list = match limit with
|
||||
@@ -57,10 +88,10 @@ let to_dated_links ?(limit) meta_list =
|
||||
^ {|<a href="|} ^ Logarion.Text.short_id m ^ {|.htm">|} ^ m.Logarion.Text.title ^ "</a><br>")
|
||||
"" meta_list
|
||||
|
||||
let date_index ?(limit) title meta_list =
|
||||
let date_index ?(limit) conv htm meta_list =
|
||||
match limit with
|
||||
| Some limit -> wrap title "Index" (to_dated_links ~limit meta_list)
|
||||
| None -> wrap title "Index" (to_dated_links meta_list)
|
||||
| Some limit -> wrap conv htm "Index" (to_dated_links ~limit meta_list)
|
||||
| None -> wrap conv htm "Index" (to_dated_links meta_list)
|
||||
|
||||
let fold_topic_roots topic_roots =
|
||||
let list_item root t = "<li>" ^ topic_link root t in
|
||||
@@ -112,14 +143,35 @@ let listing_index topic_map topic_roots path metas =
|
||||
in
|
||||
"<nav><h1>Texts</h1>" ^ item_group topic_roots ^ "</nav>"
|
||||
|
||||
let topic_main_index title topic_roots metas =
|
||||
wrap title "Topics"
|
||||
let topic_main_index conv htm topic_roots metas =
|
||||
wrap conv htm "Topics"
|
||||
(fold_topic_roots topic_roots
|
||||
^ "<nav><h1>Latest</h1>" ^ to_dated_links ~limit:10 metas
|
||||
^ {|<a href="index.date.htm">More by date</a></nav>|} )
|
||||
|
||||
let topic_sub_index title topic_map topic_root metas =
|
||||
wrap title topic_root
|
||||
let topic_sub_index conv htm topic_map topic_root metas =
|
||||
wrap conv htm topic_root
|
||||
(fold_topics topic_map [topic_root] metas
|
||||
(* ^ {|<a href=".atom" id="feed">|}^ String.capitalize_ascii topic_root ^{| feed </a>|}*)
|
||||
^ listing_index topic_map [topic_root] "" metas)
|
||||
|
||||
open Logarion
|
||||
let indices htm c =
|
||||
let file name = Logarion.File_store.file (Filename.concat c.Conversion.dir name) in
|
||||
let index_name = try Store.KV.find "HTM-index" c.Conversion.kv with Not_found -> "index.html" in
|
||||
let title = try Store.KV.find "Title" c.Conversion.kv with Not_found -> "" in
|
||||
|
||||
if index_name <> "" then
|
||||
file index_name (topic_main_index c htm c.topic_roots c.texts);
|
||||
|
||||
file "index.date.htm" (date_index c htm c.texts);
|
||||
|
||||
List.iter
|
||||
(fun root -> file ("index." ^ root ^ ".htm") (topic_sub_index c htm c.topics root c.texts))
|
||||
c.topic_roots;
|
||||
|
||||
let base_url = try
|
||||
let _i = Str.(search_forward (regexp "https?://[^;]*") (Store.KV.find "Locations" c.kv) 0) in
|
||||
Str.(matched_string (Store.KV.find "Locations" c.kv))
|
||||
with Not_found -> prerr_endline "Missing location for HTTP(S)"; "" in
|
||||
file "feed.atom" (Atom.feed title c.id base_url "text/html" c.texts)
|
||||
|
||||
Reference in New Issue
Block a user