enhance(pdf): make the weblink pdf filename to be human-readable for the annotations page

pull/8321/head
charlie 2023-01-06 12:28:18 +08:00 committed by Andelf
parent 418502deed
commit e70d76589b
3 changed files with 16 additions and 15 deletions

View File

@ -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

View 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))))

View File

@ -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"