From 72e3b16bbd258e63f047392c973ba5e8f0a823c8 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Tue, 1 Jun 2021 13:11:58 +0200 Subject: Added export button in editor --- editor/state/storage.ml | 21 +++++++++++++++++++++ editor/state/storage.mli | 3 +++ 2 files changed, 24 insertions(+) (limited to 'editor/state') 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 -- cgit v1.2.3