[back/feat] redirect zhuanlan URL

This commit is contained in:
SouthFox 2023-08-27 12:52:22 +08:00
parent f5b2c32de5
commit 7b06316210

View file

@ -10,6 +10,7 @@
[content] [content]
(generate-string content)) (generate-string content))
(defn clean-html (defn clean-html
[docs] [docs]
(-> (.select docs "style[data-emotion-css~=^[a-z0-9]*$]") (-> (.select docs "style[data-emotion-css~=^[a-z0-9]*$]")
@ -17,10 +18,11 @@
(vec (vec
(for [a (.select docs "a")] (for [a (.select docs "a")]
(.attr a "href" (.attr a "href"
(url-decode (-> (.attr a "href")
(str/replace (str/replace "https://link.zhihu.com/?target=" "")
(.attr a "href") (str/replace "https://zhuanlan.zhihu.com/p/" "#/item/")
"https://link.zhihu.com/?target=" "")))))) (url-decode))))))
(defn clean-images (defn clean-images
[docs] [docs]
@ -32,6 +34,7 @@
(for [img (.select docs "figure > div > img")] (for [img (.select docs "figure > div > img")]
(.attr img "loading" "lazy")))) (.attr img "loading" "lazy"))))
(defn fetch-hu-post (defn fetch-hu-post
[request] [request]
(let [id (-> request :path-params :id) (let [id (-> request :path-params :id)