Skip to content

Commit

Permalink
Fix lint and other minor fixes
Browse files Browse the repository at this point in the history
- Rename is-file-url to reflect boolean return val
- Remove unused 3rd arg for set-config!
  • Loading branch information
logseq-cldwalker authored and andelf committed Mar 28, 2023
1 parent 94f35bd commit 07c27b0
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 55 deletions.
20 changes: 10 additions & 10 deletions deps/common/src/logseq/common/path.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)))

Expand Down Expand Up @@ -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)))

Expand All @@ -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://"))
Expand All @@ -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)) #"^/+", ""))
Expand All @@ -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)
Expand Down Expand Up @@ -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)
[])
Expand Down
38 changes: 0 additions & 38 deletions src/main/frontend/config.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
8 changes: 3 additions & 5 deletions src/main/frontend/handler/config.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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?)]
Expand Down
2 changes: 1 addition & 1 deletion src/main/frontend/handler/conversion.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/main/frontend/handler/plugin_config.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 07c27b0

Please sign in to comment.