Replace logseq.json with logseq.edn

pull/645/head
Tienson Qin 2020-05-30 15:49:52 +08:00
parent a4d6f74871
commit 336bc7ca50
4 changed files with 57 additions and 55 deletions

View File

@ -41,7 +41,7 @@
(set))]
(set/union
config-formats
#{:json :org :md :xml :yml :dat :asciidoc :rst :txt :markdown :adoc :html :js :ts :clj :ml :rb :ex :erl :java :php :c
#{:json :org :md :xml :yml :dat :asciidoc :rst :txt :markdown :adoc :html :js :ts :edn :clj :ml :rb :ex :erl :java :php :c
:excalidraw})))
(defn img-formats
@ -64,7 +64,7 @@
(defonce hiccup-support-formats
#{:org :markdown})
(defonce config-file "logseq.json")
(def config-file "logseq.edn")
(def mobile?
(re-find #"Mobi" js/navigator.userAgent))

View File

@ -1153,8 +1153,7 @@
(defn reset-config!
[repo-url content]
(let [config (some->> content
(js/JSON.parse)
(bean/->clj))]
(reader/read-string))]
(state/set-config! repo-url config)
config))
@ -1170,7 +1169,7 @@
(d/transact! db-conn [(me-tx (d/db db-conn) me)])))
(defn restore!
[{:keys [repos] :as me} listen-handler]
[{:keys [repos] :as me} listen-handler restore-config-handler]
(doall
(for [{:keys [id url]} repos]
(let [repo url
@ -1201,8 +1200,7 @@
(reset-conn! db-conn attached-db)))
(d/transact! db-conn [(me-tx (d/db db-conn) me)]))
(listen-handler repo db-conn)
(when-let [config-content (get-file url config/config-file)]
(reset-config! url config-content)))))))))))
(restore-config-handler repo))))))))))
(defn build-page-graph
[page theme]
@ -1255,9 +1253,11 @@
:label (util/capitalize-all p)
:value (get-connections p)}
(= p page)
(assoc :color (if dark?
"#a4b5b6"
"#5850ec"))
(assoc :color
{:border "#5850ec"
:background "#5850ec"
:highlight {:background "#4C51BF"}}
:shape "dot")
dark?
(assoc :font {:color "#dfdfdf"})))))]
{:nodes nodes

View File

@ -178,7 +178,9 @@
path config/config-file
file-path (str "/" path)
default-content "{}"]
(prn {:path path})
(p/let [file-exists? (fs/create-if-not-exists repo-dir file-path default-content)]
(prn "file-exists? " file-exists?)
(when-not file-exists?
(db/reset-file! repo-url path default-content)
(git-add repo-url path)))))
@ -246,8 +248,6 @@
[repo-url diffs first-clone?]
(when (or diffs first-clone?)
(p/let [_ (load-repo-to-db! repo-url diffs first-clone?)]
(create-month-journal-if-not-exists repo-url)
(create-config-file-if-not-exists repo-url)
(history/clear-specific-history! [:git/repo repo-url])
(history/add-history!
[:git/repo repo-url]
@ -279,6 +279,9 @@
(p/then (fn [result]
(-> (git/checkout repo-url)
(p/then (fn [result]
(prn "pulled")
(create-month-journal-if-not-exists repo-url)
(create-config-file-if-not-exists repo-url)
(set-git-status! repo-url nil)
(set-git-last-pulled-at! repo-url)
(when (and latest-commit fetchHead
@ -488,7 +491,10 @@
(git-add repo path)
(cb))
(p/catch (fn [error]
(prn "Add history file handler failed, error: " error)))))}))))
(prn "Add history file handler failed, error: " error)))))}))
(fn [error]
(prn "Write file failed, path: " path ", content: " content)
(js/console.dir error))))
(defn transact-react-and-alter-file!
[repo tx transact-option file-path new-content]
@ -539,8 +545,10 @@
:or {pull-now? true}}]
(periodically-update-repo-status repo-url)
(periodically-pull repo-url pull-now?)
(when-not config/dev?
(periodically-push-tasks repo-url)))
(periodically-push-tasks repo-url)
;; (when-not config/dev?
;; (periodically-push-tasks repo-url))
)
(defn render-local-images!
[]
@ -663,9 +671,10 @@
(restore-cursor-pos! id markup false))
([id markup dummy?]
(when-let [node (gdom/getElement (str id))]
(when-let [range (string/trim (state/get-cursor-range))]
(when-let [cursor-range (state/get-cursor-range)]
(when-let [range (string/trim cursor-range)]
(let [pos (inc (diff/find-position markup range))]
(util/set-caret-pos! node pos))))))
(util/set-caret-pos! node pos)))))))
(defn search
[q]
@ -1010,28 +1019,6 @@
(p/finally (fn []
(clone-and-pull url)))))
(defn watch-config!
[]
(add-watch state/state
:config-changed
(fn [_k _r old-state new-state]
(let [repos (seq (keys (:config new-state)))]
(doseq [repo repos]
(when (not= (get-in new-state [:config repo])
(get-in old-state [:config repo]))
;; persistent to file
(let [repo-dir (util/get-repo-dir repo)
file-path (str "/" config/config-file)
content (js/JSON.stringify (bean/->js (get-in new-state [:config repo]))
nil
;; indent spacing level
2)]
(p/let [content' (load-file repo file-path)]
(when (not= content content')
(fs/write-file repo-dir file-path content)
(db/reset-file! repo config/config-file content)
(git-add repo config/config-file))))))))))
(defn remove-level-spaces
[text format]
(if-not (string/blank? text)
@ -1127,11 +1114,17 @@
(clone-and-pull-repos me))))
(fn [_e])))))
(defn restore-config!
[repo-url]
(p/let [content (load-file repo-url config/config-file)]
(when content
(db/reset-config! repo-url content))))
(defn start!
[render]
(let [me (and js/window.user (bean/->clj js/window.user))]
;; async
(-> (p/all (db/restore! me db-listen-to-tx!))
(-> (p/all (db/restore! me db-listen-to-tx! restore-config!))
(p/then
(fn []
(when me (set-state-kv! :me me))
@ -1252,6 +1245,6 @@
path)]
(let [db-content (db/get-file path)]
(prn {:content content
:db-content db-content
:utf8-length (utf8/length (utf8/encode content))}))))
)

View File

@ -328,7 +328,10 @@
(defn get-caret-pos
[input]
(bean/->clj ((gobj/get caret-pos "position") input)))
(try
(bean/->clj ((gobj/get caret-pos "position") input))
(catch js/Error e
nil)))
(defn minimize-html
[s]
@ -390,9 +393,10 @@
(defn input?
[node]
(when node
(contains?
#{"INPUT" "TEXTAREA"}
(gobj/get node "tagName")))
(gobj/get node "tagName"))))
(defn journal?
[path]
@ -555,6 +559,12 @@
(.getDate local-date-time)
0 0 0 0)))
(defn- rec-get-heading-node
[node]
(if (d/has-class? node "ls-heading-parent")
node
(rec-get-heading-node (gobj/get node "parentNode"))))
;; Take the idea from https://stackoverflow.com/questions/4220478/get-all-dom-block-elements-for-selected-texts.
;; FIXME: Note that it might not works for IE.
(defn get-selected-nodes
@ -563,15 +573,14 @@
(when (gobj/get js/window "getSelection")
(let [selection (js/window.getSelection)
range (.getRangeAt selection 0)
container (gobj/get range "commonAncestorContainer")]
(selection/getSelectedNodes container)
;; (let [container-nodes (array-seq (.getElementsByClassName container class-name))]
;; (filter
;; (fn [node]
;; (let [result (.containsNode selection node true)]
;; result))
;; container-nodes))
))
container (gobj/get range "commonAncestorContainer")
container-nodes (array-seq (selection/getSelectedNodes container))]
(map
(fn [node]
(if (= 3 (gobj/get node "nodeType")) ;textnode
(rec-get-heading-node node)
node))
container-nodes)))
(catch js/Error _e
nil)))