normalisation of input

This commit is contained in:
Stavros Polymenis 2016-09-19 19:56:36 +01:00
parent a35f6e7b5d
commit f1d328dae5
2 changed files with 6 additions and 6 deletions

View File

@ -3,7 +3,7 @@ all: web
web: logarion.cmx html.cmx src/web.ml web: logarion.cmx html.cmx src/web.ml
ocamlfind ocamlopt -o logarion-web -linkpkg \ ocamlfind ocamlopt -o logarion-web -linkpkg \
-package opium.unix,omd,str,tyxml,lens,ptime,ptime.clock.os \ -package opium.unix,omd,str,batteries,tyxml,lens,ptime,ptime.clock.os \
logarion.cmx html.cmx src/web.ml logarion.cmx html.cmx src/web.ml
html.cmx: src/html.ml logarion.cmx html.cmx: src/html.ml logarion.cmx

View File

@ -27,19 +27,19 @@ let print_form =
let ymd_of_body_pairs pairs = let ymd_of_body_pairs pairs =
let open Logarion in let open Logarion in
let open Lens.Infix in let open Lens.Infix in
let of_str y k v = (k ^= List.hd v) y in let normal v = v |> List.hd |> BatString.trim in
let of_str_list y k v = (k ^= Str.split (Str.regexp ",") (List.hd v)) y in let of_str y k v = (k ^= normal v) y in
let of_text y k v = (k ^= List.hd v) y in let of_str_list y k v = (k ^= Str.split (Str.regexp " *, *") (normal v)) y in
let field_of_pair ymd (key, value) = match key with let field_of_pair ymd (key, value) = match key with
| "title" -> of_str ymd (ymd_meta |-- meta_title) value | "title" -> of_str ymd (ymd_meta |-- meta_title) value
| "author_name" -> of_str ymd (ymd_meta |-- meta_author |-- author_name) value | "author_name" -> of_str ymd (ymd_meta |-- meta_author |-- author_name) value
| "author_email" -> of_str ymd (ymd_meta |-- meta_author |-- author_email) value | "author_email" -> of_str ymd (ymd_meta |-- meta_author |-- author_email) value
| "publish_date" -> ((ymd_meta |-- meta_date |-- date_published) ^= of_rfc (List.hd value)) ymd | "publish_date" -> ((ymd_meta |-- meta_date |-- date_published) ^= of_rfc (normal value)) ymd
| "topics" -> of_str_list ymd (ymd_meta |-- meta_topics) value | "topics" -> of_str_list ymd (ymd_meta |-- meta_topics) value
| "categories" -> of_str_list ymd (ymd_meta |-- meta_categories) value | "categories" -> of_str_list ymd (ymd_meta |-- meta_categories) value
| "keywords" -> of_str_list ymd (ymd_meta |-- meta_keywords) value | "keywords" -> of_str_list ymd (ymd_meta |-- meta_keywords) value
| "series" -> of_str_list ymd (ymd_meta |-- meta_series) value | "series" -> of_str_list ymd (ymd_meta |-- meta_series) value
| "abstract" -> of_text ymd (ymd_meta |-- meta_abstract) value | "abstract" -> of_str ymd (ymd_meta |-- meta_abstract) value
| "text" -> of_str ymd (ymd_body) value | "text" -> of_str ymd (ymd_body) value
| _ -> ymd | _ -> ymd
in in