fix: don't replace _ for the page name if it's not a local asset

pull/6021/head^2
Tienson Qin 2022-08-08 09:13:58 +08:00 committed by Andelf
parent 192a30ae1b
commit b6be007d98
2 changed files with 25 additions and 5 deletions

View File

@ -261,11 +261,15 @@
(defn fix-local-asset-filename
[filename]
(when-not (string/blank? filename)
(let [local-asset? (re-find #"[0-9]{13}_\d$" filename)]
(let [local-asset? (re-find #"[0-9]{13}_\d$" filename)
hls? (and local-asset? (re-find #"^hls__" filename))]
(if (or local-asset? hls?)
(-> filename
(subs 0 (- (count filename) (if local-asset? 15 0)))
(subs 0 (- (count filename) 15))
(string/replace #"^hls__" "")
(string/replace "_" " ")))))
(string/replace "_" " ")
(string/trimr))
filename))))
(rum/defc human-hls-filename-display
[title]

View File

@ -0,0 +1,16 @@
(ns frontend.extensions.pdf.assets-test
(:require [clojure.test :as test :refer [are deftest testing]]
[clojure.string :as str]
[frontend.extensions.pdf.assets :as assets]))
(deftest fix-local-asset-filename
(testing "matched filenames"
(are [x y] (= y (assets/fix-local-asset-filename x))
"2015_Book_Intertwingled_1659920114630_0" "2015 Book Intertwingled"
"hls__2015_Book_Intertwingled_1659920114630_0" "2015 Book Intertwingled"))
(testing "non matched filenames"
(are [x y] (= y (assets/fix-local-asset-filename x))
"foo" "foo"
"foo_bar" "foo_bar"
"foo__bar" "foo__bar"
"foo_bar.pdf" "foo_bar.pdf")))