Temporal fix for dependencies

pull/645/head
Tienson Qin 2020-08-21 01:15:06 +08:00
parent 41d8d81a6d
commit 687cb46383
2 changed files with 27 additions and 22 deletions

View File

@ -17,8 +17,9 @@
;; DONE: 1. uid converted to a uuid
;; DONE: 2. merge pages with same names (case-sensitive)
;; DONE: 3. mldoc add support to roam research macros, or we can transform here.
;; TODO: 4. mldoc add support to nested links
;; TODO: hiccup
;; DONE: 4. mldoc add support to nested links
;; TODO: 5. Roam attributes -> properties
;; TODO: 6. hiccup
(defonce uid-pattern #"\(\(([a-zA-Z0-9_\\-]{9})\)\)")
(defonce macro-pattern #"\{\{([^{}]+)\}\}")
@ -100,8 +101,7 @@
(defn ->files
[edn-data]
(load-all-refed-uids! edn-data)
(let [pages-with-data (filter :children edn-data)
files (map ->file edn-data)
(let [files (map ->file edn-data)
files (group-by (fn [f] (string/lower-case (:title f)))
files)]
(map

View File

@ -7,25 +7,30 @@
[clojure.string :as string]
[frontend.db :as db]))
(defn index-files!
[repo files error-files]
(doseq [file files]
(let [title (:title file)]
(try
(when-let [text (:text file)]
(let [path (str "pages/" (string/replace title "/" "-") ".md")]
(file-handler/alter-file repo path text {})
(when (date/valid-journal-title? title)
(let [page-name (string/lower-case title)]
(db/transact! repo
[{:page/name page-name
:page/journal? true
:page/journal-day (date/journal-title->int title)}])))))
(catch js/Error e
(swap! error-files conj file))))))
;; TODO: compute the dependencies
;; TODO: Should it merge the roam daily notes with the month journals
(defn import-from-roam-json!
[data]
(when-let [repo (state/get-current-repo)]
(let [files (external/to-markdown-files :roam data {})]
(doseq [file files]
(let [title (:title file)]
(try
(when-let [text (:text file)]
(let [path (str "pages/" (string/replace title "/" "-") ".md")]
(file-handler/alter-file repo path text {})
(when (date/valid-journal-title? title)
(let [page-name (string/lower-case title)]
(db/transact! repo
[{:page/name page-name
:page/journal? true
:page/journal-day (date/journal-title->int title)}])))))
(catch js/Error e
(let [message (str "File " (:title file) " imported failed.")]
(println message)
(js/console.error e)
(notification/show! message :error)))))))))
(let [files (external/to-markdown-files :roam data {})
error-files (atom #{})]
(index-files! repo files error-files)
(when (seq @error-files)
(index-files! repo @error-files (atom nil))))))