added article templating
This commit is contained in:
parent
0e29b9d65e
commit
c85337ea5b
21
src/html.ml
21
src/html.ml
@ -8,19 +8,22 @@ let logarion_head ?(style="/style.css") t =
|
||||
meta ~a:[a_charset "utf-8"] ();
|
||||
]
|
||||
|
||||
let of_ymd ymd =
|
||||
let of_ymd ?text_tpl:(tpl=None) ymd =
|
||||
let ymd_title = Ymd.(ymd.meta.title) in
|
||||
let ymd_body = Omd.to_html (Omd.of_string Ymd.(ymd.body)) in
|
||||
html (logarion_head ymd_title)
|
||||
(body [
|
||||
header [
|
||||
h1 [Unsafe.data ymd_title];
|
||||
details
|
||||
(summary [Unsafe.data Ymd.(ymd.meta.abstract)])
|
||||
[time ~a:[a_datetime (Ymd.(rfc_string_of ymd.meta.date.published))] []];
|
||||
];
|
||||
Unsafe.data ymd_body;
|
||||
footer [p []];
|
||||
match tpl with
|
||||
| Some s -> Unsafe.data Template.(of_string s |> fold_text ymd)
|
||||
| None ->
|
||||
header [
|
||||
h1 [Unsafe.data ymd_title];
|
||||
details
|
||||
(summary [Unsafe.data Ymd.(ymd.meta.abstract)])
|
||||
[time ~a:[a_datetime (Ymd.(rfc_string_of ymd.meta.date.published))] []];
|
||||
];
|
||||
Unsafe.data ymd_body;
|
||||
footer [p []];
|
||||
])
|
||||
|> to_string
|
||||
|
||||
|
@ -16,10 +16,17 @@ let concat l = String.concat "" l
|
||||
|
||||
let fold_text ymd =
|
||||
let escaped e = match e with
|
||||
| "title" -> meta.title
|
||||
| "abstract" -> meta.abstract
|
||||
| "authors" -> meta.authors
|
||||
| "text" ->
|
||||
| "title" -> ymd.meta.title
|
||||
| "abstract" -> ymd.meta.abstract
|
||||
| "author_name" -> ymd.meta.author.name
|
||||
| "author_email" -> ymd.meta.author.email
|
||||
| "date_edited" -> rfc_string_of ymd.meta.date.edited
|
||||
| "published" -> rfc_string_of ymd.meta.date.published;
|
||||
| "topics" -> String.concat ", " ymd.meta.topics;
|
||||
| "categories" -> String.concat ", " ymd.meta.categories;
|
||||
| "keywords" -> String.concat ", " ymd.meta.keywords;
|
||||
| "series" -> String.concat ", " ymd.meta.series;
|
||||
| "body" -> ymd.body
|
||||
| _ -> prerr_endline ("unknown tag: " ^ e); "" in
|
||||
Mustache.fold ~string ~section ~escaped ~unescaped ~partial ~comment ~concat
|
||||
|
||||
@ -27,7 +34,8 @@ let fold_entry (file, meta) =
|
||||
let escaped e = match e with
|
||||
| "title" -> meta.title
|
||||
| "abstract" -> meta.abstract
|
||||
| "authors" -> meta.authors
|
||||
| "author_name" -> meta.author.name
|
||||
| "author_email" -> meta.author.email
|
||||
| _ -> prerr_endline ("unknown tag: " ^ e); "" in
|
||||
Mustache.fold ~string ~section ~escaped ~unescaped ~partial ~comment ~concat
|
||||
|
||||
|
@ -22,12 +22,13 @@ let () =
|
||||
let module L = Logarion in
|
||||
let ymd f = L.of_file f in
|
||||
let ret_param name req = return (param req name) in
|
||||
let listing_tpl = Some (Logarion.load_file "index.mustache") in
|
||||
let listing_tpl = Some (Logarion.load_file "share/index.mustache") in
|
||||
let text_tpl = Some (Logarion.load_file "share/text.mustache") in
|
||||
App.empty
|
||||
|> post "/post" (fun req -> ymd_of_req req >>= fun ymd -> L.to_file ymd >>= fun () -> html_response (Html.of_ymd ymd))
|
||||
|> get "/edit/:ttl" (fun r -> ret_param "ttl" r >>= ymdpath >|= ymd >|= Html.form >>= html_response)
|
||||
|> get "/new" (fun _ -> return Ymd.blank_ymd >|= Html.form >>= html_response)
|
||||
|> get "/text/:ttl" (fun req -> ret_param "ttl" req >>= ymdpath >|= ymd >|= Html.of_ymd >>= html_response)
|
||||
|> get "/text/:ttl" (fun req -> ret_param "ttl" req >>= ymdpath >|= ymd >|= Html.of_ymd ~text_tpl >>= html_response)
|
||||
|> get "/!/:ttl" (fun req -> ret_param "ttl" req >|= L.latest_file_meta_pair >|= ymd_or_error >|= Html.of_ymd >>= html_response)
|
||||
|> get "/style.css" (fun _ -> return "ymd/style.css" >|= L.load_file >>= string_response)
|
||||
|> get "/" (fun _ -> return (L.file_meta_pairs ()) >|= Html.of_file_meta_pairs ~listing_tpl >>= html_response)
|
||||
|
Loading…
x
Reference in New Issue
Block a user