Merge branch 'master' into feat/integration-plugins-core

This commit is contained in:
charlie
2021-06-04 14:41:36 +08:00
32 changed files with 359 additions and 103 deletions

View File

@@ -1380,28 +1380,35 @@
url))))))))
(defn delete-asset-of-block!
[{:keys [repo href title full-text block-id local?] :as opts}]
[{:keys [repo href title full-text block-id local? delete-local?] :as opts}]
(let [block (db-model/query-block-by-uuid block-id)
_ (or block (throw (str block-id " not exists")))
format (:block/format block)
text (:block/content block)
content (string/replace text full-text "")]
(save-block! repo block content)
(when local?
(when (and local? delete-local?)
;; FIXME: should be relative to current block page path
(fs/unlink! (config/get-repo-path
repo (-> href
(string/replace #"^../" "/")
(string/replace #"^assets://" ""))) nil))))
(when-let [href (if (util/electron?) href (second (re-find #"\((.+)\)$" full-text)))]
(fs/unlink! (config/get-repo-path
repo (-> href
(string/replace #"^../" "/")
(string/replace #"^assets://" ""))) nil)))))
;; assets/journals_2021_02_03_1612350230540_0.png
(defn resolve-relative-path
[file-path]
(if-let [current-file (some-> (state/get-edit-block)
:block/file
:db/id
(db/entity)
:file/path)]
(if-let [current-file (or (some-> (state/get-edit-block)
:block/file
:db/id
(db/entity)
:file/path)
;; fix dummy file path of page
(and (util/electron?)
(util/node-path.join
(config/get-repo-dir (state/get-current-repo))
(config/get-pages-directory) "_.md")))]
(util/get-relative-path current-file file-path)
file-path))
@@ -1983,7 +1990,9 @@
exclude-properties))
:block/meta (dissoc (:block/meta block) :start-pos :end-pos)
:block/content new-content
:block/title new-title})]
:block/title new-title
:block/path-refs (->> (cons (:db/id page) (:block/path-refs block))
(remove nil?))})]
(if file
(assoc m :block/file (select-keys file [:db/id]))
m)))))