[back/feat] add lazy loading attr on image

This commit is contained in:
SouthFox 2023-08-26 12:28:26 +08:00
parent c0b4982e33
commit 7b39472012

View file

@ -14,10 +14,6 @@
[docs] [docs]
(-> (.select docs "style[data-emotion-css~=^[a-z0-9]*$]") (-> (.select docs "style[data-emotion-css~=^[a-z0-9]*$]")
(.remove)) (.remove))
(-> (.select docs "figure > img")
(.remove))
(-> (.select docs "figure > noscript")
(.tagName "div"))
(vec (vec
(for [a (.select docs "a")] (for [a (.select docs "a")]
(.attr a "href" (.attr a "href"
@ -26,6 +22,15 @@
(.attr a "href") (.attr a "href")
"https://link.zhihu.com/?target=" "")))))) "https://link.zhihu.com/?target=" ""))))))
(defn clean-images
[docs]
(-> (.select docs "figure > img")
(.remove))
(-> (.select docs "figure > noscript")
(.tagName "div"))
(vec
(for [img (.select docs "figure > div > img")]
(.attr img "loading" "lazy"))))
(defn fetch-hu-post (defn fetch-hu-post
[request] [request]
@ -34,6 +39,7 @@
docs (-> (client/get post-url) :body Jsoup/parse docs (-> (client/get post-url) :body Jsoup/parse
(.getElementsByClass "Post-RichTextContainer"))] (.getElementsByClass "Post-RichTextContainer"))]
(clean-html docs) (clean-html docs)
(clean-images docs)
{:status 200 {:status 200
:headers {"Content-Type" "application/json; charset=utf-8"} :headers {"Content-Type" "application/json; charset=utf-8"}
:body (-> (.toString docs) :body (-> (.toString docs)