mirror of https://github.com/logseq/logseq
Wip
parent
7a8ca01ee3
commit
c2df042a96
|
@ -1,6 +1,11 @@
|
|||
(ns frontend.external.protocol)
|
||||
|
||||
(defprotocol External
|
||||
(toMldocAst [this content] ; might be json or anything
|
||||
(toMarkdownFiles [this content config]
|
||||
"Should return a map of markdown's file name to contents."
|
||||
)
|
||||
(fromMldocAst [this ast]))
|
||||
|
||||
;; Long-term goal:
|
||||
;; (toMldocAst [this content])
|
||||
;; (fromMldocAst [this ast])
|
||||
)
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
(ns frontend.external.roam
|
||||
(:require [frontend.external.protocol :as protocol]
|
||||
[cljs-bean.core :as bean]
|
||||
[medley.core :as medley]
|
||||
[clojure.walk :as walk]))
|
||||
|
||||
(defonce uid->uuid (atom {}))
|
||||
|
||||
(declare children->text)
|
||||
(defn child->text
|
||||
[{:keys [uid string children] :as child}]
|
||||
(when-not (get @uid->uuid uid)
|
||||
(swap! uid->uuid assoc uid (medley/random-uuid)))
|
||||
(let [children-text (->> (map children->text children)
|
||||
(interpose "\n")
|
||||
(apply str))]
|
||||
(if string
|
||||
(str string "\n" children-text)
|
||||
children-text)))
|
||||
|
||||
(defn children->text
|
||||
[children]
|
||||
(map child->text children))
|
||||
|
||||
(defn ->file
|
||||
[page-data]
|
||||
(let [{:keys [create-time title children edit-time]} page-data]
|
||||
{:title title
|
||||
:created-at create-time
|
||||
:last-modified-at edit-time
|
||||
:text (children->text children)}))
|
||||
|
||||
(defn ->files
|
||||
[edn-data]
|
||||
(let [pages-with-data (filter :children edn-data)]
|
||||
(map ->file pages-with-data)))
|
||||
|
||||
(defrecord Roam []
|
||||
protocol/External
|
||||
(toMarkdownFiles [this content _config]
|
||||
(let [data (bean/->clj (js/JSON.parse content))]
|
||||
(->files data))))
|
||||
|
||||
;; (:create-email :create-time :title :children :edit-time :edit-email)
|
||||
(defonce test-roam-json (frontend.db/get-file "same.json"))
|
||||
|
||||
(defonce edn-data (bean/->clj (js/JSON.parse test-roam-json)))
|
Loading…
Reference in New Issue