simplify access to Ymd module via inclusion in Entry
This commit is contained in:
parent
2f446e0abd
commit
4a21adca7b
@ -39,10 +39,10 @@ let of_ymd ?(header_tpl=None) ?(text_tpl=None) blog_url lgrn ymd =
|
||||
|> to_string
|
||||
|
||||
let article_link entry =
|
||||
let module E = Logarion.Entry in
|
||||
let u = "/text/" ^ Filename.(entry.E.filepath |> basename |> chop_extension) in
|
||||
let open Logarion.Entry in
|
||||
let u = "/text/" ^ Filename.(entry.filepath |> basename |> chop_extension) in
|
||||
li [a ~a:[a_href (uri_of_string u)]
|
||||
[Unsafe.data (Ymd.(entry.E.meta.Ymd.title) ^ Ymd.Date.(pretty_date @@ last entry.E.meta.Ymd.date)) ]
|
||||
[Unsafe.data (entry.meta.title ^ Date.(pretty_date @@ last entry.meta.date)) ]
|
||||
]
|
||||
|
||||
let of_entries ?(header_tpl=None) ?(listing_tpl=None) ?(entry_tpl=None) blog_url lgrn =
|
||||
|
@ -52,6 +52,7 @@ let title_path repo title = titledir repo ^ Ymd.filename_of_title title ^ extens
|
||||
let uuid_path repo ymd = uuiddir repo ^ Ymd.(Id.to_string ymd.meta.uuid) ^ extension
|
||||
|
||||
module Entry = struct
|
||||
include Ymd
|
||||
type t = { filepath : string; meta : Ymd.meta; body : string option }
|
||||
|
||||
let of_file s =
|
||||
@ -99,16 +100,16 @@ module Archive = struct
|
||||
|
||||
let add config ymd =
|
||||
let open Lwt.Infix in
|
||||
Entry.to_file config ymd >>= fun () ->
|
||||
let open Ymd in
|
||||
let open Entry in
|
||||
to_file config ymd >>= fun () ->
|
||||
if not (categorised [Category.Draft] ymd) && ymd.meta.title <> "" then
|
||||
let archive_path = config.Configuration.repository in
|
||||
let archive = of_repo archive_path in
|
||||
let dir = titledir archive_path in
|
||||
begin try
|
||||
let entry = List.find (fun entry -> entry.Entry.meta.uuid = ymd.meta.uuid) archive in
|
||||
if slug_of_filename entry.Entry.filepath <> (Ymd.filename ymd) then
|
||||
let found_filepath = dir ^ entry.Entry.filepath in
|
||||
let entry = List.find (fun entry -> entry.meta.uuid = ymd.meta.uuid) archive in
|
||||
if slug_of_filename entry.filepath <> filename ymd then
|
||||
let found_filepath = dir ^ entry.filepath in
|
||||
Lwt_unix.rename found_filepath (next_semantic_filepath dir ymd);
|
||||
else Lwt.return ()
|
||||
with Not_found ->
|
||||
@ -124,7 +125,7 @@ module Archive = struct
|
||||
if not (List.exists p ts) then unique_entry (List.cons h ts) t else unique_entry ts t
|
||||
| [] -> ts
|
||||
in
|
||||
let unique_topics ts x = unique_entry ts x.Entry.meta.Ymd.topics in
|
||||
let unique_topics ts x = unique_entry ts Entry.(x.meta.topics) in
|
||||
List.fold_left unique_topics [] archive
|
||||
end
|
||||
|
||||
@ -134,11 +135,11 @@ let latest_entry config fragment =
|
||||
let repo = Configuration.(config.repository) in
|
||||
let latest p entry' =
|
||||
let open Entry in
|
||||
if not @@ BatString.exists (entry'.Entry.meta.Ymd.title) fragment then None
|
||||
if not @@ BatString.exists (entry'.meta.title) fragment then None
|
||||
else
|
||||
match p with
|
||||
| Some entry ->
|
||||
if entry.meta.Ymd.date.Ymd.Date.published < entry'.meta.Ymd.date.Ymd.Date.published
|
||||
if entry.meta.date.Date.published < entry'.meta.date.Date.published
|
||||
then Some entry' else p
|
||||
| None -> Some entry' in
|
||||
ListLabels.fold_left ~f:latest ~init:(None) (Archive.of_repo repo)
|
||||
|
@ -1,5 +1,3 @@
|
||||
open Ymd
|
||||
|
||||
type t = Mustache.t
|
||||
|
||||
type header = Header of t
|
||||
@ -26,6 +24,7 @@ let comment c = c
|
||||
let concat l = String.concat "" l
|
||||
|
||||
let fold_text ymd =
|
||||
let open Ymd in
|
||||
let escaped e = match e with
|
||||
| "title" -> ymd.meta.title
|
||||
| "abstract" -> ymd.meta.abstract
|
||||
@ -39,7 +38,7 @@ let fold_text ymd =
|
||||
| "categories" -> CategorySet.to_csv ymd.meta.categories;
|
||||
| "keywords" -> String.concat ", " ymd.meta.keywords;
|
||||
| "series" -> String.concat ", " ymd.meta.series;
|
||||
| "body" -> Omd.to_html (Omd.of_string Ymd.(ymd.body))
|
||||
| "body" -> Omd.to_html @@ Omd.of_string ymd.body
|
||||
| "uuid" -> Id.to_string ymd.meta.uuid
|
||||
| _ -> prerr_endline ("unknown tag: " ^ e); "" in
|
||||
Mustache.fold ~string ~section ~escaped ~unescaped ~partial ~comment ~concat
|
||||
@ -76,7 +75,7 @@ let fold_index ?(entry_tpl=None) lgrn =
|
||||
let open Logarion.Entry in
|
||||
let simple entry =
|
||||
"<li><a href=\"/text/" ^ Filename.(entry.filepath |> basename |> chop_extension) ^ "\">"
|
||||
^ entry.meta.title ^ " ~ " ^ Ymd.Date.(pretty_date @@ last entry.meta.date) ^ "</a></li>" in
|
||||
^ entry.meta.title ^ " ~ " ^ Date.(pretty_date @@ last entry.meta.date) ^ "</a></li>" in
|
||||
let fold_entry tpl entry = fold_entry entry tpl in
|
||||
let entry = match entry_tpl with Some (Listing_entry e) -> fold_entry e | None -> simple in
|
||||
let escaped e = match e with
|
||||
|
Loading…
x
Reference in New Issue
Block a user