diff --git a/doerg/src/net/deertopia/doerg/config.clj b/doerg/src/net/deertopia/doerg/config.clj index 3b1c374..f9c6806 100644 --- a/doerg/src/net/deertopia/doerg/config.clj +++ b/doerg/src/net/deertopia/doerg/config.clj @@ -11,8 +11,7 @@ ::doerg-parser])) (s/def ::file - #(or (instance? java.io.File %) - (string? %))) + (s/conformer (comp fs/file fs/absolutize fs/expand-home))) (s/def ::executable #(or (fs/executable? %) (and (fs/relative? %) diff --git a/publisher/src/net/deertopia/publisher/config.clj b/publisher/src/net/deertopia/publisher/config.clj index 18af668..c1328c1 100644 --- a/publisher/src/net/deertopia/publisher/config.clj +++ b/publisher/src/net/deertopia/publisher/config.clj @@ -4,11 +4,14 @@ [net.deertopia.doerg.config :as doerg])) (s/def ::config - (s/keys :req [::state-directory])) + (s/keys :req [::state-directory + ::org-roam-db-path])) (def default - {::state-directory (fs/xdg-state-home "doerg-publisher")}) + {::state-directory (fs/xdg-state-home "doerg-publisher") + ::org-roam-db-path (fs/file (fs/home) ".cache" "emacs" "org-roam.db")}) (def ^:dynamic *cfg* default) (s/def ::state-directory ::doerg/file) +(s/def ::org-roam-db-path ::doerg/file) diff --git a/publisher/src/net/deertopia/publisher/node.clj b/publisher/src/net/deertopia/publisher/roam.clj similarity index 88% rename from publisher/src/net/deertopia/publisher/node.clj rename to publisher/src/net/deertopia/publisher/roam.clj index 7e8d78d..8971b81 100644 --- a/publisher/src/net/deertopia/publisher/node.clj +++ b/publisher/src/net/deertopia/publisher/roam.clj @@ -1,16 +1,16 @@ -(ns net.deertopia.publisher.node +(ns net.deertopia.publisher.roam (:require [next.jdbc :as sql] [net.deertopia.publisher.config :as cfg] [net.deertopia.publisher.slug :as slug] [babashka.fs :as fs] - [elisp.instaparse :as elisp]) + [net.deertopia.publisher.elisp :as elisp]) (:import (java.util UUID))) ;;; Global database (defonce ^:dynamic *use-db-cache?* true) -(def db-path (-> (cfg/get :org-roam :database) +(def db-path (-> cfg/*cfg* ::cfg/org-roam-db-path fs/expand-home str)) (def db {:dbtype "sqlite" @@ -69,20 +69,24 @@ "Return the node associated with `this` or nil.")) (extend-protocol GetNode + String + (get-node [this] + (or (some-> this slug/from-string get-node) + (some-> this parse-uuid get-node))) java.util.UUID (get-node [this] (make-node this)) - net.deertopia.publish.slug.Slug + net.deertopia.publisher.slug.Slug (get-node [this] (-> this slug/to-uuid make-node))) (comment - (let [n (make-node (slug/to-uuid (slug/->Slug "68XqhHerTWCbE--RYLEdHw")))] - (fetch-with-cache - n :title - #(do (println "fetch") - (sql/execute-one! ds ["select title from nodes where id = ?" - (print-elisp-string (:id %))]))))) + (def node (get-node "68XqhHerTWCbE--RYLEdHw")) + (fetch-with-cache + node :title + #(do (println "fetch") + (sql/execute-one! ds ["select title from nodes where id = ?" + (print-elisp-string (:id %))])))) ;;; Node operations