more fixes
This commit is contained in:
parent
8ec7533db1
commit
01e62889e2
4 changed files with 20 additions and 29 deletions
|
|
@ -217,21 +217,20 @@ let () =
|
||||||
let parse_image image =
|
let parse_image image =
|
||||||
match image with
|
match image with
|
||||||
| None -> Ok None
|
| None -> Ok None
|
||||||
| Some image -> (
|
| Some (name, content, alt) ->
|
||||||
let image =
|
let name =
|
||||||
match image with
|
match name with
|
||||||
| Some image_name, image_content, alt ->
|
| Some name -> Dream.html_escape name
|
||||||
(Dream.html_escape image_name, image_content, Dream.html_escape alt)
|
| None ->
|
||||||
| None, image_content, alt ->
|
|
||||||
(* make up random name if no name was given *)
|
(* make up random name if no name was given *)
|
||||||
let image_name = Uuidm.to_string (Uuidm.v4_gen random_state ()) in
|
Uuidm.to_string (Uuidm.v4_gen random_state ())
|
||||||
(image_name, image_content, Dream.html_escape alt)
|
|
||||||
in
|
in
|
||||||
match image with
|
if not (is_valid_image content) then
|
||||||
| _, image_content, alt ->
|
Error "invalid image"
|
||||||
if not (is_valid_image image_content) then Error "invalid image"
|
else if String.length alt > 1000 then
|
||||||
else if String.length alt > 1000 then Error "Image description too long"
|
Error "Image description too long"
|
||||||
else Ok (Some image) )
|
else
|
||||||
|
Ok (Some (name, content, alt))
|
||||||
|
|
||||||
(*TODO switch to markdown !*)
|
(*TODO switch to markdown !*)
|
||||||
(* insert html into the comment, and keep tracks of citations :
|
(* insert html into the comment, and keep tracks of citations :
|
||||||
|
|
|
||||||
|
|
@ -11,4 +11,4 @@ let ( let^ ) o f =
|
||||||
| Error e -> Error (Format.sprintf "db error: %s" (Caqti_error.show e))
|
| Error e -> Error (Format.sprintf "db error: %s" (Caqti_error.show e))
|
||||||
| Ok x -> f x
|
| Ok x -> f x
|
||||||
|
|
||||||
let ( let* ) o f = match o with Error e -> Error e | Ok x -> f x
|
let ( let* ) o f = Result.fold ~ok:f ~error:Result.error o
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
(library
|
(library
|
||||||
(name js_pretty_post)
|
(name js_pretty_post)
|
||||||
(modules js_pretty_post)
|
(modules js_pretty_post)
|
||||||
(libraries js_of_ocaml brr)
|
(libraries js_of_ocaml brr unix)
|
||||||
(preprocess
|
(preprocess
|
||||||
(pps js_of_ocaml-ppx)))
|
(pps js_of_ocaml-ppx)))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,25 +31,17 @@ let image_click post_image event =
|
||||||
|
|
||||||
let render_time date_span =
|
let render_time date_span =
|
||||||
log "render time@.";
|
log "render time@.";
|
||||||
let unix_time =
|
let t =
|
||||||
float_of_int
|
float_of_int
|
||||||
(Jv.to_int
|
(Jv.to_int
|
||||||
(Jv.call date_span "getAttribute" [| Jv.of_string "data-time" |]) )
|
(Jv.call date_span "getAttribute" [| Jv.of_string "data-time" |]) )
|
||||||
in
|
in
|
||||||
(*use float because int overflow*)
|
let t = Unix.localtime t in
|
||||||
let time_millisecs = 1000.0 *. unix_time in
|
let date =
|
||||||
let date_constructor = Jv.get Jv.global "Date" in
|
Format.sprintf "%02d-%02d-%02d %02d:%02d" (1900 + t.tm_year) (1 + t.tm_mon)
|
||||||
let date = Jv.new' date_constructor [| Jv.of_float time_millisecs |] in
|
t.tm_mday t.tm_hour t.tm_min
|
||||||
let year = Jv.to_int @@ Jv.call date "getFullYear" [||] in
|
|
||||||
(*the month is 0-indexed*)
|
|
||||||
let month = (Jv.to_int @@ Jv.call date "getMonth" [||]) + 1 in
|
|
||||||
let day = Jv.to_int @@ Jv.call date "getDate" [||] in
|
|
||||||
let hour = Jv.to_int @@ Jv.call date "getHours" [||] in
|
|
||||||
let min = Jv.to_int @@ Jv.call date "getMinutes" [||] in
|
|
||||||
let date_string =
|
|
||||||
Format.sprintf "%02d-%02d-%02d %02d:%02d" year month day hour min
|
|
||||||
in
|
in
|
||||||
ignore @@ Jv.set date_span "innerHTML" (Jv.of_string date_string)
|
ignore @@ Jv.set date_span "innerHTML" (Jv.of_string date)
|
||||||
|
|
||||||
let make_pretty _ =
|
let make_pretty _ =
|
||||||
log "make pretty@.";
|
log "make pretty@.";
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue