mirror of https://github.com/logseq/logseq
enhance: normalize all paths in app
parent
b72e0199d0
commit
37f08d96e1
|
@ -371,26 +371,28 @@
|
||||||
(util/node-path.join (get-repo-dir repo-url) path)))
|
(util/node-path.join (get-repo-dir repo-url) path)))
|
||||||
|
|
||||||
(defn get-file-path
|
(defn get-file-path
|
||||||
|
"Normalization happens here"
|
||||||
[repo-url relative-path]
|
[repo-url relative-path]
|
||||||
(when (and repo-url relative-path)
|
(when (and repo-url relative-path)
|
||||||
(cond
|
(let [path (cond
|
||||||
(and (or (util/electron?) (mobile-util/native-android?)) (local-db? repo-url))
|
(and (or (util/electron?) (mobile-util/native-android?)) (local-db? repo-url))
|
||||||
(let [dir (get-repo-dir repo-url)]
|
(let [dir (get-repo-dir repo-url)]
|
||||||
(if (string/starts-with? relative-path dir)
|
(if (string/starts-with? relative-path dir)
|
||||||
relative-path
|
relative-path
|
||||||
(str dir "/"
|
(str dir "/"
|
||||||
(string/replace relative-path #"^/" ""))))
|
(string/replace relative-path #"^/" ""))))
|
||||||
|
|
||||||
(and (mobile-util/native-ios?) (local-db? repo-url))
|
(and (mobile-util/native-ios?) (local-db? repo-url))
|
||||||
(let [dir (-> (get-repo-dir repo-url)
|
(let [dir (-> (get-repo-dir repo-url)
|
||||||
(string/replace "file:///" "file:/"))]
|
(string/replace "file:///" "file:/"))]
|
||||||
(js/decodeURI (str dir relative-path)))
|
(js/decodeURI (str dir relative-path)))
|
||||||
|
|
||||||
(= "/" (first relative-path))
|
(= "/" (first relative-path))
|
||||||
(subs relative-path 1)
|
(subs relative-path 1)
|
||||||
|
|
||||||
:else
|
:else
|
||||||
relative-path)))
|
relative-path)]
|
||||||
|
(util/path-normalize path))))
|
||||||
|
|
||||||
(defn get-config-path
|
(defn get-config-path
|
||||||
([]
|
([]
|
||||||
|
|
|
@ -76,7 +76,7 @@
|
||||||
(util/remove-nils
|
(util/remove-nils
|
||||||
(assoc
|
(assoc
|
||||||
(block/page-name->map page false)
|
(block/page-name->map page false)
|
||||||
:block/file {:file/path file}))
|
:block/file {:file/path (util/path-normalize file)}))
|
||||||
(seq properties)
|
(seq properties)
|
||||||
(assoc :block/properties properties)
|
(assoc :block/properties properties)
|
||||||
|
|
||||||
|
|
|
@ -98,7 +98,7 @@
|
||||||
(seq images)
|
(seq images)
|
||||||
(merge (zipmap images (repeat (count images) ""))))
|
(merge (zipmap images (repeat (count images) ""))))
|
||||||
file-contents (for [[file content] file-contents]
|
file-contents (for [[file content] file-contents]
|
||||||
{:file/path file
|
{:file/path (util/path-normalize file)
|
||||||
:file/content content})]
|
:file/content content})]
|
||||||
(ok-handler file-contents))))
|
(ok-handler file-contents))))
|
||||||
(p/catch (fn [error]
|
(p/catch (fn [error]
|
||||||
|
@ -124,6 +124,7 @@
|
||||||
data)))
|
data)))
|
||||||
|
|
||||||
(defn- page-exists-in-another-file
|
(defn- page-exists-in-another-file
|
||||||
|
"Conflict of files towards same page"
|
||||||
[repo-url page file]
|
[repo-url page file]
|
||||||
(when-let [page-name (:block/name page)]
|
(when-let [page-name (:block/name page)]
|
||||||
(let [current-file (:file/path (db/get-page-file repo-url page-name))]
|
(let [current-file (:file/path (db/get-page-file repo-url page-name))]
|
||||||
|
@ -153,6 +154,7 @@
|
||||||
|
|
||||||
:else
|
:else
|
||||||
file)
|
file)
|
||||||
|
file (util/path-normalize file)
|
||||||
new? (nil? (db/entity [:file/path file]))]
|
new? (nil? (db/entity [:file/path file]))]
|
||||||
;; TODO: refactor with reset-file!
|
;; TODO: refactor with reset-file!
|
||||||
;; TODO: missing text/scheduled-deadline-dash->star
|
;; TODO: missing text/scheduled-deadline-dash->star
|
||||||
|
|
|
@ -47,7 +47,7 @@
|
||||||
(cond
|
(cond
|
||||||
mobile-native?
|
mobile-native?
|
||||||
(map (fn [{:keys [uri content size mtime]}]
|
(map (fn [{:keys [uri content size mtime]}]
|
||||||
{:file/path (string/replace uri "file://" "")
|
{:file/path (util/path-normalize (string/replace uri "file://" ""))
|
||||||
:file/last-modified-at mtime
|
:file/last-modified-at mtime
|
||||||
:file/size size
|
:file/size size
|
||||||
:file/content content})
|
:file/content content})
|
||||||
|
@ -56,7 +56,7 @@
|
||||||
electron?
|
electron?
|
||||||
(map (fn [{:keys [path stat content]}]
|
(map (fn [{:keys [path stat content]}]
|
||||||
(let [{:keys [mtime size]} stat]
|
(let [{:keys [mtime size]} stat]
|
||||||
{:file/path path
|
{:file/path (util/path-normalize path)
|
||||||
:file/last-modified-at mtime
|
:file/last-modified-at mtime
|
||||||
:file/size size
|
:file/size size
|
||||||
:file/content content}))
|
:file/content content}))
|
||||||
|
@ -70,7 +70,7 @@
|
||||||
path (-> (get-attr "webkitRelativePath")
|
path (-> (get-attr "webkitRelativePath")
|
||||||
(string/replace-first (str dir-name "/") ""))]
|
(string/replace-first (str dir-name "/") ""))]
|
||||||
{:file/name (get-attr "name")
|
{:file/name (get-attr "name")
|
||||||
:file/path path
|
:file/path (util/path-normalize path)
|
||||||
:file/last-modified-at (get-attr "lastModified")
|
:file/last-modified-at (get-attr "lastModified")
|
||||||
:file/size (get-attr "size")
|
:file/size (get-attr "size")
|
||||||
:file/type (get-attr "type")
|
:file/type (get-attr "type")
|
||||||
|
|
|
@ -1184,12 +1184,10 @@
|
||||||
(defn normalize
|
(defn normalize
|
||||||
[s]
|
[s]
|
||||||
(.normalize s "NFC"))
|
(.normalize s "NFC"))
|
||||||
|
(defn path-normalize
|
||||||
(defn search-normalize-content
|
"Normalize file path (for reading, not writting)"
|
||||||
"Normalize string for searching (loose, without lowercasing)
|
|
||||||
Case-sensitivity is ensured by the search engine"
|
|
||||||
[s]
|
[s]
|
||||||
(.normalize s "NFKD"))
|
(.normalize s "NFC"))
|
||||||
|
|
||||||
(defn search-normalize
|
(defn search-normalize
|
||||||
"Normalize string for searching (loose)"
|
"Normalize string for searching (loose)"
|
||||||
|
@ -1203,7 +1201,7 @@
|
||||||
(.normalize (string/lower-case s) "NFKD") s))
|
(.normalize (string/lower-case s) "NFKD") s))
|
||||||
|
|
||||||
(defn page-name-sanity
|
(defn page-name-sanity
|
||||||
"Sanitize the page-name for file name (strict)"
|
"Sanitize the page-name for file name (strict), for file writting"
|
||||||
([page-name]
|
([page-name]
|
||||||
(page-name-sanity page-name false))
|
(page-name-sanity page-name false))
|
||||||
([page-name replace-slash?]
|
([page-name replace-slash?]
|
||||||
|
|
Loading…
Reference in New Issue