summaryrefslogtreecommitdiff
path: root/editor/state
diff options
context:
space:
mode:
Diffstat (limited to 'editor/state')
-rwxr-xr-xeditor/state/storage.ml21
-rwxr-xr-xeditor/state/storage.mli3
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