Convert roam namespaces to cljs

The clj functionality was only for tests and those tests no longer
exist for clj. Also removed unused dependency
pull/5192/head
Gabriel Horner 2022-05-04 15:14:09 -04:00
parent 823b8ec39e
commit ca9cc2454f
3 changed files with 37 additions and 53 deletions

View File

@ -1,7 +1,6 @@
{:paths ["src/main" "src/electron" "src/workspaces" "templates"]
:deps
{org.clojure/clojure {:mvn/version "1.10.0"}
cheshire/cheshire {:mvn/version "5.10.0"}
rum/rum {:mvn/version "0.12.9"}
datascript/datascript {:mvn/version "1.3.8"}
datascript-transit/datascript-transit {:mvn/version "0.3.0"}

View File

@ -1,6 +1,4 @@
(ns frontend.external
;; Wonky cljs detection
#_:clj-kondo/ignore
(:require [frontend.external.roam :refer [->Roam]]
[frontend.external.protocol :as protocol]))

View File

@ -1,12 +1,6 @@
(ns frontend.external.roam
;; TODO: Convert this ns and upstream dependents to .cljs. .clj was only for tests
;; and those tests have been removed
(:require #?(:cljs [cljs-bean.core :as bean]
:clj [cheshire.core :as json])
;; TODO: clj-kondo incorrectly thinks these requires are unused
#_:clj-kondo/ignore
(:require [cljs-bean.core :as bean]
[frontend.external.protocol :as protocol]
#_:clj-kondo/ignore
[frontend.date :as date]
[medley.core :as medley]
[clojure.walk :as walk]
@ -42,12 +36,8 @@
(defn macro-transform
[text]
(string/replace text macro-pattern (fn [[original text]]
;; Disable clj warning since clj is unused
#_:clj-kondo/ignore
(let [[name arg] (gp-util/split-first ":" text)]
(if name
;; TODO: Why unresolved var
#_:clj-kondo/ignore
(let [name (text/page-ref-un-brackets! name)]
(util/format "{{%s %s}}" name arg))
original)))))
@ -109,48 +99,45 @@
(defn json->edn
[raw-string]
#?(:cljs (-> raw-string js/JSON.parse bean/->clj)
:clj (-> raw-string json/parse-string clojure.walk/keywordize-keys)))
(-> raw-string js/JSON.parse bean/->clj))
#?(:cljs
(do
(defn ->file
[page-data]
(let [{:keys [create-time title children edit-time]} page-data
initial-level 1
text (when (seq children)
(when-let [text (children->text children (dec initial-level))]
(let [journal? (date/valid-journal-title? title)
front-matter (if journal?
""
(util/format "---\ntitle: %s\n---\n\n" title))]
(str front-matter (transform text)))))]
(when (and (not (string/blank? title))
text)
{:title title
:created-at create-time
:last-modified-at edit-time
:text text})))
(defn ->file
[page-data]
(let [{:keys [create-time title children edit-time]} page-data
initial-level 1
text (when (seq children)
(when-let [text (children->text children (dec initial-level))]
(let [journal? (date/valid-journal-title? title)
front-matter (if journal?
""
(util/format "---\ntitle: %s\n---\n\n" title))]
(str front-matter (transform text)))))]
(when (and (not (string/blank? title))
text)
{:title title
:created-at create-time
:last-modified-at edit-time
:text text})))
(defn ->files
[edn-data]
(load-all-refed-uids! edn-data)
(let [files (map ->file edn-data)
files (remove #(nil? (:title %)) files)
files (group-by (fn [f] (string/lower-case (:title f)))
files)]
(map
(fn [[_ [fst & others]]]
(assoc fst :text
(->> (map :text (cons fst others))
(interpose "\n")
(apply str))))
files)))
(defn ->files
[edn-data]
(load-all-refed-uids! edn-data)
(let [files (map ->file edn-data)
files (remove #(nil? (:title %)) files)
files (group-by (fn [f] (string/lower-case (:title f)))
files)]
(map
(fn [[_ [fst & others]]]
(assoc fst :text
(->> (map :text (cons fst others))
(interpose "\n")
(apply str))))
files)))
(defrecord Roam []
protocol/External
(toMarkdownFiles [_this content _config]
(-> content json->edn ->files)))))
(defrecord Roam []
protocol/External
(toMarkdownFiles [_this content _config]
(-> content json->edn ->files)))
(comment
(defonce test-roam-json (frontend.db/get-file "same.json"))