summaryrefslogtreecommitdiff
path: root/editor/state/storage.ml
diff options
context:
space:
mode:
Diffstat (limited to 'editor/state/storage.ml')
-rwxr-xr-xeditor/state/storage.ml24
1 files changed, 24 insertions, 0 deletions
diff --git a/editor/state/storage.ml b/editor/state/storage.ml
index a790a9d..1bb8b81 100755
--- a/editor/state/storage.ml
+++ b/editor/state/storage.ml
@@ -157,3 +157,27 @@ let to_json
(* Also add the home page *)
let pages = Array.of_list @@ (save_for_id None)::pages in
Brr.Json.encode (Jv.Id.to_jv pages)
+
+let of_json
+ : Jstr.t -> (unit, Jv.Error.t) result
+ = fun json ->
+ let result = Json.decode json in
+ Result.map
+ (fun v ->
+ Array.iter (Jv.Id.of_jv v)
+ ~f:(fun element ->
+ let key = element##.id
+ and content = object%js
+ val title = element##.title
+ val content = element##.content
+ val date = element##.date
+ end in
+ ignore @@
+ save
+ ~check:(fun _ -> true)
+ content
+ key
+ ))
+ result
+
+