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)]