improvements on list of titled files

This commit is contained in:
Stavros Polymenis 2016-09-20 23:25:51 +01:00
parent bdd113e43e
commit 1078a2dd2f
3 changed files with 7 additions and 9 deletions

View File

@ -22,8 +22,8 @@ let of_ymd ymd =
])
|> Format.asprintf "%a" (Tyxml.Html.pp ())
let of_titles titles =
let link_item x = li [a ~a:[a_href ("/" ^ x)] [Unsafe.data x]] in
let of_titled_files titles =
let link_item (y,t) = li [a ~a:[a_href ("/" ^ Filename.chop_extension y)] [Unsafe.data t]] in
html (logarion_head "Homepage")
(body [
header [ h1 [pcdata "Homepage"] ];

View File

@ -118,11 +118,9 @@ let to_file ymd =
Printf.fprintf oc "%s" (to_string ymd);
close_out oc
let titles () =
let titled_files () =
let files = Array.to_list @@ Sys.readdir "ymd/" in
let ymds = List.fold_left
(fun a e -> if BatString.ends_with e ".ymd" then List.cons e a else a)
[]
files in
let t y = (of_file ("ymd/" ^ y)).meta.title in
let ymd_list a e = if BatString.ends_with e ".ymd" then List.cons e a else a in
let ymds = List.fold_left ymd_list [] files in
let t y = (y, (of_file ("ymd/" ^ y)).meta.title) in
List.map t ymds

View File

@ -57,7 +57,7 @@ let process_form =
end
let print_toc =
get "/" begin fun req -> `Html (Html.of_titles (Logarion.titles ())) |> respond' end
get "/" begin fun req -> `Html (Html.of_titled_files (Logarion.titled_files ())) |> respond' end
let _ =
App.empty