diff options
| author | Sébastien Dailly <sebastien@chimrod.com> | 2021-06-01 13:11:58 +0200 | 
|---|---|---|
| committer | Sébastien Dailly <sebastien@dailly.me> | 2022-02-07 16:43:33 +0100 | 
| commit | 72e3b16bbd258e63f047392c973ba5e8f0a823c8 (patch) | |
| tree | 67f75383a9d20590587c648ecb5e3c78f6bd0044 /editor/state | |
| parent | 54f6e68c051afec0d20c349352feee5356e11b35 (diff) | |
Added export button in editor
Diffstat (limited to 'editor/state')
| -rwxr-xr-x | editor/state/storage.ml | 21 | ||||
| -rwxr-xr-x | editor/state/storage.mli | 3 | 
2 files changed, 24 insertions, 0 deletions
diff --git a/editor/state/storage.ml b/editor/state/storage.ml index b0c00de..a790a9d 100755 --- a/editor/state/storage.ml +++ b/editor/state/storage.ml @@ -1,4 +1,5 @@  open Brr +open StdLabels  module Js = Js_of_ocaml.Js  let storage_key = (Jstr.v "editor") @@ -136,3 +137,23 @@ let get_ids      in      add_element [] items + +let save_for_id +  : Jstr.t option -> 'a Js.t +  = fun id -> +    let element = load id in +    object%js +      val title = element##.title +      val content = element##.content +      val date = element##.date +      val id = id +    end + +let to_json +  : unit -> Jstr.t +  = fun () -> +    let keys = get_ids () in +    let pages = List.map ~f:(fun id -> save_for_id (Some id)) keys in +    (* Also add the home page *) +    let pages = Array.of_list @@ (save_for_id None)::pages in +    Brr.Json.encode (Jv.Id.to_jv pages) diff --git a/editor/state/storage.mli b/editor/state/storage.mli index 5b7e0a0..50e164e 100755 --- a/editor/state/storage.mli +++ b/editor/state/storage.mli @@ -34,3 +34,6 @@ val delete  (** Collect all the keys to the existing pages *)  val get_ids    : unit -> Jstr.t list + +val to_json +  : unit -> Jstr.t  | 
