fix(pdf): incorrect highlights files for the same name pdfs. https://github.com/logseq/logseq/issues/11496

This commit is contained in:
charlie
2024-09-03 15:16:00 +08:00
parent 7655556d8a
commit a95b1bd0bf

View File

@@ -30,18 +30,28 @@
[rum.core :as rum]
[fipp.edn :refer [pprint]]))
(defn get-in-repo-assets-full-filename
[url]
(let [repo-dir (config/get-repo-dir (state/get-current-repo))]
(when (some-> url (string/trim) (string/includes? repo-dir))
(some-> (string/split url repo-dir)
(last)
(string/replace-first "/assets/" "")))))
(defn inflate-asset
[original-path & {:keys [href]}]
(let [filename (util/node-path.basename original-path)
web-link? (string/starts-with? original-path "http")
(let [web-link? (string/starts-with? original-path "http")
filename (util/node-path.basename original-path)
ext-name (util/get-file-ext filename)
url (if (and href (string/starts-with? href "blob"))
href
url (if (some-> href (string/starts-with? "blob")) href
(assets-handler/normalize-asset-resource-url original-path))
filekey (util/safe-sanitize-file-name (subs filename 0 (- (count filename) (inc (count ext-name)))))]
filename' (if web-link? filename (get-in-repo-assets-full-filename url))
filename' (some-> filename' (js/decodeURIComponent) (string/replace ' "/" "_"))
filekey (util/safe-sanitize-file-name (subs filename' 0 (- (count filename') (inc (count ext-name)))))]
(when-let [key (and (not (string/blank? filekey))
(if web-link?
(str filekey "__" (hash url)) filekey))]
(if web-link?
(str filekey "__" (hash url))
filekey))]
{:key key
:identity (subs key (- (count key) 15))