From 2e0e9d1047cb9ef0abca88657997c7fef4a9f670 Mon Sep 17 00:00:00 2001 From: Stavros Polymenis Date: Thu, 12 Jan 2017 23:19:09 +0000 Subject: [PATCH] fix for Sys_error exception and refactoring --- src/html.ml | 2 +- src/logarion.ml | 4 ++-- src/template.ml | 2 +- src/web.ml | 10 ++++++---- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/html.ml b/src/html.ml index d2ca974..57ab981 100644 --- a/src/html.ml +++ b/src/html.ml @@ -54,7 +54,7 @@ let of_entries ?(header_tpl=None) ?(listing_tpl=None) ?(entry_tpl=None) blog_url (match listing_tpl with | Some (Template.Listing s) -> Unsafe.data Template.(fold_index ~entry_tpl lgrn s) | None -> - let entries = Logarion.(Archive.of_repo lgrn.Configuration.repository |> latest_listed_entries) in + let entries = Logarion.Archive.(of_repo lgrn.Logarion.Configuration.repository |> latest_listed) in (div [ h2 [pcdata "Articles"]; ul (List.map article_link entries); ])) |> to_string diff --git a/src/logarion.ml b/src/logarion.ml index 686c737..fa715a7 100644 --- a/src/logarion.ml +++ b/src/logarion.ml @@ -127,9 +127,9 @@ module Archive = struct in let unique_topics ts x = unique_entry ts Entry.(x.meta.topics) in List.fold_left unique_topics [] archive -end -let latest_listed_entries es = es |> Archive.listed |> Archive.latest + let latest_listed entries = entries |> listed |> latest +end let latest_entry config fragment = let repo = Configuration.(config.repository) in diff --git a/src/template.ml b/src/template.ml index b25e485..01a7620 100644 --- a/src/template.ml +++ b/src/template.ml @@ -80,7 +80,7 @@ let fold_index ?(entry_tpl=None) lgrn = let entry = match entry_tpl with Some (Listing_entry e) -> fold_entry e | None -> simple in let escaped e = match e with | "recent_texts_listing" -> - let entries = Logarion.(Archive.of_repo lgrn.Configuration.repository |> latest_listed_entries) in + let entries = Logarion.Archive.(of_repo lgrn.Logarion.Configuration.repository |> latest_listed) in (ListLabels.fold_left ~init:("" | "topics" -> diff --git a/src/web.ml b/src/web.ml index 4c0d5b7..8c94759 100644 --- a/src/web.ml +++ b/src/web.ml @@ -76,9 +76,11 @@ let () = and (>|=) = Lwt.(>|=) in let module L = Logarion in let ymd f = - L.Entry.of_file f - |> (fun entry -> if Ymd.(CategorySet.categorised [Category.Published]) entry.L.Entry.meta.Ymd.categories - then entry else unpublished_entry) + try + L.Entry.of_file f + |> (fun entry -> if Ymd.(CategorySet.categorised [Category.Published]) entry.L.Entry.meta.Ymd.categories + then entry else unpublished_entry) + with Sys_error _ -> unpublished_entry in let ymdpath title = Lwt.return @@ Logarion.title_path lgrn.L.Configuration.repository title in let ret_param name req = Lwt.return (param req name) in @@ -100,6 +102,6 @@ let () = |> get "/new" (fun _ -> Lwt.return (Ymd.blank_ymd ()) >|= form_of_ymd >>= html_response) |> get "/text/:ttl" (fun req -> ret_param "ttl" req >>= ymdpath >|= ymd >|= L.Entry.to_ymd >|= page_of_ymd >>= html_response) |> get "/!/:ttl" (fun req -> ret_param "ttl" req >|= L.latest_entry lgrn >|= entry_option >|= L.Entry.to_ymd >|= page_of_ymd >>= html_response) - |> get "/feed.atom" (fun _ -> Lwt.return L.Archive.(of_repo ~bodies:true repo) >|= L.latest_listed_entries >|= List.map L.Entry.to_ymd >|= Atom.feed webcfg.Configuration.url lgrn >>= html_response) + |> get "/feed.atom" (fun _ -> Lwt.return L.Archive.(of_repo ~bodies:true repo) >|= L.Archive.latest_listed >|= List.map L.Entry.to_ymd >|= Atom.feed webcfg.Configuration.url lgrn >>= html_response) |> get "/" (fun _ -> Lwt.return list_of_ymds >>= html_response) |> App.run_command