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
|
@ -29,21 +29,20 @@
|
||||||
|
|
||||||
(defn inflate-asset
|
(defn inflate-asset
|
||||||
[original-path]
|
[original-path]
|
||||||
(let [filename (util/node-path.basename original-path)
|
(let [filename (util/node-path.basename original-path)
|
||||||
web-link? (string/starts-with? original-path "http")
|
web-link? (string/starts-with? original-path "http")
|
||||||
ext-name (util/get-file-ext filename)
|
ext-name (util/get-file-ext filename)
|
||||||
url (assets-handler/normalize-asset-resource-url original-path)]
|
url (assets-handler/normalize-asset-resource-url original-path)
|
||||||
(when-let [key
|
filekey (util/safe-sanitize-file-name (subs filename 0 (- (count filename) (inc (count ext-name)))))]
|
||||||
(if web-link?
|
(when-let [key (and (not (string/blank? filekey))
|
||||||
(str (hash url))
|
(if web-link?
|
||||||
(and
|
(str filekey "__" (hash url)) filekey))]
|
||||||
(= ext-name "pdf")
|
|
||||||
(subs filename 0 (- (count filename) 4))))]
|
{:key key
|
||||||
{:key key
|
:identity (subs key (- (count key) 15))
|
||||||
:identity (subs key (- (count key) 15))
|
:filename filename
|
||||||
:filename filename
|
:url url
|
||||||
:url url
|
:hls-file (str "assets/" key ".edn")
|
||||||
:hls-file (str "assets/" key ".edn")
|
|
||||||
:original-path original-path})))
|
:original-path original-path})))
|
||||||
|
|
||||||
(defn resolve-area-image-file
|
(defn resolve-area-image-file
|
||||||
|
|
|
@ -183,6 +183,7 @@
|
||||||
(-> filename
|
(-> filename
|
||||||
(subs 0 (if local-asset? (- len 15) len))
|
(subs 0 (if local-asset? (- len 15) len))
|
||||||
(string/replace #"^hls__" "")
|
(string/replace #"^hls__" "")
|
||||||
|
(string/replace #"__[-\d]+$" "")
|
||||||
(string/replace "_" " ")
|
(string/replace "_" " ")
|
||||||
(string/trimr))
|
(string/trimr))
|
||||||
filename))))
|
filename))))
|
||||||
|
|
|
@ -7,7 +7,8 @@
|
||||||
(are [x y] (= y (pdf-utils/fix-local-asset-pagename x))
|
(are [x y] (= y (pdf-utils/fix-local-asset-pagename x))
|
||||||
"2015_Book_Intertwingled_1659920114630_0" "2015 Book Intertwingled"
|
"2015_Book_Intertwingled_1659920114630_0" "2015 Book Intertwingled"
|
||||||
"hls__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"
|
(testing "non matched filenames"
|
||||||
(are [x y] (= y (pdf-utils/fix-local-asset-pagename x))
|
(are [x y] (= y (pdf-utils/fix-local-asset-pagename x))
|
||||||
"foo" "foo"
|
"foo" "foo"
|
||||||
|
|
Loading…
Reference in New Issue