mirror of
https://github.com/logseq/logseq.git
synced 2026-05-29 15:09:41 +00:00
Update publishing to optionally work with db graphs
Also updated commandline script
This commit is contained in:
@@ -2,14 +2,51 @@
|
||||
"Basic script for publishing from CLI"
|
||||
(:require [logseq.graph-parser.cli :as gp-cli]
|
||||
[logseq.publishing :as publishing]
|
||||
[logseq.db.sqlite.db :as sqlite-db]
|
||||
[logseq.db.sqlite.restore :as sqlite-restore]
|
||||
["fs" :as fs]
|
||||
["path" :as node-path]
|
||||
[clojure.edn :as edn]))
|
||||
[cljs-bean.core :as bean]
|
||||
[clojure.edn :as edn]
|
||||
[datascript.core :as d]))
|
||||
|
||||
|
||||
(defn- get-db [graph-dir]
|
||||
(let [{:keys [conn]} (gp-cli/parse-graph graph-dir {:verbose false})] @conn))
|
||||
|
||||
(defn- publish-file-graph [static-dir graph-dir output-path]
|
||||
(let [repo-config (-> (node-path/join graph-dir "logseq" "config.edn") fs/readFileSync str edn/read-string)]
|
||||
(publishing/export (get-db graph-dir)
|
||||
static-dir
|
||||
graph-dir
|
||||
output-path
|
||||
{:repo-config repo-config})))
|
||||
|
||||
(defn- read-db-graph [db-name]
|
||||
(let [{:keys [uuid->db-id-map conn]}
|
||||
(sqlite-restore/restore-initial-data (bean/->js (sqlite-db/get-initial-data db-name)))
|
||||
new-db (sqlite-restore/restore-other-data
|
||||
conn
|
||||
(sqlite-db/get-other-data db-name [])
|
||||
uuid->db-id-map)]
|
||||
|
||||
(d/conn-from-db new-db)))
|
||||
|
||||
(defn- publish-db-graph [static-dir graph-dir output-path]
|
||||
(let [db-name (node-path/basename graph-dir)
|
||||
_ (sqlite-db/open-db! (node-path/dirname graph-dir) db-name)
|
||||
conn (read-db-graph db-name)
|
||||
repo-config (-> (d/q '[:find ?content
|
||||
:where [?b :file/path "logseq/config.edn"] [?b :file/content ?content]]
|
||||
@conn)
|
||||
ffirst
|
||||
edn/read-string)]
|
||||
(publishing/export @conn
|
||||
static-dir
|
||||
graph-dir
|
||||
output-path
|
||||
{:repo-config repo-config :db-graph? true})))
|
||||
|
||||
(defn -main
|
||||
[& args]
|
||||
(when-not (= 3 (count args))
|
||||
@@ -17,10 +54,7 @@
|
||||
(js/process.exit 1))
|
||||
(let [[static-dir graph-dir output-path]
|
||||
;; Offset relative paths since they are run in a different directory than user is in
|
||||
(map #(if (node-path/isAbsolute %) % (node-path/resolve ".." %)) args)
|
||||
repo-config (-> (node-path/join graph-dir "logseq" "config.edn") fs/readFileSync str edn/read-string)]
|
||||
(publishing/export (get-db graph-dir)
|
||||
static-dir
|
||||
graph-dir
|
||||
output-path
|
||||
{:repo-config repo-config})))
|
||||
(map #(if (node-path/isAbsolute %) % (node-path/resolve ".." %)) args)]
|
||||
(if (fs/existsSync (node-path/join graph-dir "db.sqlite"))
|
||||
(publish-db-graph static-dir graph-dir output-path)
|
||||
(publish-file-graph static-dir graph-dir output-path))))
|
||||
|
||||
Reference in New Issue
Block a user