From 2809634cda675fec115d5bd5aa7fa8bdb95fcd55 Mon Sep 17 00:00:00 2001 From: SouthFox Date: Tue, 29 Aug 2023 11:06:03 +0800 Subject: [PATCH] [hugo/fix] wrong internal link --- src/main/backend/handlers.clj | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/main/backend/handlers.clj b/src/main/backend/handlers.clj index 30146d0..1bc203e 100644 --- a/src/main/backend/handlers.clj +++ b/src/main/backend/handlers.clj @@ -12,15 +12,18 @@ (defn clean-html - [docs] - (-> (.select docs "style[data-emotion-css~=^[a-z0-9]*$]") - (.remove)) - (doseq [a (.select docs "a")] - (.attr a "href" - (-> (.attr a "href") - (str/replace "https://link.zhihu.com/?target=" "") - (str/replace "https://zhuanlan.zhihu.com/p/" "#/item/") - (url-decode))))) + [docs hugo] + (let [replace-str (if hugo + "/hp/" + "#/item/")] + (-> (.select docs "style[data-emotion-css~=^[a-z0-9]*$]") + (.remove)) + (doseq [a (.select docs "a")] + (.attr a "href" + (-> (.attr a "href") + (str/replace "https://link.zhihu.com/?target=" "") + (str/replace "https://zhuanlan.zhihu.com/p/" replace-str) + (url-decode)))))) (defn clean-images @@ -48,7 +51,7 @@ title (.getElementsByClass page "Post-Title") post-time (.getElementsByClass page "ContentItem-time") docs (.getElementsByClass page "Post-RichTextContainer")] - (clean-html docs) + (clean-html docs hugo) (clean-images docs) (render-linkcard docs) (let [content {:content (.toString docs)