From aac1a65e4ccbb2237558cdeb5a6a6eee5ac0205d Mon Sep 17 00:00:00 2001 From: Stavros Polymenis Date: Thu, 24 Aug 2017 08:17:24 +0100 Subject: [PATCH] Change Meta.Email to Uri instead of String Adapt converters to new Email module --- src/converters/atom.ml | 2 +- src/converters/html.ml | 2 +- src/core/jbuild | 2 +- src/core/meta.ml | 14 +++++++------- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/converters/atom.ml b/src/converters/atom.ml index 7a55a5e..c2a5224 100644 --- a/src/converters/atom.ml +++ b/src/converters/atom.ml @@ -28,7 +28,7 @@ let entry config url node_fn note = ^ "" ^ Date.(meta.date |> last |> rfc_string) ^ "" ^ "" |> opt_element "name" @@ esc meta.author.name - |> opt_element "email" @@ esc meta.author.email + |> opt_element "email" @@ esc (Email.to_string meta.author.email) |> opt_element "summary" @@ esc meta.abstract) ^ "" ^ Meta.StringSet.fold (fun elt a -> a ^ "") meta.topics "" diff --git a/src/converters/html.ml b/src/converters/html.ml index 9375094..b411b3b 100644 --- a/src/converters/html.ml +++ b/src/converters/html.ml @@ -71,7 +71,7 @@ let form ?(header_tpl=None) blog_url lgrn ymd = let open Author in let auth = ymd.meta.author in let auth_name = either auth.name Logarion.(lgrn.Archive.Configuration.owner) in - let auth_addr = either auth.email Logarion.(lgrn.Archive.Configuration.email) in + let auth_addr = either (Email.to_string auth.email) Logarion.(lgrn.Archive.Configuration.email) in [ input ~a:[a_name "uuid"; a_value (Id.to_string ymd.meta.uuid); a_input_type `Hidden] (); input_set diff --git a/src/core/jbuild b/src/core/jbuild index 871a2db..98acf72 100644 --- a/src/core/jbuild +++ b/src/core/jbuild @@ -3,5 +3,5 @@ (library ((name logarion) (public_name logarion) - (libraries (batteries toml omd fpath ptime lwt uuidm re)) + (libraries (batteries toml omd fpath ptime lwt uuidm uri re)) )) \ No newline at end of file diff --git a/src/core/meta.ml b/src/core/meta.ml index 2634510..d8ae3dc 100644 --- a/src/core/meta.ml +++ b/src/core/meta.ml @@ -1,5 +1,5 @@ type name_t = string -type email_t = string +module Email = Uri module Date = struct type t = { @@ -42,7 +42,7 @@ end module Author = struct type t = { name: name_t; - email: email_t; + email: Email.t; } [@@deriving lens { submodule = true } ] let of_string ~email name = { name; email } end @@ -114,7 +114,7 @@ type t = { let blank ?(uuid=(Id.generate ())) () = { title = ""; - author = Author.({ name = ""; email = "" }); + author = Author.({ name = ""; email = Email.empty }); date = Date.({ created = None; edited = None; published = None }); categories = CategorySet.empty; topics = StringSet.empty; @@ -138,7 +138,7 @@ let value_with_name (meta as m) = function | "title" -> m.title | "abstract" -> m.abstract | "author_name" -> m.author.Author.name - | "author_email" -> m.author.Author.email + | "author_email" -> Email.to_string m.author.Author.email | "date" -> Date.(rfc_string @@ last m.date) | "date_created" -> Date.(rfc_string m.date.created) | "date_edited" -> Date.(rfc_string m.date.edited) @@ -159,7 +159,7 @@ let with_kv meta (k,v) = | "title" -> { meta with title = trim v } | "author" | "name" -> { meta with author = Author.{ meta.author with name = trim v }} - | "email" -> { meta with author = Author.{ meta.author with email = trim v }} + | "email" -> { meta with author = Author.{ meta.author with email = Email.of_string (trim v) }} | "abstract" -> { meta with abstract = trim v } | "date" -> { meta with date = Date.{ meta.date with created = Date.of_string v }} | "published" -> { meta with date = Date.{ meta.date with published = Date.of_string v }} @@ -178,8 +178,8 @@ let to_string (meta as m) = let has_len v = String.length v > 0 in let s field value = if has_len value then field ^ ": " ^ value ^ "\n" else "" in let a value = - Author.(if has_len value.name || has_len value.email - then "authors: " ^ value.name ^ " <" ^ value.email ^ ">\n" else "") + Author.(if has_len value.name || Email.(equal empty value.email) + then "authors: " ^ value.name ^ " <" ^ Email.to_string value.email ^ ">\n" else "") in let d field value = match value with | Some d -> field ^ ": " ^ Date.rfc_string value ^ "\n" | None -> ""