Browse Source

move all string/join used to construct paths to one place

rcmerci 3 years ago
parent
commit
de2c1f7445

+ 2 - 2
src/main/frontend/components/block.cljs

@@ -162,7 +162,7 @@
     (when current-file
       (let [parts (string/split current-file #"/")
             parts-2 (string/split path #"/")
-            current-dir (string/join "/" (drop-last 1 parts))]
+            current-dir (util/string-join-path (drop-last 1 parts))]
         (cond
           (if util/win32? (utils/win32 path) (util/starts-with? path "/"))
           path
@@ -187,7 +187,7 @@
                                    parts
                                    (rest col)))))
                 parts (remove #(string/blank? %) parts)]
-            (string/join "/" (reverse parts))))))))
+            (util/string-join-path (reverse parts))))))))
 
 (rum/defcs asset-loader
   < rum/reactive

+ 1 - 1
src/main/frontend/components/hierarchy.cljs

@@ -55,7 +55,7 @@
              (for [[idx page] (medley/indexed namespace)]
                (when (and (string? page) page)
                  (let [full-page (->> (take (inc idx) namespace)
-                                      (string/join "/"))]
+                                      util/string-join-path)]
                    (block/page-reference false
                                          full-page
                                          {}

+ 1 - 1
src/main/frontend/db/conn.cljs

@@ -16,7 +16,7 @@
   (when url
     (if (util/starts-with? url "http")
       (->> (take-last 2 (string/split url #"/"))
-           (string/join "/"))
+           util/string-join-path)
       url)))
 
 (defn get-repo-name

+ 3 - 3
src/main/frontend/fs/nfs.cljs

@@ -65,7 +65,7 @@
     (let [parts (->> (string/split dir "/")
                      (remove string/blank?))
           root (->> (butlast parts)
-                    (string/join "/"))
+                    util/string-join-path)
           new-dir (last parts)
           root-handle (str "handle/" root)]
       (->
@@ -132,7 +132,7 @@
           basename (last parts)
           sub-dir (->> (butlast parts)
                        (remove string/blank?)
-                       (string/join "/"))
+                       util/string-join-path)
           sub-dir-handle-path (str "handle/"
                                    (subs dir 1)
                                    (when sub-dir
@@ -208,7 +208,7 @@
                        (remove string/blank?))
             dir (str "/" (first parts))
             new-path (->> (rest parts)
-                          (string/join "/"))
+                          util/string-join-path)
             handle (idb/get-item (str "handle" old-path))
             file (.getFile handle)
             content (.text file)

+ 2 - 2
src/main/frontend/fs/sync.cljs

@@ -322,7 +322,7 @@
     (if (and (< 2 (count parts))
              (= 36 (count (parts 0)))
              (= 36 (count (parts 1))))
-      (string/join "/" (drop 2 parts))
+      (util/string-join-path (drop 2 parts))
       path)))
 
 (defprotocol IRelativePath
@@ -531,7 +531,7 @@
   {:post [(s/valid? ::diff %)]}
   {:TXId (inc index)
    :TXType "update_files"
-   :TXContent [[(string/join "/" [user-uuid graph-uuid relative-path]) nil checksum]]})
+   :TXContent [[(util/string-join-path [user-uuid graph-uuid relative-path]) nil checksum]]})
 
 (defn filepath+checksum-coll->partitioned-filetxns
   "transducer.

+ 1 - 1
src/main/frontend/handler/page.cljs

@@ -194,7 +194,7 @@
         ext (last (string/split (last result) "."))
         new-file (str new-file-name-body "." ext)
         parts (concat (butlast result) [new-file])]
-    (string/join "/" parts)))
+    (util/string-join-path parts)))
 
 (defn rename-file!
   "emit file-rename events to :file/rename-event-chan

+ 9 - 2
src/main/frontend/util.cljc

@@ -58,6 +58,13 @@
                (gdom/getElementByClass "sidebar-item-list")
                (app-scroll-container-node))))))
 
+(defn string-join-path
+  "Replace all `strings/join` used to construct paths with this function to reduce lint output.
+  https://github.com/logseq/logseq/pull/8679"
+  [parts]
+  (string/join "/" parts))
+
+
 #?(:cljs
    (defn safe-re-find
      {:malli/schema [:=> [:cat :any :string] [:or :nil :string [:vector [:maybe :string]]]]}
@@ -1034,7 +1041,7 @@
   (let [parts (string/split path "/")
         basename (last parts)
         dir (->> (butlast parts)
-                 (string/join "/"))]
+                 string-join-path)]
     [dir basename]))
 
 (defn get-relative-path
@@ -1050,7 +1057,7 @@
             ["."])
           parts-2
           [another-file-name])
-         (string/join "/"))))
+         string-join-path)))
 
 ;; Copied from https://github.com/tonsky/datascript-todo
 #?(:clj

+ 1 - 1
src/main/frontend/util/text.cljs

@@ -145,6 +145,6 @@
     (let [parts (->> (string/split path #"/")
                      (take-last 2))]
       (-> (if (not= (first parts) "0")
-            (string/join "/" parts)
+            (util/string-join-path parts)
             (last parts))
           js/decodeURI))))