mirror of https://github.com/logseq/logseq
enhance(pdf): make the weblink pdf filename to be human-readable for the annotations page
parent
418502deed
commit
e70d76589b
|
@ -32,13 +32,12 @@
|
|||
(let [filename (util/node-path.basename original-path)
|
||||
web-link? (string/starts-with? original-path "http")
|
||||
ext-name (util/get-file-ext filename)
|
||||
url (assets-handler/normalize-asset-resource-url original-path)]
|
||||
(when-let [key
|
||||
url (assets-handler/normalize-asset-resource-url original-path)
|
||||
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 (hash url))
|
||||
(and
|
||||
(= ext-name "pdf")
|
||||
(subs filename 0 (- (count filename) 4))))]
|
||||
(str filekey "__" (hash url)) filekey))]
|
||||
|
||||
{:key key
|
||||
:identity (subs key (- (count key) 15))
|
||||
:filename filename
|
||||
|
|
|
@ -183,6 +183,7 @@
|
|||
(-> filename
|
||||
(subs 0 (if local-asset? (- len 15) len))
|
||||
(string/replace #"^hls__" "")
|
||||
(string/replace #"__[-\d]+$" "")
|
||||
(string/replace "_" " ")
|
||||
(string/trimr))
|
||||
filename))))
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
(are [x y] (= y (pdf-utils/fix-local-asset-pagename x))
|
||||
"2015_Book_Intertwingled_1659920114630_0" "2015 Book Intertwingled"
|
||||
"hls__2015_Book_Intertwingled_1659920114630_0" "2015 Book Intertwingled"
|
||||
"hls/2015_Book_Intertwingled_1659920114630_0" "hls/2015 Book Intertwingled"))
|
||||
"hls/2015_Book_Intertwingled_1659920114630_0" "hls/2015 Book Intertwingled"
|
||||
"hls__sicp__-1234567" "sicp"))
|
||||
(testing "non matched filenames"
|
||||
(are [x y] (= y (pdf-utils/fix-local-asset-pagename x))
|
||||
"foo" "foo"
|
||||
|
|
Loading…
Reference in New Issue