From a65fd2672297008fb60971ca7b845f26dd0f1253 Mon Sep 17 00:00:00 2001 From: SouthFox Date: Thu, 31 Aug 2023 02:24:02 +0800 Subject: [PATCH] [hugo/feat] show catalog --- src/main/backend/handlers.clj | 17 ++++++++++++++++- src/main/backend/hugo/site.clj | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/backend/handlers.clj b/src/main/backend/handlers.clj index c540416..16497c0 100644 --- a/src/main/backend/handlers.clj +++ b/src/main/backend/handlers.clj @@ -42,6 +42,20 @@ (.empty link-card) (.append link-card (.attr (.parent link-card) "data-text")))) +(defn build-catalog-item + [catalog-item] + (.tagName catalog-item "a") + (.attr catalog-item "href" + (str/join ["#" (.attr catalog-item "id")])) + (.attr catalog-item "id" "") + (str "
  • " (.toString catalog-item) "
  • ")) + + +(defn build-catalog + [docs] + (let [catalog (.select docs "h2, h3, h4, h5")] + (apply str (mapv build-catalog-item catalog)))) + (defn fetch-hu-post [request & {:keys [hugo]}] @@ -56,7 +70,8 @@ (render-linkcard docs) (let [content {:content (.toString docs) :title (.text title) - :time (first (str/split (.text post-time) #"・"))}] + :time (first (str/split (.text post-time) #"・")) + :catalog (.toString (build-catalog docs))}] (if hugo content {:status 200 diff --git a/src/main/backend/hugo/site.clj b/src/main/backend/hugo/site.clj index 368b395..3571606 100644 --- a/src/main/backend/hugo/site.clj +++ b/src/main/backend/hugo/site.clj @@ -19,7 +19,7 @@ [:div {:class "flex flex-row flex-wrap py-4"} [:div {:class "w-full sm:w-1/3 md:w-1/4 px-2"} [:div {:class "sticky top-0 p-4 bg-slate-300 rounded-xl w-full"} - [:nav]]] + [:div (:catalog content)]]] [:div {:class "w-full sm:w-2/3 md:w-3/4 pt-1 px-2"} [:h1 (:title content)] [:time (:time content)]