diff --git a/src/main/backend/handlers.clj b/src/main/backend/handlers.clj index 588ca18..c689c8c 100644 --- a/src/main/backend/handlers.clj +++ b/src/main/backend/handlers.clj @@ -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)}))) diff --git a/src/main/frontend/events.cljs b/src/main/frontend/events.cljs index 56f2704..77dcd49 100644 --- a/src/main/frontend/events.cljs +++ b/src/main/frontend/events.cljs @@ -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 diff --git a/src/main/frontend/views.cljs b/src/main/frontend/views.cljs index 0e6663c..158b7e4 100644 --- a/src/main/frontend/views.cljs +++ b/src/main/frontend/views.cljs @@ -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)) "> ")]