[feat] show post title

This commit is contained in:
SouthFox 2023-08-26 18:04:44 +08:00
parent 7b39472012
commit fe62e815bf
3 changed files with 16 additions and 11 deletions

View file

@ -8,7 +8,7 @@
(defn wrap-json
[content]
(generate-string {:content content}))
(generate-string content))
(defn clean-html
[docs]
@ -34,13 +34,15 @@
(defn fetch-hu-post
[request]
(let [id (-> request :path-params :id)
(let [id (-> request :path-params :id)
post-url (str/join ["https://zhuanlan.zhihu.com/p/" id])
docs (-> (client/get post-url) :body Jsoup/parse
(.getElementsByClass "Post-RichTextContainer"))]
page (-> (client/get post-url) :body Jsoup/parse)
title (.getElementsByClass page "Post-Title")
docs (.getElementsByClass page "Post-RichTextContainer")]
(clean-html docs)
(clean-images docs)
{:status 200
:headers {"Content-Type" "application/json; charset=utf-8"}
:body (-> (.toString docs)
(wrap-json))}))
(let [content {:content (.toString docs)
:title (.text title)}]
{:status 200
:headers {"Content-Type" "application/json; charset=utf-8"}
:body (wrap-json content)})))

View file

@ -52,7 +52,7 @@
(fn [db [_ {body :body}]]
(-> db
(assoc-in [:loading :post] false)
(assoc :post (:content body)))))
(assoc :post body))))
(reg-event-db
:initialize-db

View file

@ -23,8 +23,11 @@
(if (:post loading)
[:p "Loading..."]
[:div
{:dangerouslySetInnerHTML
{:__html post}}])))
[:div {:class "text-2xl"}
[:h1 (:title post)]]
[:div
{:dangerouslySetInnerHTML
{:__html (:content post)}}]])))
(defn nav [{:keys [current-route]}]
(let [active #(when (= % (-> current-route :data :name)) "> ")]