Fix lint and other minor fixes

- Rename is-file-url to reflect boolean return val
- Remove unused 3rd arg for set-config!
pull/8914/head
Gabriel Horner 2023-03-22 14:51:05 -04:00 committed by Andelf
parent 94f35bda18
commit 07c27b0f59
5 changed files with 17 additions and 55 deletions

View File

@ -12,7 +12,7 @@
(js/console.error "decode-uri-component-failed" uri)
uri)))
(defn is-file-url
(defn is-file-url?
[s]
(and (string? s)
(or (string/starts-with? s "file://") ;; mobile platform
@ -29,7 +29,7 @@
(let [fname (if (string/ends-with? path "/")
nil
(last (string/split path #"/")))]
(if (and (seq fname) (is-file-url path))
(if (and (seq fname) (is-file-url? path))
(safe-decode-uri-component fname)
fname)))
@ -167,7 +167,7 @@
:else
nil)
(if (is-file-url base)
(if (is-file-url? base)
(apply url-join base segments)
(apply path-join-internal base segments)))
@ -190,16 +190,16 @@
(defn path-normalize
"Normalize path or URL"
[path]
(if (is-file-url path)
(if (is-file-url? path)
(url-normalize path)
(path-normalize-internal path)))
(defn url-to-path
"Extract path part of a URL, decoded.
The reverse operation is (path-join protocol:// path)"
[original-url]
(if (is-file-url original-url)
(if (is-file-url? original-url)
;; NOTE: URL type is not consistent across all protocols
;; Check file:// and assets://, pathname behavior is different
(let [^js url (js/URL. (string/replace original-url "assets://" "file://"))
@ -218,7 +218,7 @@
[base-path sub-path]
(let [base-path (path-normalize base-path)
sub-path (path-normalize sub-path)
is-url? (is-file-url base-path)]
is-url? (is-file-url? base-path)]
(if (string/starts-with? sub-path base-path)
(if is-url?
(safe-decode-uri-component (string/replace (subs sub-path (count base-path)) #"^/+", ""))
@ -233,12 +233,12 @@
[base-path sub-path]
(let [base-path (path-normalize base-path)
sub-path (path-normalize sub-path)
is-url? (is-file-url base-path)]
is-url? (is-file-url? base-path)]
(if (string/starts-with? sub-path base-path)
(if is-url?
(safe-decode-uri-component (string/replace (subs sub-path (count base-path)) #"^/+", ""))
(string/replace (subs sub-path (count base-path)) #"^/+", ""))
;; append as many ..
;; append as many ..
;; NOTE: buggy impl
(let [base-segs (string/split base-path #"/" -1)
path-segs (string/split sub-path #"/" -1)
@ -277,7 +277,7 @@
[current-path target-path]
(let [base-path (parent current-path)
sub-path (path-normalize target-path)
is-url? (is-file-url base-path)
is-url? (is-file-url? base-path)
base-segs (if base-path
(string/split base-path #"/" -1)
[])

View File

@ -432,44 +432,6 @@
(path/path-join (get-repo-dir repo-url) path)
(util/node-path.join (get-repo-dir repo-url) path)))
(defn get-file-path
"Normalization happens here"
[repo-url rpath]
(js/console.error "BUG SHOULD-NOT-USE-BUGGY-FN" repo-url rpath)
(when (and repo-url rpath)
(let [path (cond
(demo-graph?)
(let [dir (get-repo-dir repo-url)
r (path/path-join dir rpath)]
(js/console.error "get-file-path" r)
r)
(and (util/electron?) (local-db? repo-url))
(let [dir (get-repo-dir repo-url)]
(if (string/starts-with? rpath dir)
rpath
(str dir "/"
(string/replace rpath #"^/" ""))))
(and (mobile-util/native-ios?) (local-db? repo-url))
(let [dir (get-repo-dir repo-url)]
(path/path-join dir rpath))
(and (mobile-util/native-android?) (local-db? repo-url))
(let [dir (get-repo-dir repo-url)
dir (if (or (string/starts-with? dir "file:")
(string/starts-with? dir "content:"))
dir
(str "file:///" (string/replace dir #"^/+" "")))]
(util/safe-path-join dir rpath))
(= "/" (first rpath))
(subs rpath 1)
:else
rpath)]
(and (not-empty path) (gp-util/path-normalize path)))))
(defn get-repo-config-path
([]
(get-repo-config-path (state/get-current-repo)))

View File

@ -23,11 +23,9 @@
(file-handler/set-file-content! repo path new-content) nil))))
(defn set-config!
([k v]
(set-config! (state/get-current-repo) k v))
([_repo k v]
(let [path "logseq/config.edn"]
(repo-config-set-key-value path k v))))
[k v]
(let [path "logseq/config.edn"]
(repo-config-set-key-value path k v)))
(defn toggle-ui-show-brackets! []
(let [show-brackets? (state/show-brackets?)]

View File

@ -12,7 +12,7 @@
Promise <void>"
[repo format]
(js/console.log (str "Writing character escaping format " format " of repo " repo))
(set-config! repo :file/name-format format))
(set-config! :file/name-format format))
(defn- calc-current-name
"If the file body is parsed as the same page name, but the page name has a

View File

@ -37,7 +37,9 @@ when a plugin is installed, updated or removed"
rewrite/parse-string
(rewrite/assoc (keyword id) (select-keys plugin common-plugin-keys))
str)]
(fs/write-file! "" nil (plugin-config-path) updated-content {:skip-compare? true})))
;; fs protocols require repo and dir when they aren't necessary. For this component,
;; neither is needed so these are blank and nil respectively
(fs/write-file! "" nil (plugin-config-path) updated-content {:skip-compare? true})))
(defn remove-plugin
"Removes a plugin from plugin.edn"